Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp2212-cw-2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PLC
comp2212-cw-2021
Commits
54752cc3
Commit
54752cc3
authored
4 years ago
by
pm3g19
Browse files
Options
Downloads
Patches
Plain Diff
Neatened up evaluation
parent
e04ef58f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Eval.hs
+6
-10
6 additions, 10 deletions
Eval.hs
with
6 additions
and
10 deletions
Eval.hs
+
6
−
10
View file @
54752cc3
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment