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
b98b9952
Commit
b98b9952
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
funclang series5: Source code cleanup.
parent
a8a58134
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
+6
-3
6 additions, 3 deletions
funclang-taddeus/series5/ass13.ml
funclang-taddeus/series5/test.ml
+2
-1
2 additions, 1 deletion
funclang-taddeus/series5/test.ml
with
8 additions
and
4 deletions
funclang-taddeus/series5/ass13.ml
+
6
−
3
View file @
b98b9952
...
...
@@ -9,8 +9,9 @@ let rec eval exp =
|
_
->
raise
(
Failure
"Unknown unary operator"
)
in
let
eval_binop
binop
=
match
binop
with
(
op
,
Num
a
,
Num
b
)
->
(
match
op
with
(
op
,
Num
a
,
Num
b
)
->
(* Arithmethic or relational operation is possible on numbers *)
(
match
op
with
Add
->
Num
(
a
+
b
)
|
Sub
->
Num
(
a
-
b
)
|
Mul
->
Num
(
a
*
b
)
...
...
@@ -23,9 +24,11 @@ let rec eval exp =
|
Gt
->
Bool
(
a
>
b
)
|
Ge
->
Bool
(
a
>=
b
)
|
_
->
raise
(
Failure
"Unknown arithmetic/relational operator"
))
|
(
op
,
Bool
a
,
Bool
b
)
->
(
match
op
with
|
(
op
,
Bool
a
,
Bool
b
)
->
(* Locical operation is possible on booleans *)
And
|
Or
->
Bool
(
if
op
=
And
then
a
&&
b
else
a
||
b
)
(
match
op
with
And
->
Bool
(
a
&&
b
)
|
Or
->
Bool
(
a
||
b
)
|
_
->
raise
(
Failure
"Unknown locical operator"
))
|
(
op
,
e1
,
e2
)
->
BinopAp
(
op
,
eval
e1
,
eval
e2
)
in
...
...
This diff is collapsed.
Click to expand it.
funclang-taddeus/series5/test.ml
+
2
−
1
View file @
b98b9952
...
...
@@ -29,7 +29,7 @@ test_expr2string "a * 3" (BinopAp (Mul, Var "a", Num 3));;
let
l
arg
body
=
Fun
(
arg
,
body
);;
let
app
func
arg
=
FunAp
(
func
,
arg
);;
(* Define resursive factorial function for
test usage
*)
(* Define resursive factorial function for
a more extensive test
*)
let
fac
=
let
eq
=
BinopAp
(
Eq
,
Var
"n"
,
Num
0
)
in
let
sub
=
BinopAp
(
Sub
,
Var
"n"
,
Num
1
)
in
...
...
@@ -81,6 +81,7 @@ test_eval "c + b" (Let ("a", Var "c", (BinopAp (Add, Var "a", Var "b"))));;
test_eval
"a"
(
Cond
(
Bool
true
,
Var
"a"
,
Var
"b"
));;
test_eval
"b"
(
Cond
(
Bool
false
,
Var
"a"
,
Var
"b"
));;
(* Test resolving of name clash *)
let
x
=
Var
"x"
in
let
y
=
Var
"y"
in
let
z
=
Var
"z"
in
...
...
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