我在 Haskell 中编写合并排序,它给出了一个奇怪的错误:
Couldn't match expected type '[a0] -> Int' with actual type '[Int]'
代码是:
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