
#13592: Newtype type class with compiler generated instances -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.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: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): '''Even''' if we remove `type O` from the class the compiler only needs to generate the `type instance`s for `O` {{{#!hs type family O n class (Coercible (O n) n, Coercible n (O n)) => Newtype n where pack :: O n -> n pack = coerce unpack :: n -> O n unpack = coerce instance (Coercible (O n) n, Coercible n (O n)) => Newtype n }}} if you want to make `Sum` into a newtype, all the compiler has to do is generate {{{#!hs type instance O (Sum a) = a }}} pretty nifty! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13592#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler