Type constraints on all type family instances

后端 未结 3 983
-上瘾入骨i
-上瘾入骨i 2021-01-02 08:36

I suppose what I want is impossible without Template Haskell but I\'ll ask anyway.

I have an interface for types like Data.Set and Data.IntSet

3条回答
  •  情话喂你
    2021-01-02 09:41

    You can write this:

    class (SetLike (EfficientSet a), Elem (EfficientSet a) ~ a) =>
          HasEfficientSet a where
        type EfficientSet a
    

    If you associate the Elem type family with the SetLike class, you probably wouldn't even need the SetLike superclass constraint:

    class SetLike s where
        type Elem s
        insert :: Elem s -> s -> s
        member :: Elem s -> s -> Bool
    
    class Elem (EfficientSet a) ~ a => HasEfficientSet a where
        type EfficientSet a
    

提交回复
热议问题