Reference no: EM132257862
Programming Languages Assignment - four small F# functions
Overview - In this assignment, you're going to write 4 small functions, using both tail recursion and higher-order approaches. The exercise is setup on Codio, but you can work in whatever environment you prefer. Regardless of where you work, be sure to submit the 4 functions separately as described in the next section.
Exercises -
Exercise 1: subset S L
Login to Codio and edit the file "hw0901.fs". Read the comments:
NOTE: you can solve using tail-recursion, or using higher-order approach. Whatever you prefer. Beware that List.length is an O(N) operation, it actually traverses the list and counts the elements.
HINT: there are a variety of solutions. One idea is write a helper function "contains e L" that returns true if e is an element of L, and false if not. Then build on that to define subset. This leads to an O(N^2) solution, which is fine.
Write the required function, using whatever approach you prefer. To test your work, open a terminal window and load the file into F# interactive.
Exercise 2: delete e L in a tail-recursive manner
Edit the file "hw0902.fs". Read the comments, and write the necessary function in a tail-recursive manner. Test using F# interactive.
NOTE: write a tail-recursive version using a helper function; do not change the API of the original delete function. You'll also need to build the new list efficiently; you can use List.rev if need be.
Exercise 3: delete e L using a higher-order approach
Edit the file "hw0903.fs". Read the comments, and write the necessary function using a higher-order approach. Test using F# interactive.
Exercise 4: mergesort L
Edit the file "hw0904.fs". Read the comments, and rewrite the merge function to work in a safe, efficient manner (i.e. tail-recursive, and building the new list efficiently). Test using F# interactive.
Attachment:- Assignment Files.rar