Marcin 'Qrczak' Kowalczyk  <[EMAIL PROTECTED]>  
wrote on overlapping instances

> The other issue is efficiency if you want f to behave the same way even
> when the instance Eq (Maybe String) is not visible at f's definition.
> It would mean that every overloaded function must be extended to
> directly receive all dictionaries it needs. This can give not only
> very many, but even an infinite number of dictionaries needed (with
> polymorphic recursion). I cannot imagine a sensible implementation
> of the function:
>     h :: Eq a => a -> a -> Int
>     h x y = if x == y then 0 else 1 + h [x] [y]
> which would make h "1" "2" return 7 if in some other module there is:
>     instance Eq [[[[[[[String]]]]]]] where
>         x == y = length x == length y


I wonder, is this really a problem to compile this?
As this instance got to the scope, the compiler adds dictionaries
for  Eq a => Eq [..[a]..]  up to the number  7  of them to pass to
h  (assume the compiler adds the deduced context).
Maybe, the code will not be nice.
But it is, probably, as nice as the source program, that
contains  instance Eq [[[[[[[String]]]]]]] ...

Maybe, the code will be slow.
But it is only is as slow as the program "asks".
`if x==y', `h [x] [y]' are placed in such a manner, that they ask 
the evaluator to find
[x]==[y],  then [[x]]==[[y]] - with the same x,y,  and so on.
Probably, the compiler is not guilty.


------------------
Sergey Mechveliani
[EMAIL PROTECTED]




Reply via email to