fork(2) download
  1. module Main where
  2.  
  3. -- Integer arithmetic with (+) and (/)
  4. data Term =
  5. N Int
  6. | Plus Term Term
  7. | Div Term Term
  8.  
  9. --
  10. -- Basic evaluator
  11. --
  12.  
  13. eval :: Term -> Int
  14. eval (N n) = n
  15. eval (Plus t1 t2) = eval t1 + eval t2
  16. eval (Div t1 t2) = eval t1 `div` eval t2
  17.  
  18. --
  19. -- Evaluator that counts the number of operations
  20. --
  21.  
  22. inc :: Int -> Int
  23. inc n = n + 1
  24.  
  25. evalWithCount :: Term -> (Int, Int)
  26. evalWithCount t = eval' (0, t)
  27. where
  28. eval' :: (Int, Term) -> (Int, Int)
  29. eval' = undefined
  30. -- The exercise works best if you only use "inc" to bump the accumulator
  31.  
  32. --
  33. -- Evaluator that catches division by zero
  34. --
  35. -- Returns (Ok n) in case of success
  36. -- Returns (Error "Division by zero") otherwise
  37. --
  38.  
  39. data Result a = Error String | Ok a
  40.  
  41. evalChecked :: Term -> Result Int
  42. evalChecked = undefined
  43.  
  44. main = print (undefined::String)
Runtime error #stdin #stdout #stderr 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog: Prelude.undefined
CallStack (from HasCallStack):
  error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
  undefined, called at prog.hs:44:15 in main:Main