Problem with continuations and typing

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Problem with continuations and typing

Jerzy Karczmarczuk wrote:
 | zeros fc sc = sc 0 zeros
 | fails to compile as well. *I do not ask why, I know*.
 | But I would like to continue this exercice along these
lines, without too much
 | exotism (no monads, yet...), for my students. Do you have
any simple work-around?
 | Introduce some algebraic constructors? Perhaps
higher-rank polymorphism could do
 | something (but then I would have to explain it to my

How about this for a non-exotic algebraic type?

> newtype G a b = G{ unG :: b -> (a -> G a b -> b) -> b }
> glist g       = unG g [] (\b g' -> b : glist g')
> zeros         = G (\no yes -> yes 0 zeros)
> disj  g1 g2   = G (\no yes -> unG g1 (unG g2 no yes)
>                                      (\b g1' -> yes b
(disj g1' g2)))

I haven't had much practice with continuations, so don't
know whether I've just lost some generality there.

But it does support *some* avoidance of higher-rank
polymorphism, through the use of good old partial
application.  For example, the type of the state variable s
doesn't leak into the result type of unfold:

> unfold f s    = G (\no yes -> case f s of
>                     Nothing      -> no
>                     Just (s', b) -> yes b (unfold f

Haskell-Cafe mailing list
[hidden email]