Thanks, I see now where my mistake was.
Laziness (or call by name) is needed to make the step from
(\e a z -> a (f z e))
(head l)
(foldr (\e a z -> a (f z e)) id (tail l) z)
(f z (head l))
to
\z -> foldr (\e a z -> a (f z e)) id (tail l) (f z (head l))
without evaluating foldr
> > That said, to express foldl via foldr, we need a higher-order
> > fold. There are various problems with higher-order folds, related to
> > the cost of building closures. The problems are especially severe
> > in strict languages or strict contexts. Indeed,
> >
> > foldl_via_foldr f z l = fol
* o...@okmij.org [2013-02-19 06:27:10-]
>
> As others have pointed out, _in principle_, foldr is not at all
> deficient. We can, for example, express foldl via foldr. Moreover, we
> can express head, tail, take, drop and even zipWith through
> foldr. That is, the entire list processing librar
As others have pointed out, _in principle_, foldr is not at all
deficient. We can, for example, express foldl via foldr. Moreover, we
can express head, tail, take, drop and even zipWith through
foldr. That is, the entire list processing library can be written in
terms of foldr:
http://okm
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 th
Thanks Roman and Andres for the tip. I knew the trick with accumulating a
function, but I had never imagined it could work so efficiently. I thought
the problem with using foldr would be that the function would be neither
tail recursive nor efficient and so I hadn't even tried. Apparently that
was
* Roman Cheplyaka [2013-02-18 18:28:47+0200]
> * Petr Pudlák [2013-02-18 17:10:26+0100]
> > Dear Haskellers,
> >
> > while playing with folds and trying to implement `!!` by folding, I came to
> > the conclusion that:
> >
> > - `foldr` is unsuitable because it counts the elements from the end,
* Petr Pudlák [2013-02-18 17:10:26+0100]
> Dear Haskellers,
>
> while playing with folds and trying to implement `!!` by folding, I came to
> the conclusion that:
>
> - `foldr` is unsuitable because it counts the elements from the end, while
> `!!` needs counting from the start (and it's not tai
Hi.
> while playing with folds and trying to implement `!!` by folding, I came to
> the conclusion that:
>
> - `foldr` is unsuitable because it counts the elements from the end, while
> `!!` needs counting from the start (and it's not tail recursive).
What is the problem with the following defini
Dear Haskellers,
while playing with folds and trying to implement `!!` by folding, I came to
the conclusion that:
- `foldr` is unsuitable because it counts the elements from the end, while
`!!` needs counting from the start (and it's not tail recursive).
- `foldl` is also unsuitable, because it a
Dear Haskellers,
while playing with folds and trying to implement `!!` by folding, I came to
the conclusion that:
- `foldr` is unsuitable because it counts the elements from the end, while
`!!` needs counting from the start (and it's not tail recursive).
- `foldl` is also unsuitable, because it a
11 matches
Mail list logo