Kevin Atkinson wrote:

> Lennart Augustsson wrote:
>
> > No, it will not be as efficient.  foldr is not the right primitive for making
> > functions on lists.  You want the more general
> >   recurse :: (a -> c a -> b -> b) -> b -> c a -> b
>
> Could you give me some refrence on how that function is used as this is
> the first time I herd of it.

Well, I just made up the name since it's not a standard function (it should be :-).
It is useful for functions doing primitive recursion.


> What exactly does it do?  What would its defination for a list be.
> How would you define a foldl, foldr, foldl1, foldr1, zip, etc.. with it.

I think the type should (almost) explain what it does :), let me exemplfy for lists
recurse c n [] = n
recurse c n (x:xs) = c x xs (recurse c n xs)

So it's like foldr, except that the cons function gets the tail of the list,
not just the head.  With it you can define an efficient tail function.

    -- Lennart




Reply via email to