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
e256c17d
Commit
e256c17d
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
funclang series4: Made lowercase out of camelcase types.
parent
c81e90da
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
funclang-taddeus/series4/ass10.ml
+21
-17
21 additions, 17 deletions
funclang-taddeus/series4/ass10.ml
with
21 additions
and
17 deletions
funclang-taddeus/series4/ass10.ml
+
21
−
17
View file @
e256c17d
type
arith
O
p
=
Plus
|
Minus
|
Times
|
Divide
|
Modulo
type
rel
O
p
=
Eq
|
Neq
|
Lt
|
Lte
|
Gt
|
Gte
type
logic
O
p
=
And
|
Or
type
bin
O
p
=
ArithOp
of
arith
O
p
|
RelOp
of
rel
O
p
|
LogicOp
of
logic
O
p
type
mon
O
p
=
UnaryMinus
|
Negation
type
arith
_o
p
=
Plus
|
Minus
|
Times
|
Divide
|
Modulo
type
rel
_o
p
=
Eq
|
Neq
|
Lt
|
Lte
|
Gt
|
Gte
type
logic
_o
p
=
And
|
Or
type
bin
_o
p
=
ArithOp
of
arith
_o
p
|
RelOp
of
rel
_o
p
|
LogicOp
of
logic
_o
p
type
mon
_o
p
=
UnaryMinus
|
Negation
type
const
=
BoolConst
of
bool
|
IntConst
of
int
type
expr
=
Enclosure
of
expr
|
BinOp
of
expr
*
bin
O
p
*
expr
|
MonOp
of
mon
O
p
*
expr
|
BinOp
of
expr
*
bin
_o
p
*
expr
|
MonOp
of
mon
_o
p
*
expr
|
Id
of
string
|
Const
of
const
let
rec
eval_expr
=
let
eval_bin
O
p
=
let
eval_arith
O
p
=
function
let
eval_bin
_o
p
=
let
eval_arith
_o
p
=
function
Plus
->
"+"
|
Minus
->
"-"
|
Times
->
"*"
|
Divide
->
"/"
|
Modulo
->
"mod"
in
let
eval_rel
O
p
=
function
let
eval_rel
_o
p
=
function
Eq
->
"="
|
Neq
->
"!="
|
Lt
->
"<"
...
...
@@ -28,16 +28,16 @@ let rec eval_expr =
|
Gt
->
">"
|
Gte
->
">="
in
let
eval_logic
O
p
=
function
let
eval_logic
_o
p
=
function
And
->
"&&"
|
Or
->
"||"
in
function
ArithOp
op
->
eval_arith
O
p
(
op
)
|
RelOp
op
->
eval_rel
O
p
(
op
)
|
LogicOp
op
->
eval_logic
O
p
(
op
)
ArithOp
op
->
eval_arith
_o
p
(
op
)
|
RelOp
op
->
eval_rel
_o
p
(
op
)
|
LogicOp
op
->
eval_logic
_o
p
(
op
)
in
let
eval_mon
O
p
=
function
let
eval_mon
_o
p
=
function
UnaryMinus
->
"-"
|
Negation
->
"!"
in
...
...
@@ -47,25 +47,29 @@ let rec eval_expr =
in
function
Enclosure
e
->
"("
^
eval_expr
(
e
)
^
")"
|
BinOp
(
e1
,
op
,
e2
)
->
eval_expr
(
e1
)
^
" "
^
eval_bin
O
p
(
op
)
|
BinOp
(
e1
,
op
,
e2
)
->
eval_expr
(
e1
)
^
" "
^
eval_bin
_o
p
(
op
)
^
" "
^
eval_expr
(
e2
)
|
MonOp
(
op
,
e
)
->
eval_mon
O
p
(
op
)
^
eval_expr
(
e
)
|
MonOp
(
op
,
e
)
->
eval_mon
_o
p
(
op
)
^
eval_expr
(
e
)
|
Id
id
->
id
|
Const
c
->
eval_const
(
c
)
;;
(* (a) *)
print_endline
(
eval_expr
(
Enclosure
(
Id
"a"
)));;
(* -a *)
print_endline
(
eval_expr
(
MonOp
(
UnaryMinus
,
Id
"a"
)));;
(* a - b *)
print_endline
(
eval_expr
(
BinOp
(
Id
"a"
,
ArithOp
Minus
,
Id
"b"
)));;
(* a * (-b + 1) *)
let
a_times
b
=
BinOp
(
Id
"a"
,
ArithOp
Times
,
b
)
in
let
uminus
a
=
MonOp
(
UnaryMinus
,
a
)
in
let
plus
a
b
=
BinOp
(
a
,
ArithOp
Plus
,
b
)
in
let
one
=
Const
(
IntConst
1
)
in
print_endline
(
eval_expr
(
a_times
(
Enclosure
(
plus
(
uminus
(
Id
"b"
))
one
))));;
(* a = b && c *)
let
b_and_c
=
BinOp
(
Id
"b"
,
LogicOp
And
,
Id
"c"
)
in
print_endline
(
eval_expr
(
BinOp
(
Id
"a"
,
RelOp
Eq
,
b_and_c
)));;
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