WorksheetsAFP Midtvejsevaluering
Total questions: 10
Worksheet time: 5mins
Result of:
[-2;3;5] |> List.map (fun x -> x*2)
val it : int list = [-4; 6; 10]
val it : float list = [-4.0; 6.0; 10.0]
error FS0001: The type 'float' does not match the type 'int'
val it: int list = []
F# is
General purpose language with roots in FP
Functional first language with strong types, support imperative, FP and OOP
Purely functional with strong types
General purpose language with support of OOP and FP
Which is the higher order function(s) in F#
'a -> int -> 'b -> float option list
'a -> 'b -> ('c -> int)
('a -> int) -> 'c
('a -> int) -> ('b -> 'c) -> ('d -> float)
F# is lazy evaluated
True
False
Some
None
Which is the polymorphic function(s) in F#
(int -> float) -> int option -> float option
int -> int list
('a -> 'b) -> 'a -> 'b
int -> 'a list
Type of:
[1;2;3;4] |> List.fold (fun a b -> a + string b) ""
val it : string list
val it : string
val it : int
val it : int list
Result of:
[1;2;3;4] |> List.fold (fun a b -> string (int a + b)) "0"
"0"
"10"
"11"
"1234"
Worst-case runtime of sets N and M:
Set.isSubset (set [1;2;3]) (set [2;3])
O(M*log(N))
O(N*M)
O(N+M)
O(N)
Result of:
Some "a" |> Option.fold (fun a b -> "b" + b + a) ""
"ba"
"b"
"bba"
"a"
Ouput of:
Seq.item 5 (Seq.cache (Seq.initInfinite (fun i -> printf "%i" i)))
"1\n2\n3\n4\n5"
"123456"
"1234"
"12345"
