我想如果没有模板Haskell,我想要的是不可能的,但无论如何我都会问.
我有一个类似Data.Set和类型的接口Data.IntSet:
type family Elem s :: *
class SetLike s where
insert :: Elem s -> s -> s
member :: Elem s -> s -> Bool
...
type instance Elem (Set a) = a
instance Ord a => SetLike (Set a) where
...
Run Code Online (Sandbox Code Playgroud)
我有一个类型系列,它选择最佳集合实现:
type family EfficientSet elem :: *
type instance EfficientSet Int = IntSet
type instance EfficientSet String = Set String -- or another implementation
Run Code Online (Sandbox Code Playgroud)
有没有办法保证EfficientSet实例永远都是SetLike这样Elem (EfficientSet …