[Haskell-cafe] Generic "to tuple" function
Roman Cheplyaka
roma at ro-che.info
Fri Dec 26 22:39:44 UTC 2014
On 26/12/14 20:18, Michael Orlitzky wrote:
> I have tons of code like this:
>
> from_tuple = uncurry MLBBoxScoreGameBreakdownXml
> to_tuple (MLBBoxScoreGameBreakdownXml a h) = (a,h)
>
> The first function, from_tuple, generalizes easily with `uncurryN` from
> Data.Tuple.Curry. But I'm wondering, is there any generic function that
> will take a simple data type and cram it into a tuple?
>
> So instead of writing,
>
> from_tuple = uncurryN MLBBoxScoreGameBreakdownTeamXml
> to_tuple (MLBBoxScoreGameBreakdownTeamXml w x y z) = (w,x,y,z)
>
> I could just do,
>
> from_tuple = uncurryN MLBBoxScoreGameBreakdownTeamXml
> to_tuple = toTupleGeneric
>
> because things get real ugly when there are ~20 fields in the data type.
Should be easy to do with the generics-sop package.
Roman
More information about the Haskell-Cafe
mailing list