Consider the following code snippet in Idris:
myList : List Int
myList = [
1,
2,
3
]
The closing delimiter ] is on the same column as the declaration itself. I find this a quite natural way to want to format long, multi-line lists.
However, the equivalent snippet in Haskell fails to compile with a syntax error:
myList :: [Int]
myList = [
1,
2,
3
]
>> main.hs:9:1: error:
>> parse error (possibly incorrect indentation or mismatched brackets)?
>> |
>> 9 | ]
>> | ^
And requires instead the the closing delimiter ] is placed on a column number strictly greater than where the expression is declared. Or at least, as far as I can garner, this seems to be what is going on.
Is there a reason Haskell doesn't like this syntax? I know there are some subtle interactions between the Haskell parser and lexer to enable Haskell's implementation of the offsides rule, so perhaps it has something to do with that.
myList = ...line is assumed to start a new equation (or type signature). Alternatively, such lines can be separated by;as inx = [1,2,3] ; y = "hello". Your indentation is equivalent to writingx = [1,2,3 ; ] y = "hello", which triggers an error. Haskell could have been designed to make an exception when parentheses are unmatched, of course. Still, I don't know what would be the "best" option, both have their pros and cons.