diff options
author | Edoardo La Greca | 2025-07-09 22:35:50 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-07-09 22:35:50 +0200 |
commit | 319643faf6baea1c44f68800cba1947799935d05 (patch) | |
tree | 24d668ac4e0bde3579085279009cd5f51085b3e6 /lec05/Calc.hs | |
parent | 9e4698b5e7904e7dafd62a2682713742fd3eb198 (diff) |
add second exercise of lecture 5
Diffstat (limited to 'lec05/Calc.hs')
-rw-r--r-- | lec05/Calc.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lec05/Calc.hs b/lec05/Calc.hs index 8051d76..cd6f408 100644 --- a/lec05/Calc.hs +++ b/lec05/Calc.hs @@ -1,6 +1,7 @@ module Calc where import ExprT +import Parser -- Exercise 1 @@ -8,3 +9,10 @@ eval :: ExprT -> Integer eval (Lit n) = n eval (Add l r) = eval l + eval r eval (Mul l r) = eval l * eval r + +-- Exercise 2 + +evalStr :: String -> Maybe Integer +evalStr s = case parseExp Lit Add Mul s of + Nothing -> Nothing + Just t -> Just (eval t) |