[mercury-users] Type Classes: can instance implementations be methods?

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jan 29 12:19:09 AEDT 2003

On 29-Jan-2003, Maria Garcia de la Banda <mbanda at mail.csse.monash.edu.au> wrote:
> I am wondering whether the method definition in an instance declaration can
> in fact be a method in the same (or some other) type class.

Yes, it can.

> Now, I have tried this in Mercury and gives me no trouble. However, I then
> thought that one can also easily define loops among the definitions like:
> :- instance(mytype) where [
>     pred(init/2) is maybe_init,
>     pred(maybe_init/2) is init].
> and this also passes Mercury's compilation, so now I am wondering whether
> the instance definition passes compilation because it is allowed (but the
> test for looped-definitions was forgotten) or because this posibility was
> not even considered by the compiler.

The Mercury compiler does have some support for termination analysis,
to issue warnings about programs that might not terminate, but this
checking is not enabled by default; you need to use the `--check-term'
option to enable it.

Detection of all loops is undecidable in general, of course!

Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
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