F# Tutorial Exercises and Assignment : Compilation of Exercises *** "I" exercises are due next class, "C" exercises are due in one week. *** EXERCISE I1: define the combinators K = lambda x.lambda y.x, and S = lambda x.lambda y.lambda z. x z (y z). The notation for lambda x.E is fun x -> E. ***EXERCISE I2: figure out how to apply printfn to 1 and g(2,4) correctly. And in general, the proper way to apply curried functions. The hint is in the error message. *** EXERCISE I3: fix > let f y = while y>0 do printfn "%d" y y <- y-1;; *** EXERCISE I4: devise an experiment to verify that F# uses static as opposed to dynamic scoping. *** EXERCISE I4.5 (somewhat harder): Using what you learned above, recreate the "makeaccumulator" program from scheme/perl: write a function that returns a closure lambda and show that it carries its own state: I should be able to do: let a1 = makeaccumulator 0; let a2 = makeaccumulator 0; a1 2;; // returns 2 a1 2;; // returns 4 a2 2;; // returns 2 *** EXERCISE I5. Devise an experiment to test if, when an array is passed to a function as an argument, whether a reference (pointer) is passed, or is the entire array is copied. ***EXERCISE C1 (type up in editor and compile). Modify the tostring function so that expressions such as 3 + -4 is printed as (3 - 4). However, (3 + --4) should be printed as (3 + 4) and not (3 - -4). Make sure your function is recursive so you can handle nested cases. ***EXERCISE C2 : Write a function to return the length (size) of a stack (as defined in program). ***EXERCISE C3: Write a function convert an F# list into a stack, without reversing the elements. You should type up all exercises in one file and submit the assignment.