Skip to content

Generic instances missing for Int32, Word64 etc.

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

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.

Trac metadata
Trac field Value
Version 7.10.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Core Libraries
Test case
Differential revisions
BlockedBy
Related
Blocking
CC core-libraries-committee@haskell.org
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information