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

Chapter 7. Fix issue #34. Parsing function application. #90

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions chapter7/poly/src/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool = (reserved "True" >> return (Lit (LBool True)))
fix :: Parser Expr
fix = do
reservedOp "fix"
x <- aexp
x <- expr
return (Fix x)

lambda :: Parser Expr
Expand Down Expand Up @@ -71,11 +71,11 @@ letrecin = do
ifthen :: Parser Expr
ifthen = do
reserved "if"
cond <- aexp
cond <- expr
reservedOp "then"
tr <- aexp
tr <- expr
reserved "else"
fl <- aexp
fl <- expr
return (If cond tr fl)

aexp :: Parser Expr
Expand All @@ -91,7 +91,9 @@ aexp =
<|> variable

term :: Parser Expr
term = Ex.buildExpressionParser table aexp
term = aexp >>= \x ->
(many1 aexp >>= \xs -> return (foldl App x xs))
<|> return x

infixOp :: String -> (a -> a -> a) -> Ex.Assoc -> Op a
infixOp x f = Ex.Infix (reservedOp x >> return f)
Expand All @@ -111,9 +113,7 @@ table = [
]

expr :: Parser Expr
expr = do
es <- many1 term
return (foldl1 App es)
expr = Ex.buildExpressionParser table term

type Binding = (String, Expr)

Expand Down
16 changes: 8 additions & 8 deletions chapter7/poly_constraints/src/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool = (reserved "True" >> return (Lit (LBool True)))
fix :: Parser Expr
fix = do
reservedOp "fix"
x <- aexp
x <- expr
return (Fix x)

lambda :: Parser Expr
Expand Down Expand Up @@ -71,11 +71,11 @@ letrecin = do
ifthen :: Parser Expr
ifthen = do
reserved "if"
cond <- aexp
cond <- expr
reservedOp "then"
tr <- aexp
tr <- expr
reserved "else"
fl <- aexp
fl <- expr
return (If cond tr fl)

aexp :: Parser Expr
Expand All @@ -91,7 +91,9 @@ aexp =
<|> variable

term :: Parser Expr
term = Ex.buildExpressionParser table aexp
term = aexp >>= \x ->
(many1 aexp >>= \xs -> return (foldl App x xs))
<|> return x

infixOp :: String -> (a -> a -> a) -> Ex.Assoc -> Op a
infixOp x f = Ex.Infix (reservedOp x >> return f)
Expand All @@ -111,9 +113,7 @@ table = [
]

expr :: Parser Expr
expr = do
es <- many1 term
return (foldl1 App es)
expr = Ex.buildExpressionParser table term

type Binding = (String, Expr)

Expand Down