[Haskell-cafe] Using a monad to decompose a function into functions

Cristiano Paris frodo at theshire.org
Fri Mar 13 17:54:32 EDT 2009


2009/3/13 Marcin Kosiba <marcin.kosiba at gmail.com>:
> 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


More information about the Haskell-Cafe mailing list