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 folk...) :
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 s')) HTH, Tom _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe