Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected token "where" when indentation of do-block same as where #272

Closed
mabre opened this issue Apr 20, 2016 · 7 comments
Closed

unexpected token "where" when indentation of do-block same as where #272

mabre opened this issue Apr 20, 2016 · 7 comments
Assignees

Comments

@mabre
Copy link

mabre commented Apr 20, 2016

The following code, which compiles with ghc, only compiles with frege when removing a space before where

module DoWhere where

main = do
    print x
    where x = 1
E DoWhere.hs:5: unexpected token "where" while trying to
    parse do expression qualifiers
E DoWhere.hs:3: last statement in a monadic do block must
    not be let decls
E DoWhere.hs:5: syntax error on '}'
@Ingo60
Copy link
Member

Ingo60 commented Apr 20, 2016

This seems to employ the following provision in the Haskell report:

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.

This is impossible in Frege, as the layout is done in the lexical analyser.

@Ingo60 Ingo60 added the wontfix label Apr 20, 2016
@Ingo60 Ingo60 self-assigned this Apr 20, 2016
@Ingo60 Ingo60 closed this as completed Apr 20, 2016
@Dierk
Copy link
Member

Dierk commented Apr 20, 2016

How about dealing with this special case by just adding a closing brace before any "where"?

@Ingo60
Copy link
Member

Ingo60 commented Apr 20, 2016

Like in

module Main } where

Dierk???

@Dierk
Copy link
Member

Dierk commented Apr 20, 2016

well, just a bit more intelligently ;-)
Whereas it may be that the "intelligent" bit is the difficult part...

@Ingo60
Copy link
Member

Ingo60 commented Apr 20, 2016

We can, at a later date, explore additional possibilities.
Theoretically, we could have several rules of the form: Instead of issuing a syntax error, insert X in a place where X would be allowed.

Commas, Braces, Parentheses, Brackets, Semicolons, keywords, whatever you want.
It's only making everything more complicated, including resolution of genuine syntax errors. ("Why does it complain about }}}foo when I don't have braces in that line?")

@Dierk
Copy link
Member

Dierk commented Apr 20, 2016

true.

From a pure user standpoint, I would certainly like to have "where" inside "do" blocks - and at the moment I would trade the quality of error messages for that feature. (just my two cents)

@Ingo60
Copy link
Member

Ingo60 commented Apr 20, 2016

A where block can follow any case alternative or RHS of a function or pattern binding. You can, of course, have case expressions and bindings inside a do .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants