
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.

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

On Fri, Dec 26, 2014 at 5:39 PM, Roman Cheplyaka
On 26/12/14 20:18, Michael Orlitzky wrote:
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
http://lpaste.net/117317 works using the older Data.Data.Data, but it's dissatisfying because if you get the result type wrong (too few or too many elements), you'll always get a Nothing. Maybe generics-sop is better in that respect. Regards, Adam

On 12/26/2014 05:39 PM, Roman Cheplyaka wrote:
On 26/12/14 20:18, Michael Orlitzky wrote:
But I'm wondering, is there any generic function that will take a simple data type and cram it into a tuple?
Should be easy to do with the generics-sop package.
Thanks, I was able to get this working in ghci: import qualified GHC.Generics as GHC import Generics.SOP data Foo = Bar Int Int Int Int deriving (Show, GHC.Generic) instance Generic Foo to_tuple :: Foo -> (Int, Int, Int, Int) to_tuple (Bar w x y z) = (w,x,y,z) toTupleG = to . from An example:
let b = Bar 1 2 3 4 to_tuple b (1,2,3,4) toTupleG b :: (Int,Int,Int,Int) (1,2,3,4)
participants (3)
-
adam vogt
-
Michael Orlitzky
-
Roman Cheplyaka