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

Parser/Type error for + and - #98

Open
jonmountjoy opened this issue Jun 18, 2017 · 2 comments
Open

Parser/Type error for + and - #98

jonmountjoy opened this issue Jun 18, 2017 · 2 comments

Comments

@jonmountjoy
Copy link

I think #90 from @jeffreyrosenbluth introduced a bug. At least, I think it was that commit.

Prior to this commit (ie. using #1e609fb), you can do something like the following:

Poly> 2 + 3
5 : Int

Now, I get the following:

Poly> 2 + 3
Cannot unify types:
	Int
with
	Int -> a

Weirdly, it works for the * operator, but fails only for + and -:

I suspect there's something weird going on in the parser because:

Poly> 2 + x
"<stdin>" (line 1, column 5):
unexpected "x"
expecting digit
Poly> 2 * x
4 : Int
@jonmountjoy
Copy link
Author

In fact, the error is on this line. If you revert the way terms are parsed, all will be good. ie. Ex.buildExpressionParser table aexp. I don't quite understand the new code, and why it sort of works for some operators...

@tly000
Copy link

tly000 commented Aug 27, 2017

I think i found the problem: The "+" character is parsed as a positive sign inside Tok.integer lexer. I fixed the problem this way:

Parser.hs, line 20

integer :: Parser Integer
integer = Tok.natural lexer

Parser.hs line, 82

aexp :: Parser Expr
aexp = do
  r <- many1 $ choice [parens expr,bool,number,ifthen,fix,try letrecin, letin, lambda, variable]
  return $ foldr1 App r

expr :: Parser Expr
expr = Ex.buildExpressionParser table aexp

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

No branches or pull requests

2 participants