0

Why doesn't line 5 contain an indentation error. I expected to get a parse error on compilation. I expected that the + on line 5 would have to be aligned under the * in line 4.

module Learn where

x = 10
  * 5
 + y  -- why isn't this incorrect indentation

myResult = x * 5

y = 10
madhukar93
  • 507
  • 5
  • 23

2 Answers2

4

It compiles because there's no block there to consider.

Indentation only matters after where, let, do, case of. These keywords start a block of things, and it is important to understand whether a line continues the previous entry, starts a new entry, or ends the block.

case f 5 of
   A -> foo
      32         -- continues the previous entry
   B -> 12       -- starts a new entry
+ bar 43         -- ends the case

After = we do not need to split a block into entries: there's only a single expression. Hence no indentation rules apply.

Community
  • 1
  • 1
chi
  • 111,837
  • 3
  • 133
  • 218
1

This compiles because the definition of x was all to the right of the beginning of x. It's not important where each line starts as long as those lines are indented to the right of x.

glguy
  • 1,090
  • 7
  • 8