-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathconditionals.ml
More file actions
50 lines (31 loc) · 800 Bytes
/
conditionals.ml
File metadata and controls
50 lines (31 loc) · 800 Bytes
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
(* Conditionals *)
let print_grade score =
if score >= 90 then
print_string "You got an A\n"
else if score >= 80 then
print_string "You got an B\n"
else if score >= 70 then
print_string "You got an C\n"
else
print_string "Let's all practice OCaml\n";;
print_grade 100;;
let is_the_answer y =
let answer = 42 in
y = answer;; (* how do you grok this? *)
is_the_answer 17;;
is_the_answer 42;;
(* Comparing other types *)
let eq (x,y) = x = y;; (* = is polymorphic, too *)
eq(3, 3);;
let x = "hi";;
let y = x;;
eq(x,y);;
eq("hi", "hi");;
(* == *)
let eqeq(x,y) = x == y;;
(* What is an _experiment_ we could run to figure out = vs. == ? *)
eqeq(3, 3);;
let x = "hi";;
let y = x;;
eqeq(x, y);;
eqeq("hi", "hi");;