[Hs-Generics] Request for code review: Generics for tuple/newtype introspection
AntC
anthony_clayden at clear.net.nz
Sat Dec 21 08:21:36 UTC 2013
> Nicolas Frisby <nicolas.frisby <at> gmail.com> writes:
> For the "minor point", you'd like for example the following equivalence
> (modulo decomposing the Attr type)? ...
Thanks Nicolas
No, I do want a list result. it's a different list element I want. So I can
go:
toAttrs (undefined `asTypeOf` head (toAttrs (FooD 7, ...)))
(Compare: typeOf $ typeOf ...
The applicable Relational Theory here is that any data structure
can be represented as a Set (List) of tuples,
each tuple element being a Name with value of some type.
And since that applies for _any_ data structure,
it must also apply for the structure of structures.)
So instead of returning Attr:
data Attr = Attr TypeRep TypeRep deriving (Show)
Return a tuple of:
newtype AttrAttrib = AttrAttrib TypeRep
deriving (Show, Typeable, Generic)
newtype AttrBasedOn = AttrBasedOn TypeRep
deriving (Show, Typeable, Generic)
toAttrs :: (Generic product,ToAttrsR (Rep product))
=> product -> [(AttrAttrib, AttrBasedOn)]
toAttrs = map (\(Attr a b) -> (AttrAttrib a, AttrBasedOn b))
. toAttrsR . from
>
> So:
>
> 1) Have I understood your specification correctly?
>
No, but I've learnt something more about the power of Generics.
> 2) Other experts: is there safe trickery to generally specify this map?
> I think it might actually be doable in 7.4, but as far as I know,
> that was accidental generally-unsound functionality that was removed in
7.6+.
>
More information about the Generics
mailing list