-
Notifications
You must be signed in to change notification settings - Fork 108
Open
Description
In slide 7 in Haskell 101, it uses the following example to show immutability:
let a = 3
in a = a + 1
I think we need a better example than this one. Because of the following reasons:
(1) This is syntactically wrong. And the syntactic failure has nothing to do with immutability. We can, for example, rewrite it to
let a = 3
in b = c + 1
and it just fails.
(2) We can, actually, slightly revise the example to:
let a = 3
in let a = 4
in a + 1
This works. But this is, of course, related to shadowing rather than immutability. Then this example is quite confusing.
(3) We can, actually, further revise the example to:
let a = 3
in let a = a + 1
in a + 1
This works. But it just loops forever, because in the definition a = a + 1, the a being defined is brought into the scope of a + 1. So it just recurs forever. Again, this example is being confusing.
Abastro
Metadata
Metadata
Assignees
Labels
No labels