[GHC] #5927: A type-level "implies" constraint on Constraints

GHC ghc-devs at haskell.org
Sat Oct 15 07:30:41 UTC 2016


#5927: A type-level "implies" constraint on Constraints
-------------------------------------+-------------------------------------
        Reporter:  illissius         |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  7.4.1
  checker)                           |
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Iceland_jack):

 [https://www.reddit.com/r/haskell/comments/52f77p/how_would_you_express_the_free_category_in_haskell/d7k5x9r
 This] has one of the best examples

 {{{#!hs
 type f  ~> g = forall a.   f a   -> g a
 type f ~~> g = forall a b. f a b -> g a b

 newtype Free0 k p     = Free0 (forall q. k q => (p  -> q) -> q)
 newtype Free1 k p a   = Free1 (forall q. k q => (p  ~> q) -> q a)
 newtype Free2 k p a b = Free2 (forall q. k q => (p ~~> q) -> q a b)

 class Semigroup m
 class Semigroup m => Monoid m

 class                   Semigroupoid c
 class Semigroupoid c => Category c
 class Category     c => Arrow    c
 }}}

 you can define

 {{{#!hs
 instance p `Implies` Semigroup => Semigroup (Free0 p a)
 instance p `Implies` Monoid    => Monoid    (Free0 p a)

 instance p `Implies` Semigroupoid => Semigroupoid (Free2 p a)
 instance p `Implies` Category     => Category     (Free2 p a)
 instance p `Implies` Arrow        => Arrow        (Free2 p a)
 instance p `Implies` ArrowLoop    => ArrowLoop    (Free2 p a) -- (?)
 }}}

 instead of

 {{{#!hs
 instance Semigroup (Free0 Semigroup a)
 instance Semigroup (Free0 Monoid    a)
 instance Monoid    (Free0 Monoid    a)

 instance Semigroupoid (Free2 Semigroupoid p)
 instance Semigroupoid (Free2 Category     p)
 instance Semigroupoid (Free2 Arrow        p)
 instance Semigroupoid (Free2 ArrowLoop    p)
 instance Category     (Free2 Category     p)
 instance Category     (Free2 Arrow        p)
 instance Category     (Free2 ArrowLoop    p)
 instance Arrow        (Free2 Arrow        p)
 instance Arrow        (Free2 ArrowLoop    p)
 instance ArrowLoop    (Free2 ArrowLoop    p)
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/5927#comment:23>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list