Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
uva
Commits
7ee42f71
Commit
7ee42f71
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
funclang series5: Added evaluation of monops/binops.
parent
fab70057
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
funclang-taddeus/series5/ass13.ml
+38
-3
38 additions, 3 deletions
funclang-taddeus/series5/ass13.ml
funclang-taddeus/series5/test.ml
+9
-1
9 additions, 1 deletion
funclang-taddeus/series5/test.ml
with
47 additions
and
4 deletions
funclang-taddeus/series5/ass13.ml
+
38
−
3
View file @
7ee42f71
...
...
@@ -2,9 +2,44 @@
(* Perform all possible beta-reductions on an expression until the normal form
* has been reached *)
let
rec
eval
exp
=
match
exp
with
MonopAp
(
op
,
e
)
->
MonopAp
(
op
,
eval
e
)
|
BinopAp
(
op
,
e1
,
e2
)
->
BinopAp
(
op
,
eval
e1
,
eval
e2
)
let
rec
eval
exp
=
let
get_int_value
=
function
Num
i
->
i
|
_
->
raise
(
Failure
"Not an integer"
)
in
let
get_bool_value
=
function
Bool
b
->
b
|
_
->
raise
(
Failure
"Not a boolean"
)
in
let
eval_monop
op
a
=
match
op
with
Neg
->
Num
(
-
(
get_int_value
a
))
|
Not
->
Bool
(
not
(
get_bool_value
a
))
in
let
eval_binop
op
x
y
=
match
op
with
And
|
Or
->
let
a
=
get_bool_value
x
in
let
b
=
get_bool_value
y
in
(
match
op
with
And
->
Bool
(
a
&&
b
)
|
Or
->
Bool
(
a
||
b
))
|
_
->
let
a
=
get_int_value
x
in
let
b
=
get_int_value
y
in
(
match
op
with
Add
->
Num
(
a
+
b
)
|
Sub
->
Num
(
a
-
b
)
|
Mul
->
Num
(
a
*
b
)
|
Div
->
Num
(
a
/
b
)
|
Eq
->
Bool
(
a
=
b
)
|
Ne
->
Bool
(
a
!=
b
)
|
Lt
->
Bool
(
a
<
b
)
|
Le
->
Bool
(
a
<=
b
)
|
Gt
->
Bool
(
a
>
b
)
|
Ge
->
Bool
(
a
>=
b
))
in
match
exp
with
MonopAp
(
op
,
e
)
->
eval_monop
op
(
eval
e
)
|
BinopAp
(
op
,
e1
,
e2
)
->
eval_binop
op
(
eval
e1
)
(
eval
e2
)
|
Fun
(
x
,
e
)
->
Fun
(
x
,
eval
e
)
|
FunAp
(
Fun
(
x
,
Var
y
)
,
a
)
when
y
=
x
->
eval
a
(* identity function *)
|
FunAp
(
Fun
(
y
,
e
)
,
a
)
->
(* prevent recursion *)
...
...
This diff is collapsed.
Click to expand it.
funclang-taddeus/series5/test.ml
+
9
−
1
View file @
7ee42f71
#
use
"ass12.ml"
;;
#
use
"ass13.ml"
;;
(* let a = 1 in b *)
...
...
@@ -68,6 +67,15 @@ let show_eval e =
^
"
\n
is:
\n
"
^
(
expr2string
(
eval
e
)))
;;
(* -5 *)
show_eval
(
BinopAp
(
Sub
,
Num
4
,
Num
9
));;
(* false *)
show_eval
(
BinopAp
(
Lt
,
Num
6
,
Num
5
));;
(* true *)
show_eval
(
BinopAp
(
Or
,
Bool
true
,
Bool
false
));;
(* fun u -> fun w -> fun a -> a *)
show_eval
ass1a
;;
...
...
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