-
Notifications
You must be signed in to change notification settings - Fork 2
/
hw2-template.ml
83 lines (64 loc) · 1.89 KB
/
hw2-template.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(* CS3250 Programming Languages F23: Homework 2 *)
(* Template, by ceskalka *)
(*
NOTE: you should complete all parts where it says COMPLETE ME. Curently most are these
are functions with dummy bodies that are not correct solutions.
*)
(* Problem 1 *)
type nat = Zero | Succ of nat
(*
sum : nat -> nat -> nat
in : nats n1 and n2
out : nat that denotes n1 + n2
*)
let rec sum n1 n2 =
match n1 with
Zero -> n2
| (Succ n) -> Succ(sum n n2)
(*
mult : nat -> nat -> nat
in : pair (x, y) where x denotes a number n1 and y denotes n2
out : z that denotes n1 * n2
*)
let rec mult n1 n2 = n2 (* COMPLETE ME *)
(* Problem 2 *)
(*
Please include your answer here. A few sentences will suffice, but say as much as you
like. COMPLETE ME
*)
(* Problem 3 *)
(*
member : 'a -> 'a list -> bool
in : Value v, list l
out : True iff v is in l
*)
let rec member v l = false (* COMPLETE ME *)
(* Problem 4 *)
(* measurement datatype *)
type emeasures = Meter of float | Liter of float | Centigrade of float
type ameasures = Feet of float | Gallon of float | Fahrenheit of float
(*
conversion : emeasures -> ameasures
in : english measurement x
out : conversion of x into corresponding american
measurement
*)
let conversion em = (Feet 0.0) (* COMPLETE ME *)
(* Problem 5 *)
(* tree datatype *)
type 'a tree = Leaf | Node of 'a tree * 'a * 'a tree
(*
lookup : ('a * 'a -> bool) -> 'a -> 'a tree -> bool
in : strict total order lt, element x, tree t possessing
BST property
out : true iff there exists y in t with eq(x,y)
*)
let rec lookup lt x t = false (* COMPLETE ME *)
(*
insert : ('a * 'a -> bool) -> 'a -> 'a tree -> 'a tree
in : strict total order lt, element x, tree t possessing
BST property
out : tree t' which is t with x inserted such that t'
possesses BST property
*)
let rec insert lt x t = Leaf (* COMPLETE ME *)