[GHC] #10318: Cycles in class declaration (via superclasses) sometimes make sense.

GHC ghc-devs at haskell.org
Tue Apr 28 13:02:56 UTC 2015


#10318: Cycles in class declaration (via superclasses) sometimes make sense.
-------------------------------------+-------------------------------------
        Reporter:  ekmett            |                   Owner:
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Compiler (Type    |                 Version:  7.10.1
  checker)                           |                Keywords:
      Resolution:                    |            Architecture:
Operating System:  Unknown/Multiple  |  Unknown/Multiple
 Type of failure:  GHC rejects       |               Test Case:
  valid program                      |                Blocking:
      Blocked By:                    |  Differential Revisions:
 Related Tickets:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Hmm.  In all the examples you give, one can statically enumerate the
 transitive superclasses.
 Fro example in comment:5 we have
 {{{
 Ring r
 ==> Module r r
     ==> Group r
         ==> Module r Integer
             ==> Group r  -- STOP
                 Ring Integer
                 ==> Module Integer Integer
                     ==> Group Integer
                         ==> Module Integer  -- STOP
                         Ring Integer   -- STOP
         Ring r  -- STOP
 }}}
 Here I am writing
 {{{
 Class a b
 ==> Superclass1 a b
     Superclass2 a b
 }}}
 with nesting to describe nested superclasses.  `STOP` means that we've
 seen this before, so going on generating superclasses will reveal nothing
 new.

 Notice that I reach a fixpoint for every instantiation of `r`.  Indeed I
 can precompute all these transitive superclasses, once and for all, at the
 class declaration.

 Similarly for `IntegralDomain`, but I have to use the equalities:
 class (Frac (Frac a) ~ Frac a, Fractional (Frac a), IntegralDomain (Frac
 a))
   => IntegralDomain a where
 {{{
 ID a
 ==> Frac (Frac a) ~ Frac a                    -- (1)
     Fractional (Frac a)
     ==> superclasses of Fractional
     ID (Frac a)
     ==> Frac (Frac (Frac a)) ~ Frac (Frac a)  -- STOP; a consequence of
 (1)
         ID (Frac (Frac a)                     -- rewrite with (1)
         = ID (Frac a)   -- STOP
         Fractional (Frac (Frac a))            -- rewrite with (1)
         = Fractional (Frac a)      -- STOP
 }}}
 In the examples you care about, does the collection of superclasses always
 statically terminate in this way?

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


More information about the ghc-tickets mailing list