[mercury-users] this appears to be a mixin

Dave Slutzkin dave_slutzkin at yahoo.com
Tue Jul 10 22:41:40 AEST 2001


 --- Ralph Becket <rbeck at microsoft.com> wrote:
> > From: Terrence Brannon
> > But anyway, my feeling is that the code below was
> not described as a
> > mixin, when it does in fact appear to be so.
> > 
> > :- pred distance(P1, P2, float) <= (point(P1),
> point(P2)).
> > :- mode distance(in, in, out) is det.
> > 
> > distance(A, B, Distance) :-
> >         coords(A, Xa, Ya),
> >         coords(B, Xb, Yb),
> >         XDist = Xa - Xb,
> >         YDist = Ya - Yb,
> >         Distance = sqrt(XDist*XDist +
> YDist*YDist).
> 
> Having searched around on the web for a definition,
> it's still not
> clear to me exactly what constitutes a mixin class. 
> As far as I
> can work out, mixin classes are pretty much the same
> thing as
> Java/C# interfaces - that is, something inheriting
> from a mixin 
> class must provide its own implementations for the
> method signatures
> specified in the mixin class.  On this basis, type
> classes are very
> similar to interfaces/mixin classes since they do
> not provide
> implementation inheritance.

A mixin is in fact, AFAIK, a base class that provides
all the functionality (methods and data) for a child
class - the class does not (should not) override the
methods itself.  A mixin provides functionality that
is exactly similar in many different classes, by
providing each class with these methods.  The classes
know nothing about this functionality and do not need
to know anything about it.  Then other classes that
access the mixin functionality need only know that the
class is derived from the mixin.

But I'm not sure how this relates to the code Terrence
gave previously.  And, in fact, I'm becoming less sure
as to whether or not I am right.  ;-)

Hoping, Dave.

_____________________________________________________________________________
http://messenger.yahoo.com.au - Yahoo! Messenger
- Voice chat, mail alerts, stock quotes and favourite news and lots more!
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list