Question about typing

Dylan Thurston dpt@math.harvard.edu
Sun, 8 Apr 2001 12:38:27 -0400


On Sun, Apr 08, 2001 at 11:34:45AM +0000, Marcin 'Qrczak' Kowalczyk wrote:
> ...
> I found a way to express map and zipWith, but it's quite ugly. I would
> be happy to have a better way.
> 
>     class Map c' a' c a | c' -> a', c -> a, c' a -> c, c a' -> c' where
>         map :: (a' -> a) -> c' -> c
> ...
>     -- zipWith is similar to map, only more complicated:
>     class ZipWith c1 a1 c2 a2 c a
>         | c1 -> a1, c2 -> a2, c -> a,
>           c1 a -> c, c a1 -> c1, c2 a -> c, c a2 -> c2
>         where
>         zipWith :: (a1 -> a2 -> a) -> c1 -> c2 -> c
> ...

You raise many interesting question, but let me ask about one: why the
specific choice of functional dependencies above?  Why is "c' a -> c"
necessary for Map?  Why doesn't ZipWith include, e.g., "c1 a2 -> c2"?

(I don't have a lot of experience with these functional
dependencies...)