1

Consider the following code:

foo = do
  let bar = do
    baz
  bar

It doesn't parse in ghc, version 8. It complains about the line containing baz. This code does parse, though:

foo = do
  let bar = do
      baz
  bar

I find this confusing. What's the essential difference between the two versions?

Turion
  • 5,684
  • 4
  • 26
  • 42

1 Answers1

4

The problem is the indentation puts baz in no-mans land. It isn't indented far enough to be part of the let expression, but it is indented too far to be the next part of the do expression containing the let expression.

chepner
  • 497,756
  • 71
  • 530
  • 681
  • Why are two spaces not enough to make it part of the `do` block? Note that it's not directly part of the `let`, since no value is assigned to it. – Turion Feb 06 '17 at 22:34
  • 1
    @Turion Haskell’s layout rules require that everything on the RHS of a `let` or `where` be indented *at least* as far as the first column of the pattern on the LHS. In your first example, `baz` isn’t indented as far as `bar`, which is not okay, but in the second example it is. – Alexis King Feb 06 '17 at 22:51