Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addop, mulop :: Parser (Expr -> Expr -> Expr)
- addop = (infixOp "+" Add) <|> (infixOp "-" Sub)
- mulop = infixOp "*" Mul
- int :: Parser Expr
- int = do
- n <- number
- return (Lit n)
- expr :: Parser Expr
- expr = term `chainl1` addop
- term :: Parser Expr
- term = factor `chainl1` mulop
- factor :: Parser Expr
- factor = int <|> parens expr
- run :: String -> Expr
- run = runParser expr
- eval :: Expr -> Int
- eval ex = case ex of
- Add a b -> eval a + eval b
- Mul a b -> eval a * eval b
- Sub a b -> eval a - eval b
- Lit n -> n
- evExpr :: String -> Maybe Integer
- evExpr [] = Nothing
- evExpr str = Just (eval (run str))
- • Couldn't match type ‘Int’ with ‘Integer’
- Expected type: Maybe Integer
- Actual type: Maybe Int
- • In the expression: Just (eval (run str))
- In an equation for ‘evExpr’: evExpr str = Just (eval (run str))
- |
- 37 | evExpr str = Just (eval (run str))
- | ^^^^^^^^^^^^^^^^^^^^^
- • Couldn't match type ‘SourceName
- -> [Char] -> Either ParseError Expr’
- with ‘Expr’
- Expected type: String -> Expr
- Actual type: () -> SourceName -> [Char] -> Either ParseError Expr
- • Probable cause: ‘runParser’ is applied to too few arguments
- In the expression: runParser expr
- In an equation for ‘run’: run = runParser expr
- |
- 26 | run = runParser expr
- | ^^^^^^^^^^^^^^
Add Comment
Please, Sign In to add comment