# Arrows and pickler combinators

5 messages
Open this post in threaded view
|

## Arrows and pickler combinators

 Folks, I'm trying to monadify the pickler code. sequ below positively looks   like >>= but you can't really join both pickle and unpickle into a   single monad. I would like to keep the ops together, though, as this   allows me a single specification for both pickling and unpickling. Cale suggested that PU is really an arrow in that it supports both   input and output. I could not find an example of such an arrow,   though. I thought that it could be a "dual arrow" but then could not   find a description for one. I would appreciate your suggestions! The original paper is at http:// research.microsoft.com/ ~akenn/fun/picklercombinators.pdf         Thanks, Joel P.S. data PU a = PU      {       appP :: Ptr Word8 -> Int -> a -> IO Int,       appU :: Ptr Word8 -> Int -> IO (a, Int),       appS :: a -> IO Int      } pickle :: PU a -> Ptr Word8 -> Int -> a -> IO Int pickle p ptr ix value = appP p ptr ix value unpickle :: PU a -> Ptr Word8 -> Int -> IO (a, Int) unpickle p ptr ix = appU p ptr ix sizeup :: PU a -> a -> IO Int sizeup p value = appS p value lift :: a -> PU a lift x = PU (\_ ix _ -> return ix) (\_ ix -> return (x, ix)) (\_ ->   return 0) sequ :: (b -> a) -> PU a -> (a -> PU b) -> PU b sequ f pa k = PU                (\ptr ix b ->                     do let a = f b                            pb = k a                        ix1 <- appP pa ptr ix a                        appP pb ptr ix1 b)                (\ptr ix ->                     do (a, ix1) <- appU pa ptr ix                        let pb = k a                        appU pb ptr ix1)                (\b ->                     do let a = f b                            pb = k a                        sz1 <- appS pa a                        sz2 <- appS pb b                        return \$ sz1 + sz2) pair :: PU a -> PU b -> PU (a,b) pair pa pb = sequ fst pa (\ a -> sequ snd pb                            (\ b -> lift \$! (a, b))) -- http://wagerlabs.com/_______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe
Open this post in threaded view
|

## Re: Arrows and pickler combinators

Open this post in threaded view
|

## Re: Arrows and pickler combinators

 Jeremy, This is a very nice library you've got but... It does not answer my   question re: arrows and it still requires you to specify pickling and   unpickling separately. I can have a single spec right now and would   like to keep that.         Thanks, Joel On Dec 22, 2005, at 8:25 PM, Jeremy Shaw wrote: > Last weekend, I hacked up a pickling/unpickling library of my own. The > code is currently a little confusing because I decided to change the > naming scheme half way through. So, don't assume to much from the > names of things. > > darcs get http://www.n-heptane.com/nhlab/repos/BerkeleyDB-- http://wagerlabs.com/_______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe