can someone help me answer the following #Fsharp multiple choice questions along
ID: 3880531 • Letter: C
Question
can someone help me answer the following #Fsharp multiple choice questions along with explanations for each question please.
7. How does F# interpret the type int * bool -> string list? Select one:
a. (int * (bool -> string)) list
b. ((int * bool) -> string) list
c. int * (bool -> (string list))
d. (int * bool) -> (string list)
8. Let F# function foo be defined as follows:
let rec foo = function
| (xs, []) -> xs | (xs, y::ys) -> foo (xs@[y], ys)
If foo is supposed to append its two list parameters, which of the following is true? Select one:
a. foo fails Step 1 of the Checklist for Programming with Recursion.
b. foo fails Step 2 of the Checklist for Programming with Recursion.
c. foo fails Step 3 of the Checklist for Programming with Recursion.
d. foo satisfies all three steps of the Checklist for Programming with Recursion.
11. Which of the following is the type that F# infers for (fun f -> f 17)? Select one:
a. ('a -> 'b) -> 'b
b. (int -> int) -> int
c. (int -> 'a) -> 'a
d. ('a -> 'a) -> 'a
12. Which of the following has type int -> int list? Select one:
a. (@) [5]
b. [fun x -> x+1]
c. fun x -> 5::x
d. fun x -> x::[5]
13. What type does F# infer for the expression (3, [], true) ? Select one:
a. int * 'a list * bool
b. int * 'a * bool
c. int * int list * bool
d. Type error.
Explanation / Answer
How does F# interpret the type int * bool -> string list? Select one:
Answer:
a. (int * (bool -> string)) list
Explantion:
Because here the first string is going to get validate and then it is taken by the int finally convert to list.
8.let rec foo = function
| (xs, []) -> xs | (xs, y::ys) -> foo (xs@[y], ys)
If foo is supposed to append its two list parameters, foo satisfies all three steps of the Checklist for Programming with Recursion.
Answer: D
11. F# infers for (fun f -> f 17)
Answer:
b. (int -> int) -> int
12. Which of the following has type int -> int list?
Answer:
c. fun x -> 5::x
13. F# infer for the expression (3, [], true)
Answer:D
d. Type error.
Have a great day.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.