generics-sop
generics-sop copied to clipboard
[feat] allow deriving via Generically
-
[x] allow deriving
via Genericallyas suchdata A = B | C deriving stock GHC.Generic deriving Generic via Generically A -
closes #153
-
[x] update on the documentation with a short section on deriving
Generic -
[x] CI passes
Somewhat unfortunately, datatypeInfo has the wrong type for being able to derive it via Generically:
class Generic a => HasDatatypeInfo a where
-- | Type-level datatype info
type DatatypeInfoOf a :: T.DatatypeInfo
type DatatypeInfoOf a = GDatatypeInfoOf a
-- | Term-level datatype info; by default, the term-level datatype info is produced
-- from the type-level info.
--
datatypeInfo :: proxy a -> DatatypeInfo (Code a)
default datatypeInfo :: (GDatatypeInfo a, GCode a ~ Code a) => proxy a -> DatatypeInfo (Code a)
datatypeInfo = gdatatypeInfo
The issue here is that because proxy is a type variable, we cannot assume that its parameter is representational or phantom, there are three solutions, all of which are breaking changes, the obvious one being specializing to Proxy or Proxy# which both have type role phantom on their parameter. Another option would be to specify a quantified Coercible constraint which would have the advantage to not fix the type but the disadvantage that it's basically incompatible with all ghc versions.
another possibility without specifying the type and without quantified constraints is to directly have
Coercible (proxy a) (proxy (Generically a)) which would hold for all the proxy types without role nominal and allow deriving via Generically, but this would nonetheless be a breaking change for people using proxies with a nominal parameter.
oups, this is a duplicate of #159 ... perhaps we can merge these