Question

I have this code provided by my instructor. I am supposed to fix it by finding what type f# infers from mergesort. When I try to send to interactive i get an error . I asked my proffesor what was wrong and he said that it was due to formatting errors on the class website. I have tried adding spaces removing spaces you name it but every time i get a

~vs4489.fsx(8,14): error FS0588: Block following this 'let' is unfinished. Expect an expression.

on the last two methods. How can I fix this?

Here is the code

 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)
Was it helpful?

Solution

I can only guess as to what the correct indentation is, but …

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top