7
我不明白,爲什麼下面的代碼不會編譯:類型變量「A0」是不明確的
{-# LANGUAGE GADTs, ScopedTypeVariables #-}
data A = A
class C a where
c :: a -> Bool
instance C A where
c _ = True
data D a where
D :: C a => D a
toBool :: D a -> Bool
toBool D = c (undefined::a)
以下是錯誤消息:
Could not deduce (C a0) arising from a use of ‘c’
from the context (C a)
bound by a pattern with constructor
D :: forall a. C a => D a,
in an equation for ‘toBool’
at test.hs:15:8
The type variable ‘a0’ is ambiguous
Note: there is a potential instance available:
instance C A -- Defined at test.hs:8:10
In the expression: c (undefined :: a)
In an equation for ‘toBool’: toBool D = c (undefined :: a)
有人能解釋這是怎麼回事上 ?
'ScopedTypeVariables'要求你明確地寫出哪些類型的簽名應該被寫出來:'toBool :: forall a。 D a - > Bool'。 – user2407038 2014-09-20 05:00:17