Question: 2 . ( 2 0 points ) Here is an SML mergesort program: ` ` ` fun merge ( [ ] , ys ) =
points Here is an SML mergesort program:
fun merge ys ys
mergexs xs
mergex::xs y::ys
if x y then x::mergexs y::ys
else y::mergex::xs ys
fun split
split aa
split a::b::cs
let val MN split cs in
a::M b::N
end
fun mergesort
mergesort aa
mergesort ab if a b then ab else ba
mergesort L
let val MN split L
in
merge mergesort M mergesort N
end
Note that mergesort includes three base cases aa b and all are handled correctly.
Suppose we delete the third line of mergesort, so that a b is no longer handled as a base case. You can verify that this change makes no difference in the type of mergesort or in its behavior.
Now suppose we also delete the second line of mergesort, leaving
fun mergesort
mergesort L
let val MN split L
in
merge mergesort M mergesort N
end
What effect does this change have on the type that SML infers for mergesort?
Verify that whether updated mergesort works correctly by running on your system and explain your findings.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
