r/purescript • u/Unable_Breadfruit • Oct 22 '19
How does the continuation monad work?
https://maxhallinan.com/posts/2019/10/22/how-does-the-continuation-monad-work/
13
Upvotes
r/purescript • u/Unable_Breadfruit • Oct 22 '19
3
u/dave4420 Oct 22 '19
No. m does not need to be a monad. m only needs to be a (covariant) functor.
Also, I think it complicates matters to jump straight to ContT. Consider data Cont r a = Cont ((a -> r) -> r) — this allows you to set r ~ m s if you want.
3
u/amalloy Oct 23 '19
This doesn't cover the thing about Cont that I always have trouble with: what do I use it for, and how? For other monads it's easy: I want to model state, so I use State; my computation may fail, so I use Maybe, or Either e. For Cont I...want to write functions in continuation-passing style? Why? What programs are easy to write with Cont that would be hard without it?