Kevin Atkinson wrote:

> cons   :: a -> c a -> c a
> empty  :: c
> foldr  :: (a -> b -> b) -> b -> c a -> b

I am not an expert. I have a minor problem with this, the type of
empty: if c stands for a type constructor then empty should have type
(c a). Moreover, I don't understand why you use 'c' for lists (if you
are hoping for polytypism, -- abstraction over type constructors --
that is being able to zip trees etc, then this is not going to work)

Now, if by zipping you mean the operation defined in the Prelude
(slightly differently) as:

zip :: [a] -> [b] -> [(a, b)]
zip (x:xs) (y:ys) = (x,y):zip xs ys
zip _      _      = []

then (you still need pairing and case)

foldr (\ a g ys -> case ys of 
                    []     -> empty
                    (b:bs) -> (a,b) `cons` g bs)
      (\ _ -> [])

will do. It's an example of a higher order fold. It builds a function
instead of a list. You can learn a lot about folds, from the bananas
paper[1], the warm fusion paper[2], or other papers by L. Fegaras (his
page is  http://www-cse.uta.edu/~fegaras/fegaras.html)

Hope this helps.
  Laszlo


[1] Meijer, Fokkinga, Paterson: Functional Programming with Bananas,
Lenses and Barbed Wire (it's on Erik Meijer's home page)
[2] Launchbury, Sheard: Warm Fusion: Deriving Build-Catas from
Recursive Definitions (it's on J. Launchbury's home page at OGI)




Reply via email to