Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 如何解决此类型错误?_Haskell - Fatal编程技术网

Haskell 如何解决此类型错误?

Haskell 如何解决此类型错误?,haskell,Haskell,我无法将以下程序加载到GHCi: minList :: Ord a => [a] -> a minList (x:[]) = x minList (x:y:xs) = minList( min x y : xs) bubList :: Ord a => [a] -> [a] bubList [] = [] bubList ( x:y:[] ) = min x y : max x y bubList ( x:y:xs ) = minList(x:y:xs) : b

我无法将以下程序加载到GHCi:

minList :: Ord a => [a] -> a   
minList (x:[]) = x
minList (x:y:xs) = minList( min x y : xs)

bubList :: Ord a => [a] -> [a]
bubList [] = []
bubList ( x:y:[] ) = min x y : max x y 
bubList ( x:y:xs ) = minList(x:y:xs) : bubList(xs) 
当我编译它时,会收到以下错误消息:

   Couldn't match type `a' with `[a]'
  `a' is a rigid type variable bound by
      the type signature for bubList :: Ord a => [a] -> [a]
      at ex1.hs:11:1
In the second argument of `max', namely `y'
In the second argument of `(:)', namely `max x y'
In the expression: min x y : max x y

max x y
将返回一个值(
a
),而不是一个列表(
[a]
)。您只能将cons(
)添加到列表中。您将需要编写以下内容:

(min x y : [max x y]) 

max x y
将返回一个值(
a
),而不是一个列表(
[a]
)。您只能将cons(
)添加到列表中。您将需要编写以下内容:

(min x y : [max x y]) 

它被编译了。非常感谢,大卫。@DavidKramf你应该把他的回答标记为答案:)编译好了。非常感谢,大卫。@DavidKramf你应该把他的回答标记为答案:)我希望你看到第三行的打字错误,
minLiist
我希望你看到第三行的打字错误,
minLiist