>>>>> "Kevin" == Kevin Atkinson <[EMAIL PROTECTED]> writes (quoting Lennart)
>> recurse c n [] = n
>> recurse c n (x:xs) = c x xs (recurse c n xs)
> Ok so how would you define, a foldl, foldr, foldl1, foldr1, and zip
> using it?
Maybe Lennart's recurse should be called listrec.
> I remember seeing it before and I could not figure out how to define a
> foldl using it.
Use higher order types. If I remember foldl,
foldl f a [] = a
foldl f a (x:xs) = foldl f (f a x) xs
By interchanging the last two arguments,
foldl f a xs = foldl' f xs a
where
foldl' f [] = \ a -> a
foldl' f (x:xs) = \ a -> foldl' f xs (f a x)
So take
n = id
c x xs r = \ a -> r (f a x)
ie.
my_foldl f a xs = recurse (\ x xs r a -> r (f a x)) id xs a
I've not checked it. Try to define zip yourself using the same
idea.
-- Peter
- Re: Zipping two sequences together with only cons, empt... Lennart Augustsson
- Re: Zipping two sequences together with only cons, empt... Kevin Atkinson
- Re: Zipping two sequences together with only cons, empt... Valery Trifonov
- Re: Zipping two sequences together with only cons, empt... Kevin Atkinson
- Re: Zipping two sequences together with only cons, empt... Lennart Augustsson
- Re: Zipping two sequences together with only cons, empt... Kevin Atkinson
- Re: Zipping two sequences together with only cons, empt... Lennart Augustsson
- Re: Zipping two sequences together with only cons, empt... Kevin Atkinson
- Re: Zipping two sequences together with only cons, empt... Koen Claessen
- Re: Zipping two sequences together with only cons, empt... Torsten Grust
- Re: Zipping two sequences together with only cons, empt... Peter Hancock
- Re: Zipping two sequences together with only cons, empt... Laszlo Nemeth
- Re: Zipping two sequences together with only cons, empt... Erik Meijer
- Re: Zipping two sequences together with only cons, empt... Laszlo Nemeth
- Re: Zipping two sequences together with only cons, empt... Lennart Augustsson
- Re: Zipping two sequences together with only cons, empt... Lennart Augustsson
