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