相关疑难解决方法(0)

在所有类型族实例上键入约束

我想如果没有模板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 …

haskell types type-families

9
推荐指数
1
解决办法
1181
查看次数

标签 统计

haskell ×1

type-families ×1

types ×1