玩弄 GHC.TypeLits 我做了这段代码
data A (a :: Symbol) = A
type B a (b :: Symbol) (c :: Symbol) = A a
class AC a where
af :: (String, a)
-- instance SingI a => AC (A a) where
-- af = (fromSing (sing :: Sing a), A)
instance (SingI a, SingI b, SingI c) => AC (B a b c) where
af = (fromSing (sing :: Sing c), A)
如果我尝试在某个地方调用 af 并出现此错误,则无法编译:
No instance for (SingI Symbol c) arising from a use of `af'
Possible fix: add an instance declaration for (SingI Symbol c)
In the second argument of `($)', namely
`(af :: (String, B "a" "b" "c"))'
In the second argument of `($)', namely
`fst $ (af :: (String, B "a" "b" "c"))'
In a stmt of a 'do' block:
print $ fst $ (af :: (String, B "a" "b" "c"))
它仍然可以正常工作,instance SingI a => AC (A a)
因为很明显它是类型同义词,但我找不到任何解释。很高兴听到它为什么会这样工作,并且有没有机会添加一些标签之王来键入同义词?
扩展,用于编译:
DataKinds,
KindSignatures,
TypeSynonymInstances,
ScopedTypeVariables,
-- MultiParamTypeClasses,
UndecidableInstances