[GHC] #5462: Deriving clause for arbitrary classes

GHC ghc-devs at haskell.org
Fri Sep 26 12:50:35 UTC 2014


#5462: Deriving clause for arbitrary classes
-------------------------------------+-------------------------------------
              Reporter:  simonpj     |            Owner:  dreixel
                  Type:  feature     |           Status:  new
  request                            |        Milestone:  ⊥
              Priority:  normal      |          Version:  7.2.1
             Component:  Compiler    |         Keywords:  Generics
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Unknown
  Unknown/Multiple                   |       Blocked By:
       Type of failure:              |  Related Tickets:  #7346
  None/Unknown                       |
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by dreixel):

 Replying to [comment:29 rwbarton]:
 > Can't we determine the context for the derived instance from the
 contexts of the default method type signatures?

 Not really. Look at the [http://www.haskell.org/haskellwiki/GHC.Generics
 serialisation example from the wiki page]:

 {{{
 putDefault :: (Generic a, GSerialize (Rep a)) => a -> [Bit]
 }}}

 Nothing here tells us that we need `Serialize` constraints on the datatype
 parameters.

 More info comes from the K1 instance, though:

 {{{
 instance (Serialize a) => GSerialize (K1 i a) where
   gput (K1 x) = put x
 }}}

 Here we see that the constructor arguments will require a `Serialize`
 instance. So if parameter `a` appears as argument to a constructor, we
 should introduce the constraint `Serialize a`. But this is non-trivial in
 general... the constraint might be part in an instance of the form `K1 i a
 :*: g`, for example.

 I think going for Andres's proposal is still the best idea, as it is
 simple and relates to something people already know.

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


More information about the ghc-tickets mailing list