Is it possible to introduce additional type variables into a superclass-constraint?

前端 未结 1 896
借酒劲吻你
借酒劲吻你 2021-01-17 09:49

When dealing with type families, it is often handy to use equality constraints to avoid having to repeat some type-function\'s name in a signature:

class Foo         


        
相关标签:
1条回答
  • 2021-01-17 10:27

    It surprised me to learn you can't do that (I've used the same technique and know it works in instance declarations), but there seems to be a long-standing GHC feature request to support this.

    Maybe you can use ConstraintKinds to get the same benefit:

    {-# LANGUAGE TypeFamilies , FlexibleContexts , ConstraintKinds #-}
    import Data.Monoid
    
    class Foo f where
      type BulkyAssociatedType f :: *
    
    type B f = (Monoid (BulkyAssociatedType f))
    
    class ( Foo f, B f) => Bar f
    
    0 讨论(0)
提交回复
热议问题