Opened 4 years ago

Closed 4 years ago

#9042 closed bug (invalid)

List indenting in case fails

Reported by: laar Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.2
Keywords: 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:


The following code fails to parse

module Temp where

t = case [1..2] of
        [ 1
        , 2
        ] -> True
        _ -> False


    parse error (possibly incorrect indentation or mismatched brackets)

Which relates to the line , 2. Indenting both that line and the next one is needed to parse the module. This is contrary to what I suspected. As this vertical layout for lists is allowed as expression, I would also expect it to work for patterns.

Change History (1)

comment:1 Changed 4 years ago by goldfire

Resolution: invalid
Status: newclosed

I would say GHC's behavior in this case is correct. According to (my understanding of) the layout rule, the first character after a layout herald (the of, in your case) sets the new indentation level (provided it is not too far left!). So, your open-bracket sets the indentation level. Then, your comma is at the same level of indentation, so GHC inserts a ; before the comma, causing the parse error.

So, that syntax is available in patterns, as witness by the following (accepted) code:

t = case Just [1..2] of
        Just [ 1
             , 2
             ] -> True
        _ -> False

In this example, the J of the Just in the pattern sets the indentation level, so there's no problem laying out the list vertically.

Note: See TracTickets for help on using tickets.