Compilation error in Merge Sort in Haskell
I was writing Merge Sort in Haskell and it is giving a strange error:
Couldn't match expected type '[a0] -> Int' with actual type '[Int]'
Code is:
f :: [Int] -> [Int]
f l
|length l == 1 = l
|length l == 2 = if head l > last l then reverse l else l
|otherwise = myappend ( take ( div length l 2 ) l ) ( drop ( div
length l 2 ) l )
myappend :: [Int] -> [Int] -> [Int]
myappend l [] = l
myappend [] l = l
myappend ( x : xs ) (y : ys) = if x > y then y : x : myappend xs ys else x
: y : myappend ys xs
No comments:
Post a Comment