Is there a Haskell Wiki page (or blog) on Monad Suspension? This looks
like a nice paradigm that apfelmus points out "can be used to
considerably shorten your code", but only if the rest of us learn how!
If not, maybe someone can be persuaded to write one?
Dan
Joachim Breitner wrote:
Hi,
Am Freitag, den 25.04.2008, 11:49 -0700 schrieb Dan Weston:
I guess like minds think alike! See the very recent e-mail thread
started by Ryan Ingram:
http://thread.gmane.org/gmane.comp.lang.haskell.cafe/39155/focus=39159
Take a look at the code referenced in Luke Palmer's reply:
http://luqui.org/git/?p=luqui-misc.git;a=blob;f=work/code/haskell/frp/Fregl/Suspend.hs
A snippet follows:
> class (Monad m) => MonadSuspend v m | m -> v where
> attempt :: m a -> m (Either a (v -> m a))
> suspend :: m v
>
> newtype SuspendT v m a
> = SuspendT { runSuspendT :: m (Either a (v -> SuspendT v m a)) }
Your (Coroutine m a) appears to be isomorphic to (SuspendT () m a) [so
Coroutine m () = SuspendT () m ()]
Your runCoroutineT appears to be isomorphic to a specialization of
runSuspendT:
runSuspendT' :: SuspendT () m () -> m (Either () (() -> SuspendT () m ()))
Here the () -> a ~ a and Either () a ~ Maybe a
You are quite right, it really is the same thing. The implementation
behind runCoroutineT is not just a specialization, but the exact same
thing (with Left and Right switched). I just put the specialization
there because I had no need for a return value in my use case.
And interesting how Ryan and me had the same thoughts on the same day.
Maybe the April 24th should be considered Suspend You Monadic Action
Day.
Greetings,
Joachim
------------------------------------------------------------------------
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe