我不明白为什么我从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) 我无法将以下程序加载到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) 为什么不编译?
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)