[bitc-dev] Type Classes: Pragmatics Questions

Iavor Diatchki iavor.diatchki at gmail.com
Mon Aug 1 16:42:54 EDT 2005


Hello,

On 8/1/05, Jonathan S. Shapiro <shap at eros-os.org> wrote:
> ...
> Actually, CY is asking a good question that I did not initially
> understand. A later comment by Mark Miller clarified it for me.
> 
> Type Classes introduces a necessary violation of lexical scope in order
> to ensure that two instantiations do not exist simultaneously for the
> same type.
> 
> In consequence, it is possible to write two programs A and B, each
> providing its own instantiation of "TC char". These two programs may
> communicate fine over a pipe, but if they are later linked into a single
> binary image it becomes necessary to resolve the collision of
> instantiations.

I think this problem is not specific to type classes, the same problem
occurs if the two programs define the same global identifier.  To fix
the problem a programmer would have to rename one of the identifiers,
and rename all references in the one program to use the new name.

The situation with type classes is simillar: if the two programs
really need different  instances for the same class and the same type,
then in one of the programs the type will have to be replaced with a
new type that is isomorphic to the old one.   In practise this is
probably not very common, as long as programmers use types that are
tailored to what they  are doing.  Furtermore this problem will never
occur, if the system does not have user defined type class, for
example, if only the numeric operations are overloaded for the usual
built-in types.

Of course, as Jonathan pointed out, there may be more sophisticated
changes that have to happen before two programms can be merged into
one.

-Iavor



More information about the bitc-dev mailing list