Talk:Haskell/Indentation/Archive 1

Discussion from Talk:Haskell/Solutions/Indentation
I'm confused about one thing: Would the solution to the second exercise be of {a ;b c    ;d }where {a ;b ;c ;do {you like ;the }}way i let {myself abuse ;these }layout rules or of {a ;b c    ;d }where {a ;b ;c }do {you like ;the }way i let {myself abuse ;these }layout rules ? According to the 3 rules given in the indentation chapter, since do is at the same level as the preceding expression, c, a semicolon should be added instead of a close brace. HOWEVER: main = do print x  where x = 5 prints 5 (in GHC), whereas main = do {print x  ;where {x = 5}} gives "parse error on input `where'" even though where is on the same level of indentation as print x so according to the 3 rules, a semicolon should be inserted. However main = do {print x  }where {x = 5}} successfully parses and prints 5. -Qeny 11:27, 31 July 2007 (UTC)


 * Uh-oh. You might have found a bug in my interpretation of the Haskell report.  Would you be willing to chase up on it?  The informal explanation in Section 2.7 and Section 9.3 has the more precise rules.  If not, please check with the Haskell Café or the #haskell channel.  Sorry! -- Kowey 12:04, 31 July 2007 (UTC)


 * To follow up: I suspect that the relevant snippet is "A close brace is also inserted whenever the syntactic category containing the layout list ends; that is, if an illegal lexeme is encountered at a point where a close brace would be legal, a close brace is inserted.", so maybe there needs to be a fourth informal rule, like "if you see something unexpected, (like 'where'), insert a close brace", but maybe that would have its own share of bugs. (FWIW, the first solution looks more like what I was expecting; on the other hand, for your minimal example, this new fourth rule would explain the second ws to layout translation).  Frankly, I don't really know much what I'm talking about and was only interpreting the Haskell Report to the best of my ability. -- Kowey 12:09, 31 July 2007 (UTC)


 * I think that's exactly what we should be put for the fourth rule, then everything would be okay. I guess the question for the example though, is whether "do" is an illegal lexeme to be in a where list. I would guess that it is, because afaik a  list item always supposed to be like  . And what is a lexeme anyway, are ,  , and   lexemes? I guess they would be legal but invalid 'cause they aren't followed by  . --Qeny 08:28, 1 August 2007 (UTC)