[GHC] #10868: Make GHC generics capable of handling unboxed types

GHC ghc-devs at haskell.org
Fri Sep 11 19:04:56 UTC 2015


#10868: Make GHC generics capable of handling unboxed types
-------------------------------------+-------------------------------------
              Reporter:              |             Owner:  RyanGlScott
  RyanGlScott                        |
                  Type:  feature     |            Status:  new
  request                            |
              Priority:  normal      |         Milestone:
             Component:  Compiler    |           Version:  7.10.2
              Keywords:              |  Operating System:  Unknown/Multiple
          Architecture:              |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
             Test Case:              |        Blocked By:
              Blocking:              |   Related Tickets:  #8468
Differential Revisions:              |
-------------------------------------+-------------------------------------
 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
 [https://mail.haskell.org/pipermail/ghc-devs/2015-September/009895.html
 previously], Andres suggested adding new generic representation types to
 mark where `Int#`, `Char#`, etc. are used (suggesting the name `UInt` to
 represent `Int#`).

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


More information about the ghc-tickets mailing list