Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
b98b9952
Commit
b98b9952
authored
Dec 05, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
funclang series5: Source code cleanup.
parent
a8a58134
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
funclang-taddeus/series5/ass13.ml
funclang-taddeus/series5/ass13.ml
+6
-3
funclang-taddeus/series5/test.ml
funclang-taddeus/series5/test.ml
+2
-1
No files found.
funclang-taddeus/series5/ass13.ml
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
...
...
funclang-taddeus/series5/test.ml
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment