1
data Maybe' a = Nothing' | Just' a deriving (Show)
class From' t
where from' :: t a -> a
instance From' Maybe'
where from' (Just' x) = x
This works。功能和類別之間的類型簽名
但是......
from2 :: t a -> a
from2 (Just' x) = x
Couldn't match type `t' with `Maybe''
`t' is a rigid type variable bound by
the type signature for from2 :: t a -> a at test.hs:11:1
In the pattern: Just' x
In an equation for `from2': from2 (Just' x) = x
我不知道爲什麼它不工作。
這只是一個例子。謝謝! ehird。你是個好人。 – user1286894 2012-03-22 20:38:39
沒問題:)如果我的回答對你有幫助,你應該點擊旁邊的複選標記,以便問題被標記爲已解決。 – ehird 2012-03-22 20:40:41
@ehird:他使用的類型是「Maybe」,而不是「Maybe」。你應該更正你的答案,添加缺少的''':) – 2012-03-22 22:13:10