[Haskell-cafe] Recursion problem in infinite list model

Luke Palmer lrpalmer at gmail.com
Thu Mar 27 10:32:23 EDT 2008

On Thu, Mar 27, 2008 at 2:18 PM, Claude Heiland-Allen
>  The combination of (-+) and h is too strict, this modification works:
>  (-+) :: a -> List a -> List a
>  x -+ ~(List y) = List(f) where   -- lazy pattern match
>    f 0 = x
>    f k = y(k-1)

More to the point, if List is declared as:

    newtype List a = List (Integer -> a)

Instead of with "data", it also works.

The problem, as was stated, was that -+ is too strict.  That is,
without the ~ there, -+ evaluates its right argument to make sure it's
not _|_ (that is the only other possibility in this case), and then
proceeds with the rest of the function.  So in:

    h x = first x -+ h (rest X)

This first evaluates the recursive call, which will evaluate the
recursive call, which ...


More information about the Haskell-Cafe mailing list