[mercury-users] accessing typeclass dictionaries

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Nov 6 01:21:29 AEDT 1999


On 05-Nov-1999, Juergen Stuber <juergen at mpi-sb.mpg.de> wrote:
> On a similar note, it would also be nice to get access to
> the dictionaries for typeclasses by some kind of low-lewel
> Mercury.  Then I could put values such as for example the N
> for the type of integers modulo N there and access them
> efficiently (there is already a rather inefficient way to do
> it with existential types).  This allows to use the standard
> infix notation as the N gets passed around in the type, and
> the typechecker makes sure I only add two numbers with the
> same modulus.

I don't really understand what you mean here.
Perhaps you could elaborate, e.g. by showing the way to do
it with existential types.

If you want to put an integer in the typeclass dictionary,
you can use a zero-arity function method that returns an integer:

	typeclass foo(T) where [
		func num(T::unused) = (int::out) is det
	].

This is not quite as efficient as putting an integer in the
typeclass dictionary, since you may end up doing an indirect
method call rather than merely doing a load.  But I find it hard
to imagine this making a significant difference in real applications.

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