[Haskell-cafe] Recursion problem in infinite list model

Hans Aberg haberg at math.su.se
Fri Mar 28 04:28:19 EDT 2008

On 28 Mar 2008, at 03:03, Ryan Ingram wrote:
> Another way to defer the evaluation of the second argument of (-+)  
> is like this:
> (-+) :: a -> List a -> List a
> x -+ y = List(f) where
>   f 0 = x
>   f k = case y of List g -> g (k-1)
> This is exactly what the lazy pattern will do at compile-time.

Thank you for inputs - I discovered adding ordinal length made it  
tricky to get the lazy evaluation I called for. The problem is that I  
   data List a = (Ordinal->a) :+ Ordinal
and then in
   (-++) :: a -> List a -> List a
   x -++ (b:+ q) = f:+(1+q) where
     f 0 = x
     f k = b(k-1)
possibly I need to get both b and q to be lazy. I tried experimenting  
with putting i ~also on them, but it did not seem to work.

So I may have to experiment a bit more, and perhaps return with a  
more completet example later. But inputs are welcome.

> Does
> this give you a better understanding of how lazy patterns work and why
> they fix the problem?

I had such rewriting in mind as well, but could not figure out the  
right blend. The manual call the lazy pattern "irrefutable". The  
terminology you use here is more intuitive.

It show a problem in language design: Haskell has mad a choice of  
strict and lazy evaluation in different context, but it has the  
disadvantage of hiding away the semantics. Something to think about  
when designing the next lazy computer language. :-)

   Hans Aberg

More information about the Haskell-Cafe mailing list