[m-rev.] Fast string library

Fergus Henderson fjh at cs.mu.OZ.AU
Thu May 17 01:40:41 AEST 2001


On 17-May-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> On Wed, May 16, 2001 at 03:35:54AM -0700, Ralph Becket wrote:
> > To make the typeclass-only idea work, we would presumably have to make
> > every
> > user defined type an instance and automatically provide default 
> > implementations.
> 
> Right.  I believe that's happening now for unification and comparison, and
> maybe printing.  Maybe others?

Well, almost.  What happens now is that there are some builtin operations,
namely unification, comparison, and the RTTI stuff in std_util.m
(construct, deconstruct, etc.), which are provided automatically for all types.
But currently these operations are *not* type class members.

> > Moreover, we would have to restrict the declaration of
> > instancehood for this case to the defining module.  Bleugh.
> 
> Why would that be?  I guess I don't understand how instance declaractions
> for a type can be defined other than in the module that defines the type.
> How can the compiler keep you from declaring the same type to be an instance
> of the same class, with different method implementations, in different
> source files?

The compiler alone can't, but together with the linker it can:
you'll get duplicate symbol definition errors from the linker.

bash$ mmc duplicate_instance_1.m duplicate_instance_2.m
duplicate_instance_2.o(.data+0x0): multiple definition of `<instance declaration for duplicate_instance_1:foo(int/0)>'
duplicate_instance_1.o(.data+0x0): first defined here

bash$ cat duplicate_instance_1.m
:- module duplicate_instance_1.
:- interface.
:- typeclass foo(T) where [].
:- instance foo(int) where [].

bash$ cat duplicate_instance_2.m
:- module duplicate_instance_2.
:- interface.
:- import_module duplicate_instance_1.
:- instance foo(int) where [].

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list