[Haskell-cafe] generalized, tail-recursive left fold that can finish tne computation prematurely
Niklas Hambüchen
mail at nh2.me
Mon Feb 18 18:48:21 CET 2013
On 18/02/13 16:10, Petr Pudlák wrote:
> - `foldr` is unsuitable because it counts the elements from the end,
> while `!!` needs counting from the start (and it's not tail recursive).
It is common misconception that foldr processes the list "from the right".
foldr "brackets" from the right, but this has nothing to do with
processing direction; all [a] are processed left to right, since this is
the only way to structurally deconstruct them.
This is the reason why it is possible to write
foldr (:) [] [1..]
If foldr processed the list from the right, it would on infinite lists -
and it does.
More information about the Haskell-Cafe
mailing list