Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Need a better example for immutability #19

@xnning

Description

@xnning

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions