0

We create this function:

conanO'Brien = "It's a-me, Conan O'Brien!"

The author then states, "Because we can't change what names (and functions) mean once we've defined them, conanO'Brien and the string "It's a-me, Conan O'Brien!" can be used interchangeably."

Yet, I can make the reassignment conanO'Brian = 2 with no trouble. What does he mean by "we can't change what names (and functions) mean"?

Reef Loretto
  • 61
  • 1
  • 6
  • 3
    You can define a new variable of the same name _shadowing_ the previous variable and with a different value, but you can't change the variable's value. – Alec Jun 05 '17 at 15:53
  • 5
    You can't reassign in a .hs file. In GHCi, the REPL lets you redefine a binding, much as if you wrote two nested bindings `let x= ... in let x= ... in ...`, but this is no reassignment, only shadowing of the outermost `x`. – chi Jun 05 '17 at 15:54
  • 4
    Try this in GHCi. `x = 10` and then `f y = x+y`. Then, try to "reassign" to `x`, and observe that `f` is not affected by that -- `f y` still returns `10+y`. – chi Jun 05 '17 at 15:56
  • 2
    `"conanO'Brian" == "conanO'Brien"` ==> `False`. – Will Ness Jun 05 '17 at 16:52

0 Answers0