-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter_03_ex_4.fs
More file actions
37 lines (29 loc) · 693 Bytes
/
Chapter_03_ex_4.fs
File metadata and controls
37 lines (29 loc) · 693 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
module Chapter_03_ex_4
// 3.4 1.
// A record type for a straight line:
type StraightLineRec = {
a: float
b: float
}
// we can also use a tuple
type StraightLine = float*float
// 3.4 2.
let mirrorX line =
let a, b = line
(-a, -b)
let mirrorXRec (line: StraightLineRec) =
let a, b = line.a, line.b
{ a= -a; b= -b}
let mirrorY line =
let a, b = line
(-a, b)
let mirrorYRec (line: StraightLineRec) =
let a, b = line.a, line.b
{ a= -a; b=b}
// 3.4 3.
let formatStraightLine line =
let a, b = line
sprintf "y = %fx + %f" a b
let formatStraightLineRec (line: StraightLineRec) =
let a, b = line.a, line.b
sprintf "y = %fx + %f" a b