小编Dav*_*amf的帖子

Haskell初学者

我不明白为什么我从GHCi得到以下回复.不是Maybe构造函数吗?

Prelude> :t Maybe

<interactive>:1:1: Not in scope: data constructor `Maybe'
Prelude> let e = Maybe 5

<interactive>:1:9: Not in scope: data constructor `Maybe'
Run Code Online (Sandbox Code Playgroud)

haskell maybe

11
推荐指数
2
解决办法
4253
查看次数

如何解决此类错误?

我无法将以下程序加载到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) 
Run Code Online (Sandbox Code Playgroud)

当我编译它时,我收到以下错误消息:

   Couldn't match type `a' with `[a]'
  `a' is a rigid type variable bound by
      the type signature for bubList :: Ord a => [a] -> …
Run Code Online (Sandbox Code Playgroud)

haskell

1
推荐指数
1
解决办法
125
查看次数

另一种类型错误

为什么不编译?

append :: [a] -> [a] -> [a]
append xs ys = foldr (:) ys xs

traverse :: a -> [[a]] -> [[a]]
traverse x [[]] = [[x]]
traverse x [(y:ys)] = append [(x:y:ys)] (map (y:) (traverse x [ys]))

comb :: [a] -> [[a]]
comb [] = [[]]
comb (x:[]) = [[x]]
comb (x:y:[]) = [[x,y],[y,x]] 
comb (x:xs) = map (traverse x) (comb xs)
Run Code Online (Sandbox Code Playgroud)

它失败并出现此错误:

 Couldn't match type `a' with `[a]'
  `a' is a rigid type variable bound by
      the …
Run Code Online (Sandbox Code Playgroud)

haskell

-1
推荐指数
2
解决办法
172
查看次数

标签 统计

haskell ×3

maybe ×1