我正在学习关于家庭的类型,但它太令人困惑了。当我在类定义之外定义多态类型时,它运行良好。
{-# LANGUAGE Rank2Types #-}
type T = Num a => a
但是当在类定义中定义多态类型时,
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE Rank2Types #-}
data D = D
class A a where
type T a :: *
instance A D where
type T D = Num a => a
然后编译器显示错误:
Illegal polymorphic or qualified type: forall a. Num a => a
In the type instance declaration for 'T'
In the instance declaration for 'A D'
有没有办法在返回类型为多态的类中创建函数,如3(Num a => a)?