0

我在 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 
4

1 回答 1

3

你的问题出在div length l 2零件上。在这里,您给出了div3 个参数:lengthl2。相反,您应该编写div (length l) 2.

于 2013-08-11T14:15:45.663 回答