On Mon, 4 Oct 1999, Mariano Suarez Alvarez wrote:

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

I don't know.  Like I said before it was just a general idea of what I was
trying to accomplish.

Perhapes Carlos Camarao de Figueiredo <[EMAIL PROTECTED]>, the author of
"Type Inference for Overloading without Restrictions, Declarations or 
Annotations", http://www.dcc.ufmg.br/~camarao, could comment on this one
as resolving those sort of ambiguities, I belive, is part of his paper. (I
have not had a chance to look at in detail as it is quite technical.)

---
Kevin Atkinson
[EMAIL PROTECTED]
http://metalab.unc.edu/kevina/





Reply via email to