-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment1.fs
More file actions
66 lines (48 loc) · 1.6 KB
/
Assignment1.fs
File metadata and controls
66 lines (48 loc) · 1.6 KB
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
module Assignment1
let sqr x = x * x
let pow x n= System.Math.Pow(x,n)
let rec fib =
function
| 0 -> 0
| 1 -> 1
| n -> fib (n-1) + fib (n-2)
let rec sum =
function
| 0 -> 0
| n -> n + sum (n - 1)
let dup (s :string) = s + s
let rec dupn (s: string) =
function
| 0 -> ""
| n -> s + dupn s (n-1)
let rec readInt() =
let readFromConsole = System.Console.ReadLine().Trim()
let tryParseInt (str: string) = System.Int32.TryParse str
let input = tryParseInt readFromConsole
match input with
| (true, result) -> result
| (false, result) ->
printfn "%d is not an integer" result
readInt()
let timediff (hh1, mm1) (hh2, mm2) =
60*(hh2-hh1) + (mm2-mm1)
let minutes (hh,mm) =
timediff (00,00) (hh,mm)
let rec bin (n, k) =
match (n, k) with
| (n, 0) -> 1
| (n, k) when n = k -> 1
| (n, k) -> bin (n - 1, k-1) + bin (n-1, k)
(*let curry _ = failwith "not implemented"
let uncurry _ = failwith "not implemented"
*)
let curry f a b = f(a, b)
let uncurry f (a,b) = f a b
(*
Definition of curry:
When a function takes multiple variables, currying then creates a
sequence of functions which only takes one argument
Definition of uncurry:
Uncurry is the opposite of curry meaning it takes a sequence of single-argument
functions and turns it into a single function which takes all arguments at once
*)