
On Friday 13 March 2009, Cristiano Paris wrote:
2009/3/13 Marcin Kosiba
: Hi, I've already checked those out. I tried using your yield implementation and while it works, I couldn't get it to work with the state monad. So while: data RecPair a b = Nil | RP (b, a -> RecPair a b) yield x = Cont $ \k -> RP (x, k)
got me half-way to my goal, I couldn't figure out how to make something like:
yield' = do state <- get state' <- yield state put state'
Basically, the yield is built upon the Cont monad which has a transformer counter part, ContT. You could try and re-implement the yield under ContT instead of just Cont then you can stack ContT on top of State (or StateT if you need more monads) and have a state (i.e. get/put) and the yield.
Great! That helped a lot. I'm attaching a ConT yield implementation and another one which also handles a return statement with a different type. Hope someone finds them useful. Thanks! Marcin Kosiba