
On Friday 13 March 2009, Cristiano Paris wrote:
2009/3/13 Marcin Kosiba
: ... Threading the state is not the problem. Maybe this will help: what I have now:
fsm world state = case state of first -> do_stuff_one (move_up, succ state) second -> do_stuff_two (move_left, succ state) third -> do_stuff_three (move_right, first)
what I'd want to have is to say: fsm world state = do do_stuff_one yield move_up do_stuff_two yield move_left do_stuff_three yield move_right fsm world state
and have it "translated" to:
fsm world state = do_stuff_one (move_up, \world' state' -> do_stuff_two (move_left, \world'' state'' -> do_stuff_three (move_right, fsm world'' state'')
Hi,
I've not fully understood your exact problem but I think you might have a look to Continuations and Delimited Continuations.
Both can help you solve the problem with implementing a yield statement. You can have a look at one of my (rather) old blog's posts about how to implement yield/send statements a-la-python:
http://monadicheadaches.blogspot.com/2008/01/python-25s-iterators-in-haskel l-sort-of.html
Notice that blogspot messed up with code blocks so indentation looks bad and some character is even missing.
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' Thanks! Marcin Kosiba