[Haskell-cafe] Parameterizing on type

Joel Reymont joelr1 at gmail.com
Tue Nov 8 23:49:14 EST 2005


Folks,

How can I create a generic pickler that's parameterized on type and  
constructor?

I define types like this:

newtype AvgPot = AvgPot Word64 deriving (Show, Typeable)
newtype NumberOfPlayers = NumberOfPlayers Word16 deriving (Show,  
Typeable)

and then have a lot of boiler-plate code like this, a pickler for  
each type:

puAvgPot :: PU AvgPot
puAvgPot = wrap (\a -> AvgPot a, \(AvgPot b) -> b) endian

where

data PU a = PU { appP :: (a, [Word8]) -> [Word8],
                  appU :: [Word8] -> (a, [Word8]) }

wrap :: (a -> b, b -> a) -> PU a -> PU b

What I would like to have is a generic pickler that's parameterized  
on constructor and type. These can and will be the same, though. I  
want something like this, how can it be done in Template Haskell or  
otherwise?

pickler :: PU T
pickler Con pa = wrap (\a -> Con a, \(Con b) -> b) pa

	Thanks, Joel

--
http://wagerlabs.com/







More information about the Haskell-Cafe mailing list