
#8516: Add (->) representation and the Invariant class to GHC.Generics -------------------------------------+------------------------------------- Reporter: nfrisby | Owner: Type: feature request | Status: new Priority: low | Milestone: Component: Compiler (Type | Version: 7.7 checker) | 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: | -------------------------------------+------------------------------------- Comment (by nfrisby): Ryan, this looks very promising! I think this snippet presents the idea clearly, if I understand correctly. Please confirm. {{{#!hs -- | We suspect higher-order kinds (#9123) would supplant this typeclass. class RoleIsRep f where mapCoerce :: Coercible a b => f a -> f b data T f a = T (f [a]) instance RoleIsRep f => Generic1 (T f) where type Rep1 (T f) = D1 ('MetaData "T" "module" "package" 'True) (C1 ('MetaCons "T" 'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (f :.: Rec1 []))) from1 (T x) = M1 (M1 (M1 (Comp1 (mapCoerce x)))) to1 (M1 (M1 (M1 x))) = T (mapCoerce (unComp1 x)) }}} Note that this is a performance improvement in some cases to boot! And your observation is that if we can define a lawful `Functor f` then we can define `RoleRep f`, right? Can we anticipate a time where a user would want these three things simultaneously: 1) a lawful `Functor f`, 2) a `nominal` role for `f`'s argument, and 3) an automatically derived `Generic1` instance? That's the only case where this would be "worse" for the user, I think. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8516#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler