Make GHC generics capable of handling unboxed types
Currently, GHC generics will not accept any unboxed constructor arguments:
$ ghci
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
λ> :set -XMagicHash -XDeriveGeneric
λ> :m + GHC.Generics GHC.Exts
λ> data IntHash = IntHash Int# deriving Generic
<interactive>:4:38:
Can't make a derived instance of ‘Generic IntHash’:
IntHash must not have unlifted or polymorphic arguments
In the data declaration for ‘IntHash’
This makes GHC generics strictly less powerful than deriving
clauses in some scenarios, as typeclasses like Eq
, Ord
, and Show
are capable of special-casing certain unboxed types:
λ> :set -ddump-deriv
λ> data IntHash = IntHash Int# deriving Show
==================== Derived instances ====================
Derived instances:
instance GHC.Show.Show Ghci1.IntHash where
GHC.Show.showsPrec a_a1OJ (Ghci1.IntHash b1_a1OK)
= GHC.Show.showParen
((a_a1OJ GHC.Classes.>= 11))
((GHC.Base..)
(GHC.Show.showString "IntHash ")
(GHC.Show.showsPrec 11 (GHC.Types.I# b1_a1OK)))
GHC.Show.showList = GHC.Show.showList__ (GHC.Show.showsPrec 0)
As discussed on the GHC devs mailing list previously, Andres suggested adding new generic representation types to mark where Int#
, Char#
, etc. are used (suggesting the name UInt
to represent Int#
).
Trac metadata
Trac field | Value |
---|---|
Version | 7.10.2 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | dreixel, kosmikus |
Operating system | |
Architecture |