[Haskell-cafe] Re: Control.Monad.Cont fun

Tomasz Zielonka tomasz.zielonka at gmail.com
Sun Jul 10 07:55:49 EDT 2005

On Sat, Jul 09, 2005 at 07:05:20PM +0200, Thomas Jäger wrote:
> Hello Tomasz,

Hello Thomas,

> Haskell doesn't support infinite types, but we can get close enough by
> creating a type C m b such that C m b and C m b -> m b become
> isomorphic:
> newtype C m b = C { runC :: C m b -> m b }

Thanks for this tip - I am sure it will help me in the future.

> With the help of C we can implement another version of getCC and
> rewrite the original example.
> [...]
> We can move the self-application of jmp into getCC to get the same
> type signature as your solution, but we still rely on the auxiliary
> datatype C.
> [...]
> It is easy to get rid of C here arriving exactly at your definition of getCC.

Neat! I didn't know (or didn't thought about) how to systematically
derive getCC. Thanks!

> > - is it possible to define a MonadFix instance for Cont / ContT?

> Levent Erkök's thesis suggests (pp. 66) that there's no implementation
> of mfix that satisfies the purity law.
> http://www.cse.ogi.edu/PacSoft/projects/rmb/erkok-thesis.pdf

This is a very interesting reading.

> > - do you think it would be a good idea to add them to
> >   Control.Monad.Cont?
> I think so, because they simplify the use of continuations in an
> imperative setting and are probably helpful in understanding
> continuations. Letting continuations escape is quite a common pattern
> in scheme code, and painful to do in Haskell without your cool trick.

I'll try to come up with some motivating examples, unless someone who
is in power to add these functions is reading this thread and agrees
that they are useful... ?

Alternatively, we could place them on http://haskell.org/hawiki/MonadCont.
Wow! I noticed there is a link to my message already ;-)

Best regards

More information about the Haskell-Cafe mailing list