Haskell: What monad did I just reinvent? Haskell: What monad did I just reinvent? multithreading multithreading

Haskell: What monad did I just reinvent?


It looks like a resumption-with-state monad. I think there used to be a resumption monad in MTL around GHC 6.6 but if there was it disappeared. William Harrison at the University of Missouri has a number of papers about resumption monads - http://people.cs.missouri.edu/~harrisonwl/publications.html


I don't understand why not

data Computation a = Step (Computation a) | Done ainstance Monad Computation where   (Step g) >>= f = Step $ g >>= f   (Done b) >>= f = Step (f b)   return = Done

I'm not sure what this monad is, but it's definitely simpler and seems to be equivalent in most respects.


I haven't spent too much time understanding your code, but it really sounds like the coroutine monad from the monad-coroutine package, which may be a bit more general.