Functional Purity using 'let' in Haskell

前端 未结 2 957
遥遥无期
遥遥无期 2021-01-12 20:51

As I am working on learning Haskell, I understand it is a purely functional language. I am having trouble understanding why let-statements don\'t violate purity

2条回答
  •  Happy的楠姐
    2021-01-12 21:25

    Your second let creates a new binding for e that shadows the existing variable. It does not modify e. You can easily check this with the following:

    Prelude> let e = 1
    Prelude> let f () = "e is now " ++ show e
    Prelude> f ()
    "e is now 1"
    Prelude> let e = 2
    Prelude> e
    2
    Prelude> f ()
    "e is now 1"
    Prelude> 
    

提交回复
热议问题