[Haskell-cafe] Recursion problem in infinite list model

Hans Aberg haberg at math.su.se
Thu Mar 27 10:55:58 EDT 2008


On 27 Mar 2008, at 15:32, Luke Palmer wrote:
> 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 ...

Thank for the suggestion, and explanation.

The reason I used a "data" construct was that I include the size of  
the list, excluded in order to keep the example as simple as possible:
   data List a = List(Ordinal -> a, Ordinal)

In addition, there seems to be no way to choose default value for a  
given (non-empty) type in Haskell, so I wrote it
   data List a = Empty | List(Ordinal -> a, Ordinal)
Here, if a type T has a default element t, I can represent the empty  
list by
   List(\_ -> t, 0)
making the constructor "Empty" redundant.

   Hans Aberg




More information about the Haskell-Cafe mailing list