6
let x=1
    y=2
    z=3

does not work in GHCi, forcing me to use let {x=1;y=2;y=3} instead. How can I fix this problem?

ThePiercingPrince
  • 1,873
  • 13
  • 21

1 Answers1

12

The documentation says:

GHCi also has a multiline mode, enabled by :set +m, in which GHCi detects automatically when the current statement is unfinished and allows further lines to be added. A multi-line input is terminated with an empty line.

The multiline mode makes GHCi behave much like e.g. the Python interpreter:

Prelude> :set +m
Prelude> let x = 1
Prelude|     y = 2
Prelude|     z = 3
Prelude|
Prelude> (x, y, z)
(1,2,3)

This hidden gem is wonderful for playing with readable code!

If you want this to be the default behaviour, you can create a .ghci file in your home directory with a line saying :set +m. (Now that this came up, I actually did so.)

kqr
  • 14,791
  • 3
  • 41
  • 72