Antoine, Thanks for the suggestions. No sooner did I send my message than I came to the same conclusion of creating a monadic version of the combinators to simplify the migration. It actually worked out fairly well -- most of the code ported over to the monadic version unaltered. The only exception is with literal lists used by combinators such as 'sep', e.g. sep [...]. This has to become sep $ sequence [...] in order to convert the argument into the expected monad.
I put my code up on github https://github.com/warrenharris/pretty/blob/master/src/Text/PrettyPrint/Reader.hs. If you can take a look, I'd appreciate your suggestions. Warren On Apr 12, 2012, at 6:22 PM, Antoine Latter wrote: > Hi Warren, > > On Thu, Apr 12, 2012 at 6:31 PM, Warren Harris <[email protected]> > wrote: >> I wrote a parsec parser that does symbols lookups during the parsing process >> (ParsecT String Store IO a). Now I'd like to write a pretty printer that >> does the reverse. Unfortunately there doesn't appear to be a transformer >> version of Text.PrettyPrint.HughesPJ. Can anyone suggest a way to do this? >> Thanks, > > It seems like the opposite would be a function of type 'a -> Store -> IO Doc'. > > Maybe a function of type 'a -> ReaderT Store IO Doc' could be easier > to work with. > > If you go this route you could write a lifted versions of (<>), (<+>), hcat > etc. > > An example: > > (<>) :: Applicative m => m Doc -> m Doc -> m Doc > > I haven't tried any of this, so I'm not sure if you would get any big > win over just using the first suggestion (a function of type 'a -> > Store -> IO Doc') and using the stock combinators and threading the > store around by hand. > > But do let me know if something works out. > > Antoine
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
