[mercury-users] Typeclass problem (bug, misunderstanding, oth er?)

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Aug 4 00:46:14 AEST 2000


On 03-Aug-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> Fergus Henderson:
> > One thing that would certainly help is syntax for explicit type
> > qualification.  Then you could write it as
> > 
> > 	main -->
> > 		{ Sol = solve(CSP, _::my_node) },
> > 		...
> 
> Sure.  Can we ditch : as a module separator sometime soon and use
> : as a type qualifier instead?

Yes, that is indeed the plan.  Sorry if I confused things by
using `::' in that example.

> > That won't work in general, since the choice of the node type
> > could affect the semantics.
> 
> I know I'm being a bit slow, but could you give an example?

Sure.

	:- typeclass foo(T) where [ func val(T::unused) = (int::out) is det].
	:- instance foo(int)    where [ func(val/1) = int_val ].
	:- instance foo(string) where [ func(val/1) = string_val ].

	int_val(_) = 1.

	string_val(_) = 2.

	main --> print(val(_X)), nl.

This will print `1' if `_X' has type `int', or `2' if `_X' has type `string'.

-- 
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-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