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

#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

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: ekmett Type: feature request | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by ekmett): This'll be incredibly tedious, but it is the right thing to do. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: ekmett Type: feature request | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by dreixel): I'm actually not too sure that this is the right thing to do. In fact, I've wondered if we shouldn't *remove* all the instances for base types altogether. They don't really add much, do they? Generic functions typically require ad-hoc instances for base types, so it doesn't help to have these instances. Perhaps the only reason is the meta-data... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

In fact, I've wondered if we shouldn't *remove* all the instances for
#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: ekmett Type: feature request | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by ekmett): base types altogether. Actually from talking to Eric Mertens on the topic I now agree. The goal with generics is usually to get down to "leaves" that you know how to handle. This actively gets in the way of handling certain kinds of leaves. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: ekmett Type: feature request | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by andreas.abel): All I know is that when I tried to generate the Binary instances for my data types, I got the complaint about missing Generic instances for Int32 and Word64. I might have asked for too superclasses somewhere. At least Binary does not need Generic Int32 or Generic Word64. It is too late today to try to reconstruct my problem... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: ekmett Type: feature request | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by rwbarton): * cc: vagarenko (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 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: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: ekmett (added) Comment:
All I know is that when I tried to generate the Binary instances for my data types, I got the complaint about missing Generic instances for Int32 and Word64.
Really? I'm not sure why this would be the case, since in all of the examples I've seen, `Generic` instances don't require that a datatype's arguments also be `Generic`. For example, if you have this: {{{#!hs {-# LANGUAGE DeriveAnyClass, DeriveGeneric #-} data T = T Int32 Word64 deriving (Binary, Generic) }}} Then the generic machinery in `binary` only requires that `Int32` and `Word64` be `Binary` instances. Might I ask what your use case is? It seems ''very'' unlikely that we're going to be adding `Generic` instances for base types like these going forwards. In fact, we're going to [http://git.haskell.org/ghc.git/blobdiff/d4bcd05d7df3138429abdf43d3e3eb8f6da2... remove] the `Generic` instances for `Char`, `Double`, `Float`, and `Int` in GHC 8.0 for the reasons that Pedro and Ed described. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: | Keywords: Generics Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: => Generics -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: wontfix | Keywords: Generics Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => closed * resolution: => wontfix Comment: I'm going to close this, since we have already moved in the direction of not providing `Generic` instances for primitive types with [changeset:"700c42b5e0ffd27884e6bdfa9a940e55449cff6f/ghc" 700c42b5/ghc]. Please re-open if you feel strongly otherwise. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: wontfix | Keywords: Generics 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 nh2): Note: In https://ghc.haskell.org/trac/ghc/ticket/9526#comment:13 RyanGlScott provided an explanation of why this change is no longer necessary. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: wontfix | Keywords: Generics Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9526 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #9526 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10512: Generic instances missing for Int32, Word64 etc. -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Core Libraries | Version: 7.10.1 Resolution: wontfix | Keywords: Generics Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9526 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): Seems to break example from [https://hackage.haskell.org/package/Chart-1.1/docs/Generics-Deriving- Lens.html Generics.Deriving.Lens] {{{ ghci> allOf tinplate (=="Hello") (1::Int,2::Double,(),"Hello",["Hello"]) <interactive>:85:7: error: • No instance for (GHC.Generics.Generic Char) arising from a use of ‘tinplate’ • In the first argument of ‘allOf’, namely ‘tinplate’ In the expression: allOf tinplate (== "Hello") (1 :: Int, 2 :: Double, (), "Hello", ["Hello"]) In an equation for ‘it’: it = allOf tinplate (== "Hello") (1 :: Int, 2 :: Double, (), "Hello", ["Hello"]) }}} {{{ ghci> mapMOf_ tinplate putStrLn ("hello",[(2 :: Int, "world!")]) <interactive>:86:9: error: • No instance for (GHC.Generics.Generic Char) arising from a use of ‘tinplate’ • In the first argument of ‘mapMOf_’, namely ‘tinplate’ In the expression: mapMOf_ tinplate putStrLn ("hello", [(2 :: Int, "world!")]) In an equation for ‘it’: it = mapMOf_ tinplate putStrLn ("hello", [(2 :: Int, "world!")]) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10512#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC