[m-dev.] io streams

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Jan 6 14:25:55 AEDT 2000


On 06-Jan-2000, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> On Wed, Jan 05, 2000 at 07:32:57PM +1100, Fergus Henderson wrote:
> > On 05-Jan-2000, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> > > This is where default methods are important:  they allow you to add new
> > > methods to type classes without forcing every instance declaration
> > > (which may be in user code) to change, as long as the new methods have
> > > defaults.  It may even be possible to change an existing ordinary
> > > library predicate into a method without changing code that uses it,
> > > provided the existing code doesn't explicitly module qualify calls to
> > > it (would this be possible, DJ?).
> > 
> > That would be possible.  It would be possible even if the calls
> > where module qualified, so long as the type class and the
> > library predicate are defined in the same module.
> 
> I thought *that* was not permitted, since that means there is more
> than one "predicate" with the same arity and argument types in the
> same module?  If that is allowed, I'm glad to hear it.

No, you can't have both at the same time.
But you can start off with

	:- module m.
	:- interface.

	:- typeclass foo(T) where [
		pred p(T),
		mode p(in) is semidet
	].

	:- pred q(T) <= foo(T).
	:- mode q(in) is semidet.

	q(X) :- p(X).

and then, if default methods were supported,
you could change it to

	:- module m.
	:- interface.

	:- typeclass foo(T) where [
		pred p(T),
		mode p(in) is semidet

		pred q(T),
		mode q(in),

		default(q(X) :- p(X))	% or whatever the syntax
					% for default methods is
	].

and the client code will not need to change.

(In fact, with our current compilation scheme, if intermodule
optimization was not enalbed then I _think_ the client
code will not even need to be recompiled.)

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list