2

I have an F# function mergesort as well as 2 other helper functions split and merge. When i try to run it, it gives me an error:

error FS0030: Value restriction. The value 'it' has been inferred to have generic type

When i look at the type for mergesort, it gives me:

_arg1:'a list -> 'b list when 'b : comparison

is the the reason for the error the fact that I'm passing an 'a List and getting a 'b List back? how can I fix this?

Here is the code:

let rec merge = function
| ([], l2) -> l2
| (l1, []) -> l1
| (x::l1, y::l2) -> if x < y then x :: merge (l1, y::l2)
                        else y :: merge (x::l1, l2)
let rec split = function
| [] -> ([], [])
| [a] -> ([a], [])
| a::b::listTail -> let (M,N) = split listTail in (a::M, b::N)

let rec mergesort = function
| []  -> []
| L   -> let (M, N) = split L in merge (mergesort M, mergesort N)
ZodiacRumble
  • 23
  • 1
  • 5

0 Answers0