Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using F# language. Full and complete answers in order to get full credit please, thank you. 1)Here is an attempt to write mergesortin F#: let

Using F# language. Full and complete answers in order to get full credit please, thank you.

1)Here is an attempt to write mergesortin F#:

 let rec merge = function | ([], ys) -> ys | (xs, []) -> xs | (x::xs, y::ys) -> if x < y then x :: merge (xs, y::ys) else y :: merge (x::xs, ys) let rec split = function | [] -> ([], []) | [a] -> ([a], []) | a::b::cs -> let (M,N) = split cs (a::M, b::N) let rec mergesort = function | [] -> [] | L -> let (M, N) = split L merge (mergesort M, mergesort N) 

Analyze mergesort with respect to the Checklist for Programming with Recursion, again addressing all three Steps. (Assume that merge and split both work correctly, as indeed they do.)

Enter this program into F# and see what type F# infers for mergesort. Why is this type a clue that something is wrong with mergesort?

Based on your analysis, correct the bug in mergesort.

2)Recall that an F# function that takes two arguments can be coded in either uncurried form (in which case it takes a pair as its input) or curried form (in which case it takes the first argument and returns a function that takes the second argument). In fact it is easy to convert from one form to the other in F#. To this end, define an F# function curry f that converts an uncurried function to a curried function, and an F# function uncurry f that does the opposite conversion. For example,

 > (+);; val it : (int -> int -> int) =  > let plus = uncurry (+);; val plus : (int * int -> int) > plus (2,3);; val it : int = 5 > let cplus = curry plus;; val cplus : (int -> int -> int) > let plus3 = cplus 3;; val plus3 : (int -> int) > plus3 10;; val it : int = 13 

What are the types of curry and uncurry?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. Does the survey prompt discussions with your direct reports?

Answered: 1 week ago