Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> writes
>> > 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?
> I certainly believe so.
There exist at least two implementations that compile such things.
Only they require to add 7 contexts like Eq [..[String]..].
I believe they can be easily improved to compile directly the initial
program.
>> 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).
> h did not know about these instances - does not accept anything more
> than a single dictionary of Eq a!
>
> And if you referred to a case where they are visible at the place
> of definition of h,
Yes, it relies on the visible instances.
As h "knows" of Eq a, then it knows potentially of its
consequences too. The consequences are defined by visible instances.
> it is still very hard to deduct that instances
> being built will lead to the one that is defined separately. It
> would probably require to look up at runtime each dynamically built
> instance in a large repository of all instances - a big complication
> and performance hit.
??
(1) Eq a => Eq [a], Eq [[a]] ... - due to standard instance,
(2) Eq [[[String]]] - by the user instance.
Do you say it is hard for the compiler to detect that the instance
for Eq [[[String]]] can be deduced in two ways?
Probably, it is as simple as all the other type resolution business
in Haskell. And surely, no run-time resolution needed.
By the way, I suggested recently how the example with overlaps
(similar to one you presented in other letter), with the modules
F,G,E, can be compiled, and overlaps resolved statically, without
in-lining between the modules.
And some people confirmed the existing compilers do act this way.
Being not an implementor at all, I was able to explain the
compilation way. The expert implementors would handle more complex
and generic task setting.
------------------
Sergey Mechveliani
[EMAIL PROTECTED]