Answered step by step
Verified Expert Solution
Question
1 Approved Answer
need help with this do questions F# Programming: Type Inference Q1. For each of the following definitions, say whether it is a simple value or
need help with this
do questions
F# Programming: Type Inference Q1. For each of the following definitions, say whether it is a simple value or a function, and if a function, what is the function signature? If in doubt, run them in the F# Interactive Tool to find out! 1, let testA = 2 2. let testB x = 2 + x 3. let testC x 2.0x 4. let testD "hello" 5. let testE printfn "hello" 6. let testF 0 42 7. let testG 0 printfn "hello" 8. let testH x String.length x 9. let testi x-sprintf "%i" x 10. let test x-printfn "96i" x 11. let testk x = printfn "X s %f" x x // return x 12. let testL (f:int-> string) x = f x 13. let testM f (x:int) :string fx 14. let testN x :string x1 I/hint: what does :string modify? 15. let testO x 1 16. let testP x = x 1 17. let testQ x y-x 18. let testRx y z z 19, let tests x = x=x 20. let testT f (f 1) 2 21. let testu f = sprintf "%i" (f 1 ) 22. let testV f = fo + 2 23. let testw x-fun y>y*x 24. let testX x y y*x 25, let testY = fun x v-> v * x /I hint: what kind of thing is x? 26. let testZ fx - (f 1) + x 27. let testZzzfgx- g (fx) // apply fto x, then apply g to the result Q2. For each of the following signatures, create a function that will be inferred to have that signature. Avoid using explicit type annotations! 1. val sigA-int->int 2. val sigB-int -> unit 3. val sigC-int -> string 4. val sigDunit ->string 5. val sigE- string -> string 6. val sigF- int->bool->float -> string 7. val sigG-x:int -> y:int-> int // 2 different implementation styles, please 8. val sigH-xint -> (int -> int) // Hint: define a nested function 9. val sigl f:(int-int) >int 10. val sigl-x:int -> y:int-> z:int -> int 11. val sigk-f:(int>int)->(int-> int) 12. val sigL-xint ->f:(int->int) ->int 13. val sigM- f:(int -> int -> int) -> int 14. Val sigN-f:('a-> int)-> x"-> string // Hint: use sprintf 15. val sigo xint->(a-> int) Q3. Below are four generic signatures. Try to create four functions that are inferred to have these signatures 1. val sigW = 'a-> int 2. val sigX- int -> 'a 3. val sigY- a -> 'a F# Programming: Type Inference Q1. For each of the following definitions, say whether it is a simple value or a function, and if a function, what is the function signature? If in doubt, run them in the F# Interactive Tool to find out! 1, let testA = 2 2. let testB x = 2 + x 3. let testC x 2.0x 4. let testD "hello" 5. let testE printfn "hello" 6. let testF 0 42 7. let testG 0 printfn "hello" 8. let testH x String.length x 9. let testi x-sprintf "%i" x 10. let test x-printfn "96i" x 11. let testk x = printfn "X s %f" x x // return x 12. let testL (f:int-> string) x = f x 13. let testM f (x:int) :string fx 14. let testN x :string x1 I/hint: what does :string modify? 15. let testO x 1 16. let testP x = x 1 17. let testQ x y-x 18. let testRx y z z 19, let tests x = x=x 20. let testT f (f 1) 2 21. let testu f = sprintf "%i" (f 1 ) 22. let testV f = fo + 2 23. let testw x-fun y>y*x 24. let testX x y y*x 25, let testY = fun x v-> v * x /I hint: what kind of thing is x? 26. let testZ fx - (f 1) + x 27. let testZzzfgx- g (fx) // apply fto x, then apply g to the result Q2. For each of the following signatures, create a function that will be inferred to have that signature. Avoid using explicit type annotations! 1. val sigA-int->int 2. val sigB-int -> unit 3. val sigC-int -> string 4. val sigDunit ->string 5. val sigE- string -> string 6. val sigF- int->bool->float -> string 7. val sigG-x:int -> y:int-> int // 2 different implementation styles, please 8. val sigH-xint -> (int -> int) // Hint: define a nested function 9. val sigl f:(int-int) >int 10. val sigl-x:int -> y:int-> z:int -> int 11. val sigk-f:(int>int)->(int-> int) 12. val sigL-xint ->f:(int->int) ->int 13. val sigM- f:(int -> int -> int) -> int 14. Val sigN-f:('a-> int)-> x"-> string // Hint: use sprintf 15. val sigo xint->(a-> int) Q3. Below are four generic signatures. Try to create four functions that are inferred to have these signatures 1. val sigW = 'a-> int 2. val sigX- int -> 'a 3. val sigY- a -> 'a Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started