[Haskell-cafe] Generic "to tuple" function
Michael Orlitzky
michael at orlitzky.com
Fri Dec 26 18:18:24 UTC 2014
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.
More information about the Haskell-Cafe
mailing list