Kevin Atkinson wrote:

> >  Assuming that
> > you allow pairs and lambda expressions you can do it like this:
> >
> > caseList xs n c =
> >     fst (foldr (\ x (_, xs) -> (\ n c -> c x xs, x `cons` xs))
> >                (\ n c -> n, empty) xs) n c
> >
> > zip =
> >   foldr (\ a g ys -> caseList ys empty ( \ b bs ->(a,b) `cons` g bs))
> >         (\ _ -> empty)
>
> That is a heck of a lot of lambda's.  What exactly is going on here and
> if the container was a list would it be as efficient as the straight
> forward zip defined in the prelude.

The caseList function implements case analysis on lists using basically
"the old predecessor trick".  Then I just borrowed the zip from a previous
message.
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

    -- Lennart




Reply via email to