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
- Zipping two sequences together with only cons, empty, f... Kevin Atkinson
- Re: Zipping two sequences together with only cons,... Laszlo Nemeth
- Re: Zipping two sequences together with only cons,... Kevin Atkinson
- Re: Zipping two sequences together with only cons,... Lennart Augustsson
- Re: Zipping two sequences together with only cons,... Kevin Atkinson
- Re: Zipping two sequences together with only cons,... Valery Trifonov
- Re: Zipping two sequences together with only cons,... Kevin Atkinson
- Re: Zipping two sequences together with only cons,... Lennart Augustsson
- Re: Zipping two sequences together with only cons,... Kevin Atkinson
- Re: Zipping two sequences together with only cons,... Lennart Augustsson
- Re: Zipping two sequences together with only cons,... Kevin Atkinson
- Re: Zipping two sequences together with only cons,... Koen Claessen
- Re: Zipping two sequences together with only cons,... Torsten Grust
- Re: Zipping two sequences together with only cons,... Peter Hancock
- Re: Zipping two sequences together with only cons,... Laszlo Nemeth
- Re: Zipping two sequences together with only cons,... Erik Meijer
- Re: Zipping two sequences together with only cons,... Laszlo Nemeth
- Re: Zipping two sequences together with only cons,... Lennart Augustsson