On Mon, 4 Oct 1999, Kevin Atkinson wrote:
> On Mon, 4 Oct 1999, Joe English wrote:
>
> > I don't quite see what algorithm you're using
> > to decide how many arguments are passed
> > to the function.
>
> Neither do I. I meant to express a general idea. Perhaps that is not the
> best way to do it but that is what I would like to be able to do.
>
> > What would you get if you typed:
> >
> > foo = foldr union []
>
> since foldr expects the function to have the signature
> (a->b->b) it will use the union which matches it, which
> will be the union :: [a] -> [a] -> [a] and not
> union :: ( a -> a -> Bool) -> [a] -> [a] -> [a].
The problem is the two might match! Consider the definitions
union :: [a] -> [a] -> [a]
unionBy :: (a -> a -> a) -> [a] -> [a] -> [a]
union = error ""
unionBy = error ""
f = union . map fst
g = unionBy . map fst
(I have dropped the (Eq a) context in the signature for union for
simplicity.) This goes thru the typechecker, and hugs tells me that
f :: [(a,b)] -> [a] -> [a]
g :: (a -> (a -> a, b)) -> [a] -> [a] -> [a]
If one were allowed to write union for both union and unionBy, so which
one should one choose?
-- m
-----------------------------------------------------------------------
Mariano Suarez Alvarez
Departamento de Matematica - Universidad Nacional de Rosario
Pellegrini 250 - Rosario 2000 - Argentina
El autor no responde de las molestias que puedan ocasionar sus escritos:
Aunque le pese
El lector tendra que darse siempre por satisfecho.
Nicanor Parra, `Poemas y antipoemas' (Advertencia al lector)
-----------------------------------------------------------------------