toString, aka overloading problems

Alan Grover awgrover@umich.edu
Thu, 4 Jun 1998 09:05:29 -0500


At 3:49 AM -0500 6/4/98, Sjaak Smetsers wrote:
>Alan Grover <awgrover@umich.edu> wrote
>>	instance test [Int]
>>		where
>>		test a = (map ((+) 1) a)
>>
>>	instance test [[Int]]
>>		where
>>			test a = (map sum a)		// <--- line 67
<snip>
>>The compiler prevents me from evaluating the wrong type,
>>and it derives the two types, yet seems to get it wrong in instances.
>>
>
>I don't understand what you mean.

I meant that the compiler seems to know the difference between [] and [[]]
in all cases except instances. I gave the example where I tried to evaluate
[[1]] where the function was typed for [], and the compiler indicated a
type mismatch. Also, the compiler derived the types [[]] and [] for the two
instances. Yet, if both instances exist, I get the "multiply defined
symbol" error.

It seems that the compiler is quite capable of staticly determining that
these two instances are of different types. You note that there are
technical reasons for actually not allowing this. Since I am no expert in
that area, and didn't try to figure out the principle involved, I am
certainly not challenging your statement.  Could you give a brief hint
towards those reasons? I might guess that it is something about picking the
instance when the compiler can't staticly type the application.

---
"Alan Grover, Technical Pb" awgrover@umich.edu
+1 (743) 647-5778
Project Leader
Health Media Research Lab, Cancer Center
5D04 North Ingalls Building, Mail Stop 0471
300 North Ingalls
Ann Arbor, MI 48109-0471