[Hs-Generics] Request for code review: Generics for tuple/newtype introspection

Nicolas Frisby nicolas.frisby at gmail.com
Sat Dec 21 15:54:14 UTC 2013


Ah. I took "feed toAttrs' output tuple into itself" too literally.

Good luck to you.


On Sat, Dec 21, 2013 at 2:21 AM, AntC <anthony_clayden at clear.net.nz> wrote:

> > 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+.
> >
>
>
>
> _______________________________________________
> Generics mailing list
> Generics at haskell.org
> http://www.haskell.org/mailman/listinfo/generics
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/generics/attachments/20131221/3bae645e/attachment.html>


More information about the Generics mailing list