2

I have read the answers in this question, but I am still confused. In both GHCi (version 8.2.1) and WinGHCi (version 1.0.6), running in Windows 10, I appear to be able to bind a value to an expression, when typing at the prompt, both with and without using let (see below). And similarly I appear to be able to define identically performing functions by both let f x = xx* and f x = xx*

Prelude> x = 3
Prelude> let y = 3
Prelude> x
3
Prelude> y
3
Prelude> x == y
True
Prelude>

So when is the let actually necessary in GHCi?

In case it is relevant, the language flags set for GHCi (which I presume are default values as I haven't messed whth them) are

base language is: Haskell2010
with the following modifiers:
  -XNoDatatypeContexts
  -XExtendedDefaultRules
  -XNoMonomorphismRestriction
  -XNondecreasingIndentation
Penguino
  • 2,136
  • 1
  • 14
  • 21
  • I think you didn’t used to be able to do that, but if you can now that’s nice. Maybe it’s only there for backwards compatibility? – Ry- Jul 15 '18 at 01:37

1 Answers1

5

In answer to my own question. I have just read the footnote

This has changed as of the release of GHC 8.0.1; using let in declarations in GHCi is no longer necessary. As we assume most readers of this edition will be using an earlier version of GHC, we have kept the let notation throughout the book, and this shouldn’t cause any errors or breakage.

in Haskell Programming From First Principles, which confirms that let is no longer necessary.

Penguino
  • 2,136
  • 1
  • 14
  • 21