Commit 54752cc3 authored by pm3g19's avatar pm3g19
Browse files

Neatened up evaluation

parent e04ef58f
...@@ -22,16 +22,16 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o ...@@ -22,16 +22,16 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
_ -> error "Filter argument error" _ -> error "Filter argument error"
Map -> case(inputSets', args') of Map -> eval' $ case(inputSets', args') of
([Set records], [lambda]) -> Set (map (\record -> eval' $ FuncCall lambda [] [record]) records) ([Set records], [lambda]) -> Set (map (\record -> FuncCall lambda [] [record]) records)
_ -> error "Map argument error" _ -> error "Map argument error"
IsEqual -> case args' of -- TODO not sufficent. IsEqual -> case args' of -- TODO not sufficent.
[e1, e2] -> Boolean (e1 == e2) [e1, e2] -> Boolean (e1 == e2)
_ -> error "isEqual argument error" _ -> error "isEqual argument error"
XProduct -> case inputSets' of XProduct -> eval' $ case inputSets' of
[(Set l1), (Set l2)] -> Set $ [ x `concatRecord` y | x <- l1, y <- l2] [Set l1, Set l2] -> Set $ [ x `concatRecord` y | x <- l1, y <- l2]
_ -> error "X product takes in two sets" _ -> error "X product takes in two sets"
(BooleanFunc op) -> case args' of (BooleanFunc op) -> case args' of
...@@ -40,7 +40,6 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o ...@@ -40,7 +40,6 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
RecordIndex -> eval' $ case args' of RecordIndex -> eval' $ case args' of
[Record recordData,Int index] -> recordData `listAtIndex` index [Record recordData,Int index] -> recordData `listAtIndex` index
--TODO CBH
RecordSelect -> case args' of RecordSelect -> case args' of
(Record recordData: indexes ) -> Record filteredList (Record recordData: indexes ) -> Record filteredList
where where
...@@ -74,13 +73,10 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o ...@@ -74,13 +73,10 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
Not -> case args' of Not -> case args' of
[Boolean exp1] -> Boolean $ not exp1 [Boolean exp1] -> Boolean $ not exp1
--implement later
--(Map) -> Set $ (map (\r -> FuncCall predicate [] [r]) inputRecords)
(FuncDef setParams argParams body) -> eval newEnv body (FuncDef setParams argParams body) -> eval newEnv body
where where
newEnv = let (setEnv, argsEnv) = (zip setParams inputSets, zip argParams args) in setEnv ++ argsEnv ++ env newEnv = let (setEnv, argsEnv) = (zip setParams inputSets, zip argParams args) in setEnv ++ argsEnv ++ env
--newEnv = foldl (\env entry@(name, expr) -> addVar env name expr) env --adds entries to environment
-- TODO FIX
(Var name) -> case findVar env name of (Var name) -> case findVar env name of
(Just value) -> eval' value (Just value) -> eval' value
Nothing -> error $ "Variable " ++ name ++ " not found." Nothing -> error $ "Variable " ++ name ++ " not found."
...@@ -97,7 +93,7 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o ...@@ -97,7 +93,7 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
eval newEnv newControl eval newEnv newControl
(Record exprs) -> Record $ map eval' exprs (Record exprs) -> Record $ map eval' exprs
(Record exprs) -> Record $ map eval' exprs (Set exprs) -> Set $ map eval' exprs
_ -> expr _ -> expr
listAtIndex :: [a] -> Int -> a listAtIndex :: [a] -> Int -> a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment