Why does Haskell handle the bottom layout correctly?

I am testing my understanding of the layout parsing function in a Haskell report ( here )

I could understand that:

  • test case 1 will pass due to good alignment
  • test case 2 will fail because "in a + b" is considered a new element at the module level

However, I couldn't figure out why Test Case 3 would be parsed correctly. So the questions:

Why will test case 3 be parsed correctly? What pattern in LHS parsing function L (see here ) does test case 3 match?

-- test case 1
f_1 = let a = 1
          b = 2
      in a + b

-- test case 2
f_2 = let a = 1
          b = 2
in a + b

-- test case 3
f_3 = let a = 1
          b = 2
                     in a + b

      

+3


source to share


1 answer


Test case 3 matches the parse-error (t) rule. Since the token is in

not legal at this point in the block let

, before is in

inserted }

to end it.



The parse rule can be misleading, but it is also very flexible; using it you can, for example, write Haskell one-liners with rarely any explicit {}

at all.

+2


source







All Articles