-
Notifications
You must be signed in to change notification settings - Fork 1
/
rec.fs
50 lines (40 loc) · 1.1 KB
/
rec.fs
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
module MyRec
type Book =
{ Name: string;
AuthorName: string;
Rating: int option;
ISBN: string }
type VHS =
{ Name: string;
AuthorName: string;
Rating: string; // Videos use a different rating system.
ISBN: string }
let bananaBook =
{ Name = "Banana book";
AuthorName = "Bla";
Book.Rating = None;
ISBN = "1234343" }
let pearBook =
{ bananaBook with Book.Rating = Some 3 }
let print (book: Book) =
match book.Rating with
| Some rating ->
printfn "I give %s %A stars out of 5" book.Name rating
| None -> printfn "I give %s no rating" book.Name
type MushroomColor =
| Red
| Green
| Blue
type PowerUp =
| FireFlower
| MushRoom of MushroomColor
| Star of int
let handlePowerUp powerUp =
match powerUp with
| FireFlower -> printfn "FireFlower"
| MushRoom color -> match color with
| Red -> printfn "Red"
| Green -> printfn "Green"
| Blue -> printfn "Blue"
| Star duration -> printfn "duration %d" duration
MushRoom Green |> handlePowerUp