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
6f9f38c3
Commit
6f9f38c3
authored
Jan 06, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup.
parent
2091563a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
29 deletions
+27
-29
funclang-taddeus/series4/ass10.ml
funclang-taddeus/series4/ass10.ml
+8
-8
funclang-taddeus/series6/ass14.ml
funclang-taddeus/series6/ass14.ml
+9
-9
funclang-taddeus/series6/ass16.ml
funclang-taddeus/series6/ass16.ml
+10
-12
No files found.
funclang-taddeus/series4/ass10.ml
View file @
6f9f38c3
...
...
@@ -5,7 +5,7 @@ type bin_op = ArithOp of arith_op | RelOp of rel_op | LogicOp of logic_op
type
mon_op
=
UnaryMinus
|
Negation
type
const
=
BoolConst
of
bool
|
IntConst
of
int
type
expr
=
Enclosure
of
expr
Enclosure
of
expr
|
BinOp
of
expr
*
bin_op
*
expr
|
MonOp
of
mon_op
*
expr
|
Id
of
string
...
...
@@ -15,14 +15,14 @@ type expr =
let
rec
eval_expr
=
let
eval_bin_op
=
let
eval_arith_op
=
function
Plus
->
"+"
|
Plus
->
"+"
|
Minus
->
"-"
|
Times
->
"*"
|
Divide
->
"/"
|
Modulo
->
"mod"
in
let
eval_rel_op
=
function
Eq
->
"="
|
Eq
->
"="
|
Neq
->
"!="
|
Lt
->
"<"
|
Lte
->
"<="
...
...
@@ -30,24 +30,24 @@ let rec eval_expr =
|
Gte
->
">="
in
let
eval_logic_op
=
function
And
->
"&&"
|
And
->
"&&"
|
Or
->
"||"
in
function
ArithOp
op
->
eval_arith_op
(
op
)
|
ArithOp
op
->
eval_arith_op
(
op
)
|
RelOp
op
->
eval_rel_op
(
op
)
|
LogicOp
op
->
eval_logic_op
(
op
)
in
let
eval_mon_op
=
function
UnaryMinus
->
"-"
|
UnaryMinus
->
"-"
|
Negation
->
"!"
in
let
eval_const
=
function
IntConst
i
->
string_of_int
i
|
IntConst
i
->
string_of_int
i
|
BoolConst
b
->
string_of_bool
b
in
function
Enclosure
e
->
"("
^
eval_expr
(
e
)
^
")"
|
Enclosure
e
->
"("
^
eval_expr
(
e
)
^
")"
|
BinOp
(
e1
,
op
,
e2
)
->
eval_expr
(
e1
)
^
" "
^
eval_bin_op
(
op
)
^
" "
^
eval_expr
(
e2
)
|
MonOp
(
op
,
e
)
->
eval_mon_op
(
op
)
^
eval_expr
(
e
)
...
...
funclang-taddeus/series6/ass14.ml
View file @
6f9f38c3
...
...
@@ -9,17 +9,17 @@ let emptySet = Set([])
(* Delete an element from a set (if it does not exists in it yet)
* and return the new set with the element *)
let
addElem
elem
set
=
match
set
with
Set
([])
->
Set
([
elem
])
|
Set
([])
->
Set
([
elem
])
|
Set
(
l
)
->
if
List
.
mem
elem
l
then
set
else
Set
(
elem
::
l
)
(* Delete an element from a set (if it exists in it) and return
* the new set without the element *)
let
delElem
elem
set
=
let
rec
delFromList
elem
=
function
[]
->
[]
|
[]
->
[]
|
h
::
t
->
if
h
=
elem
then
t
else
h
::
(
delFromList
elem
t
)
in
match
set
with
Set
([])
->
set
|
Set
([])
->
set
|
Set
(
l
)
->
Set
(
delFromList
elem
l
)
(* Check if an element exists in a set *)
...
...
@@ -28,19 +28,19 @@ let isElem elem = function Set (l) -> List.mem elem l
(* Get the union of sets a and b as a new set *)
let
union
a
b
=
match
a
with
Set
([])
->
b
|
Set
([])
->
b
|
Set
(
la
)
->
match
b
with
Set
([])
->
a
|
Set
([])
->
a
|
Set
(
lb
)
->
Set
(
la
@
List
.
filter
(
fun
e
->
not
(
List
.
mem
e
la
))
lb
)
(* Get the intersection of sets a and b as a new set *)
let
intersection
a
b
=
match
a
with
Set
([])
->
a
|
Set
([])
->
a
|
Set
(
la
)
->
match
b
with
Set
([])
->
b
|
Set
(
lb
)
->
|
Set
([])
->
b
|
Set
(
lb
)
->
let
b_in_a
=
List
.
filter
(
fun
e
->
List
.
mem
e
la
)
lb
in
Set
(
List
.
filter
(
fun
e
->
List
.
mem
e
lb
)
b_in_a
)
...
...
@@ -63,4 +63,4 @@ let b = addElem 9 b;;
let
b
=
addElem
0
b
;;
(* 0, 9, 3, 8, 2 *)
union
a
b
;;
(* 1, 7, 3, 8, 2, 0, 9 *)
intersection
a
b
;;
(* 3, 8, 2 *)
\ No newline at end of file
intersection
a
b
;;
(* 3, 8, 2 *)
funclang-taddeus/series6/ass16.ml
View file @
6f9f38c3
module
type
SET
=
sig
module
type
SET
=
sig
type
'
a
set
val
emptySet
:
'
a
set
val
addElem
:
'
a
->
'
a
set
->
'
a
set
...
...
@@ -9,8 +8,7 @@ sig
val
intersection
:
'
a
set
->
'
a
set
->
'
a
set
end
module
Set
:
SET
=
struct
module
Set
:
SET
=
struct
type
'
a
set
=
Set
of
'
a
list
(* Create an empty set *)
...
...
@@ -19,17 +17,17 @@ struct
(* Delete an element from a set (if it does not exists in it yet)
* and return the new set with the element *)
let
addElem
elem
set
=
match
set
with
Set
([])
->
Set
([
elem
])
|
Set
([])
->
Set
([
elem
])
|
Set
(
l
)
->
if
List
.
mem
elem
l
then
set
else
Set
(
elem
::
l
)
(* Delete an element from a set (if it exists in it) and return
* the new set without the element *)
let
delElem
elem
set
=
let
rec
delFromList
elem
=
function
[]
->
[]
|
[]
->
[]
|
h
::
t
->
if
h
=
elem
then
t
else
h
::
(
delFromList
elem
t
)
in
match
set
with
Set
([])
->
set
|
Set
([])
->
set
|
Set
(
l
)
->
Set
(
delFromList
elem
l
)
(* Check if an element exists in a set *)
...
...
@@ -38,19 +36,19 @@ struct
(* Get the union of sets a and b as a new set *)
let
union
a
b
=
match
a
with
Set
([])
->
b
|
Set
([])
->
b
|
Set
(
la
)
->
match
b
with
Set
([])
->
a
|
Set
([])
->
a
|
Set
(
lb
)
->
Set
(
la
@
List
.
filter
(
fun
e
->
not
(
List
.
mem
e
la
))
lb
)
(* Get the intersection of sets a and b as a new set *)
let
intersection
a
b
=
match
a
with
Set
([])
->
a
|
Set
([])
->
a
|
Set
(
la
)
->
match
b
with
Set
([])
->
b
|
Set
(
lb
)
->
|
Set
([])
->
b
|
Set
(
lb
)
->
let
b_in_a
=
List
.
filter
(
fun
e
->
List
.
mem
e
la
)
lb
in
Set
(
List
.
filter
(
fun
e
->
List
.
mem
e
lb
)
b_in_a
)
end
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