
13 Mar
2009
13 Mar
'09
5:54 p.m.
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. Hope this helps. Cristiano