Question
(Cs 346 )
(ML programing )
Q2 Convert the following C function into ML #include int add3 (int x) return x +3 nt do fun (int (fp)(int x). int y) return (fo(y)+y+1 void main (void) printf("%din-,do-fun(add 3.5)); 03 Write a function Fib that takes and integer n and returns a list of the first n Fibonacci numbers but sorted in descending order from high to low 04 Write a curried function replace that takes two integer arguments and a list of integers. The function returns a list of integers in which it replaces all occurrences of the second argument by the first argument. For example Replace 5 3 [1,3,5,2,3,4,6,71 val it [1,5,5,2,5,4,6,7]: int list Q5 Order of Operations: Eager Evaluate operand, substitute value for formal parameter, and evaluate expression. ·Lazy I substitute operand for formal parameter, evaluate expression, evaluate parameter only when value is needed Write a function of your choice to show if ML has Eager or Lazy evaluation.
Explanation / Answer
Answer to Question 2 :-
fun add3 x = //in ML language
x+3
fun do_fun (-fp)x,y = //in ML language
(-fp)y+y+1;