[mercury-users] [petdr at miscrit.be: Report on the ICFP 2000 prog contest]

Peter Schachte schachte at cs.mu.OZ.AU
Thu Sep 7 13:06:20 AEDT 2000


On Wed, Sep 06, 2000 at 01:56:47PM +1100, Fergus Henderson wrote:
> I think we should just accept arbitrary clauses in instance declarations.
> In some cases it's nicer to define a procedure using several clauses
> with pattern matching rather than using a disjunction where the pattern
> matching is done with explicit unifications.

That would be good.  It would save writing things in two places by letting
you write it only in the instance declaration.

While you're at it, how about also allowing people to omit 'is' clauses from
an instance declaration for any predicate or function that is already
defined with the right signature?  This would save you from writing things
in two places by letting you write just the predicate/function.  I expect
this will tend to come up quite often (it even does in the reference manual
discussion of type classes).

For example, if I have a class fooable:

        :- typeclass fooable(T) where [
                pred foo(T, int),
                mode foo(in, out) is det
        ]

and I have a type sometype with a foo/2 predicate:

        :- type sometype ---> ...

        :- pred foo(sometype, int).
        :- mode foo(in, out) is det.
        ...

then it seems kind of silly to have to say

        :- instance fooable(sometype) where [
                foo/2 is foo
        ].

If the method signature is the same as a visible predicate or function, why
not use that by default if no substitute is given, so I could instead write:

        :- instance fooable(sometype) where [].

It'd be nice to be able omit the "where" part altogether when the list is
empty, but I expect this would cause an ambiguity with abstract instance
declarations.

On a related note, is there any reason you'd ever want to export a concrete
rather than an abstract instance declaration?  Seems like it would always be
undesirable from a SE standpoint.  Maybe exported instance declarations
should always be taken as abstract?


-- 
Peter Schachte <schachte at cs.mu.OZ.AU>  True development puts first those
http://www.cs.mu.oz.au/~schachte/      that society puts last.
Phone:  +61 3 8344 9166                    -- Mahatma Gandhi 
Fax:    +61 3 9348 1184                
--------------------------------------------------------------------------
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