🎣 Add TryCatchOp and add our eval. catch implementation and runeval missing
This commit is contained in:
@ -20,7 +20,7 @@ evalIntBinOp' f e1 e2 =
|
||||
where
|
||||
f' x y = pure $ f x y
|
||||
|
||||
-- Replace with your 'eval' from your solution to assignment 2.
|
||||
-- Replaced their eval with ours as instructed NOTE
|
||||
eval :: Exp -> EvalM Val
|
||||
eval (CstInt x) = pure $ ValInt x
|
||||
eval (CstBool b) = pure $ ValBool b
|
||||
@ -71,3 +71,23 @@ eval (Apply e1 e2) = do
|
||||
failure "Cannot apply non-function"
|
||||
eval (TryCatch e1 e2) =
|
||||
eval e1 `catch` eval e2
|
||||
eval (Print s e1) = do
|
||||
v1 <- eval e1
|
||||
case v1 of
|
||||
(ValInt i) -> do
|
||||
evalPrint (s++": "++(show i))
|
||||
pure $ v1
|
||||
(ValBool b) -> do
|
||||
evalPrint (s++": "++(show b))
|
||||
pure $ v1
|
||||
(ValFun _ _ _) -> do
|
||||
evalPrint (s++": #<fun>")
|
||||
pure $ v1
|
||||
eval (KvPut e1 e2) = do
|
||||
v1 <- eval e1
|
||||
v2 <- eval e2
|
||||
evalKvPut v1 v2
|
||||
pure $ v2
|
||||
eval (KvGet e) = do
|
||||
v <- eval e
|
||||
evalKvGet v
|
||||
|
Reference in New Issue
Block a user