我不明白为什么下面的代码不会编译:
{-# 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)
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
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 …Run Code Online (Sandbox Code Playgroud) haskell ×1