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
_ -> error "Filter argument error"
Map -> case(inputSets', args') of
([Set records], [lambda]) -> Set (map (\record -> eval' $ FuncCall lambda [] [record]) records)
Map -> eval' $ case(inputSets', args') of
([Set records], [lambda]) -> Set (map (\record -> FuncCall lambda [] [record]) records)
_ -> error "Map argument error"
IsEqual -> case args' of -- TODO not sufficent.
[e1, e2] -> Boolean (e1 == e2)
_ -> error "isEqual argument error"
XProduct -> case inputSets' of
[(Set l1), (Set l2)] -> Set $ [ x `concatRecord` y | x <- l1, y <- l2]
XProduct -> eval' $ case inputSets' of
[Set l1, Set l2] -> Set $ [ x `concatRecord` y | x <- l1, y <- l2]
_ -> error "X product takes in two sets"
(BooleanFunc op) -> case args' of
......@@ -40,7 +40,6 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
RecordIndex -> eval' $ case args' of
[Record recordData,Int index] -> recordData `listAtIndex` index
--TODO CBH
RecordSelect -> case args' of
(Record recordData: indexes ) -> Record filteredList
where
......@@ -74,13 +73,10 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
Not -> case args' of
[Boolean exp1] -> Boolean $ not exp1
--implement later
--(Map) -> Set $ (map (\r -> FuncCall predicate [] [r]) inputRecords)
(FuncDef setParams argParams body) -> eval newEnv body
where
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
(Just value) -> eval' value
Nothing -> error $ "Variable " ++ name ++ " not found."
......@@ -97,7 +93,7 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
eval newEnv newControl
(Record exprs) -> Record $ map eval' exprs
(Record exprs) -> Record $ map eval' exprs
(Set exprs) -> Set $ map eval' exprs
_ -> expr
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