>>>>> "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


Reply via email to