Parsers and Producers with different base monads

62 views
Skip to first unread message

Daniel Díaz

unread,
Sep 20, 2014, 6:52:19 AM9/20/14
to haskel...@googlegroups.com
Hi,

Would it be feasible to have a parser which worked in a different monad than its producer? And would it make sense?

Something like this:

type Parser a t m r = forall x. StateT (Producer a m x) (t m) r

Where t is an instance of MonadTrans. For example, if t is itself a Producer, we have a streaming parser.

Of course, we can just hoist lift the Producer which is passed to the parser, and then somehow remove the unused monad layer in the result Producer, after running the parser. But this is kind of ugly.

Daniel Díaz

unread,
Sep 23, 2014, 6:00:44 PM9/23/14
to haskel...@googlegroups.com
After playing with the idea a little, it is indeed workable.

One defines a type like

type ParserZ a t m r = forall x. StateT (Producer a m x) (t m) r

and uses hoist lift to lift pre-existing pipes-parse parsers as needed. We can have effects available to the parser that aren't available to the source Producer. 

An example here.

Gabriel Gonzalez

unread,
Sep 23, 2014, 6:01:51 PM9/23/14
to haskel...@googlegroups.com, diaz.c...@gmail.com
Yeah, see this Github issue, which talks about this same trick:

https://github.com/Gabriel439/Haskell-Pipes-Parse-Library/issues/31
--
You received this message because you are subscribed to the Google Groups "Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-pipe...@googlegroups.com.
To post to this group, send email to haskel...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages