[GHC] #10512: Generic instances missing for Int32, Word64 etc.

GHC ghc-devs at haskell.org
Fri Jun 12 08:38:51 UTC 2015


#10512: Generic instances missing for Int32, Word64 etc.
-------------------------------------+-------------------------------------
              Reporter:              |             Owner:  ekmett
  andreas.abel                       |            Status:  new
                  Type:  feature     |         Milestone:
  request                            |           Version:  7.10.1
              Priority:  normal      |  Operating System:  Unknown/Multiple
             Component:  Core        |   Type of failure:  None/Unknown
  Libraries                          |        Blocked By:
              Keywords:              |   Related Tickets:
          Architecture:              |
  Unknown/Multiple                   |
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------
 Some base types have Generic instances, like Integer, the machine-specific
 ones like Int32 have none.  But these would be most useful when using
 generic Binary serialization.

 I think it makes sense to add Generic instances for *all* primitive types
 in base.

 I can define the instance myself, see
 https://github.com/agda/agda/commit/1d3710189989aced61be79c8e52945651fc94c0e

 {{{#!hs
 import GHC.Generics (Generic(..))
 import qualified GHC.Generics as Gen

 data D_Int32
 data C_Int32

 instance Gen.Datatype D_Int32 where
   datatypeName _ = "Int32"
   moduleName   _ = "GHC.Int32"
   -- packageName  _ = "base"

 instance Gen.Constructor C_Int32 where
   conName _ = "" -- JPM: I'm not sure this is the right implementation...

 instance Generic Int32 where
   type Rep Int32 = Gen.D1 D_Int32 (Gen.C1 C_Int32 (Gen.S1 Gen.NoSelector
 (Gen.Rec0 Int32)))
   from x = Gen.M1 (Gen.M1 (Gen.M1 (Gen.K1 x)))
   to (Gen.M1 (Gen.M1 (Gen.M1 (Gen.K1 x)))) = x
 }}}
 However, as GHC.Generics is a moving target, and changes over the compiler
 versions, I'd rather not have to.

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


More information about the ghc-tickets mailing list