Skip to content

Commit

Permalink
Missing case eval
Browse files Browse the repository at this point in the history
  • Loading branch information
SophieBosio committed Jan 15, 2024
1 parent b56266d commit d3e754d
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ evaluate (Pattern (Constructor c ps a)) =
do ts <- mapM evaluate (Pattern <$> ps)
ps' <- mapM (return . strengthenToPattern) ts
return $ Pattern (Constructor c ps' a)
-- evaluate (Rec x t0 a) =
-- do notAtTopLevel (x, a)
-- evaluate (substitute x t0 (Rec x t0 a))
-- evaluate (Let x t0 t1 a) =
-- do notAtTopLevel (x, a)
-- evaluate t0 >>= evaluate . substitute x t1
-- evaluate (Application t1 t2 _) =
-- do f <- evaluate t1 >>= function
-- x <- evaluate t2
-- evaluate (f x)
evaluate (Rec x t0 a) =
do notAtTopLevel (x, a)
evaluate (substitute x t0 (Rec x t0 a))
evaluate (Let x t0 t1 a) =
do notAtTopLevel (x, a)
evaluate t0 >>= evaluate . substitute x t1
evaluate (Application t1 t2 _) =
do f <- evaluate t1 >>= function
x <- evaluate t2
evaluate (f x)
-- evaluate (Case t0 ts _) =
-- do v <- evaluate t0
-- let us = map (first $ unify v) ts
Expand Down Expand Up @@ -121,8 +121,14 @@ pair :: Show a => Term a -> Runtime a (Term a, Term a)
pair (Pattern (Pair t1 t2 _)) = return (t1, t2)
pair t = error $ "expected a pair, but got a " ++ show t

-- function :: Show a => Term a -> Runtime a (Term a -> Term a)
-- function (Lambda x t a) =
-- do notAtTopLevel (x, a)
-- return $ substitute x t
-- function t = error $ "expected a function, but got a " ++ show t
function :: Show a => Term a -> Runtime a (Term a -> Term a)
function (Lambda x t a) =
do notAtTopLevel (x, a)
return $ substitute x t
function t = error $ "expected a function, but got a " ++ show t

notAtTopLevel :: (X, a) -> Runtime a ()
notAtTopLevel (x, _) =
do program <- ask
when (x `elem` (fst <$> functions program)) $
error $ "the name " ++ x ++ "shadows the top level declaration of " ++ x

0 comments on commit d3e754d

Please sign in to comment.