Opened 2 years ago

Closed 2 years ago

#10884 closed bug (invalid)

Indentation requirements for parsing seem inconsistent

Reported by: Samvh Owned by:
Priority: normal Milestone:
Component: Compiler (Parser) Version: 7.10.2
Keywords: parsing, indentation, do-notation Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The "golden rule of indentation" does not seem to be strictly adhered to in all cases: there is an interaction between let/where clauses and do-notation that makes indentation requirements different in different situations:

Example 1, parsed successfully:

f = let y = do
        Just 1
    in y

Example 2, causes an error:

f = let y =
        Just 1
    in y

Example 3, causes an error:

f = do
Just 1

This behavior seems inconsistent to me.

See also http://stackoverflow.com/questions/32531508/haskell-parse-error-from-incorrect-indent.

Change History (1)

comment:1 Changed 2 years ago by ezyang

Resolution: invalid
Status: newclosed

This is due to NonDecreasingIndentation, which is not per Haskell98 but useful in cases where you want to open a do-block without increasing indentation. This will parse fail:

{-# LANGUAGE NoNondecreasingIndentation #-}

f = let y = do
        Just 1
    in y

Non-decreasing indentation doesn't work at the top level, because if you applied it there, there would be no indentation you could drop back in order to get out of a do-block.

Note: See TracTickets for help on using tickets.