Skip to content
Snippets Groups Projects
Commit 934a4993 authored by pm3g19's avatar pm3g19
Browse files

Added support for extra functions, untested

parent 87fd77bb
No related branches found
No related tags found
No related merge requests found
......@@ -19,14 +19,43 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
Filter -> let (Set inputRecords,predicate) = (eval' $ head inputSets, eval' $ head args) in
Set $ filter ((==Boolean True).(\r -> eval' $ FuncCall predicate [] [r])) $ map eval' inputRecords
Map -> Set (map (\record -> FuncCall lambda [] [record]) records)
where
(Set records:_) = inputSets
(lambda:_) = args
IsEqual -> let (e1:e2:_) = args in -- TODO not sufficent.
Boolean (eval' e1 == eval' e2)
XProduct -> let ((Set l1): (Set l2):_) = map eval' inputSets in
Set $ [ x `concatRecord` y | x <- l1, y <- l2]
RecordIndex -> let (Record recordData:Int index:_) = (map eval' args) in
recordData !! index
XProduct -> debug (show env) $ let ((Set l1): (Set l2):_) = map eval' inputSets in
Set $ [ x `concatRecord` y | x <- l1, y <- l2]
RecordSelect -> Record filteredList
where
(Record recordData: indexes) = args
indexesRaw = map (\(Int i) -> i) indexes
filteredList = map (recordData!!) indexesRaw
{-numberedElems = zip [1..] recordData :: [(Int, Expr)]
filtered = filter ((`elem` indexesRaw).fst) numberedElems :: [(Int, Expr)]
filteredList = map snd filtered :: [Expr]-}
IsEmpty -> case eval' (head args) of
(String a) -> Boolean $ null a
Contains -> case args of
(mainString:containsWhat:_) -> case (eval' mainString , eval' containsWhat) of
(String a, String b) -> a `beginsWith` b
Plus -> let (e1:e2:_) = args in case (eval' e1, eval' e2) of
(String a, String b) -> String (a ++ b)
(Record a, Record b) -> Record (a ++ b)
_ -> error "eval error"
--implement later
--(Map) -> Set $ (map (\r -> FuncCall predicate [] [r]) inputRecords)
......@@ -37,6 +66,11 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
-- TODO FIX
(Var name) -> eval' $ findVar env name
control@(Control lastResult exprs) -> if null exprs then lastResult else eval' $ evalControl1 env control
_ -> expr
......@@ -52,4 +86,5 @@ evalFull = eval
--evalFull env (Set xs) = Set (map (eval env) xs) -- evaluates expression fully (not just weak head normal form)
--evalFull _ e = e
--TODO implement properly
concatRecord (Record r1) (Record r2) = Record (r1 ++ r2)
\ No newline at end of file
concatRecord (Record r1) (Record r2) = Record (r1 ++ r2)
beginsWith = notImplemented
\ No newline at end of file
This diff is collapsed.
......@@ -7,16 +7,17 @@ type Environment = [(SymbolName, Expr)] -- (result of last calculation, other bi
--data OutputLine = Let SymbolName Expr | Expr -- Expr always a function call for a set function, but not enforced by AST.
type Output = [Expr]
data PredefFunc = XProduct | XXProduct | IsEqual | IsNotEqual | Add --operators
data PredefFunc = XProduct | XXProduct | IsEqual | IsNotEqual | Plus --operators
| Map | Filter
| RecordIndex -- [] operator
| IsEmpty | NotEmpty -- string functions
| RecordSelect
| IsEmpty | NotEmpty | Contains | IsSubString -- string functions
deriving (Show, Eq)
--n.b. these definitions do not enforce type checking! The use of any function or operator will be associated with a FuncCall.
--Therefore, it is possible to have ASTs with ridiculous things where e.g. a XX product is applied to and int and a String, or a function call has an Int as a function!
--These issues will be checked via the type checker after the AST has been built.
--These issues can be checked via the type checker after the AST has been built.
-- filter [A] (\(r) -> r[1] == "hello")
-- FuncCall (PredefFunc Filter) [Var "A"] [FuncDef [] ["r"] [(FuncCall (PredefFunc IsEqual) [] (r[1]) ("hello"))]]
......@@ -34,6 +35,7 @@ data Expr = Control Expr [Expr] -- result of last computation, sequence of instr
| Int Int
| String String
| Boolean Bool
-- | Nat Int
deriving (Show, Eq)
data Parameter = NamedParam SymbolName | TupleMatch [SymbolName]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment