title: How to create a simple calculator on Haskell?
body: <p>I want to implement a program that reads a string and performs mathematical operations on it.</p>
  
  <pre><code>addop, mulop :: Parser (Expr -&gt; Expr -&gt; Expr)
  addop = (infixOp "+" Add) &lt;|&gt; (infixOp "-" Sub)
  mulop = infixOp "*" Mul
  
  int :: Parser Expr
  int = do
    n &lt;- number
    return (Lit n)
  
  expr :: Parser Expr
  expr = term `chainl1` addop
  
  term :: Parser Expr
  term = factor `chainl1` mulop
  
  factor :: Parser Expr
  factor = int &lt;|&gt; parens expr
  
  run :: String -&gt; Expr
  run = runParser expr
  
  eval :: Expr -&gt; Int
  eval ex = case ex of
     Add a b -&gt; eval a + eval b
     Mul a b -&gt; eval a * eval b
     Sub a b -&gt; eval a - eval b
     Lit n   -&gt; n
  
  evExpr :: String -&gt; Maybe Integer
  evExpr [] = Nothing
  evExpr str = Just (eval (run str))
  </code></pre>
  
  <p>But I have error:</p>
  
  <pre><code>• 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))
     |              ^^^^^^^^^^^^^^^^^^^^^
  </code></pre>
  
  <p>and</p>
  
  <pre><code> • Couldn't match type ‘SourceName
                         -&gt; [Char] -&gt; Either ParseError Expr’
                   with ‘Expr’
    Expected type: String -&gt; Expr
      Actual type: () -&gt; SourceName -&gt; [Char] -&gt; 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
     |       ^^^^^^^^^^^^^^
  </code></pre>
  
  <p>When the program is working correctly, I should see like this:</p>
  
  <p>•  evExpr “27-(6*3+5%2)” = Just 8</p>
  
  <p>Help me please. Thank you</p>