[m-dev.] modes in typeclass instances

Thomas Conway conway at cs.mu.OZ.AU
Wed Oct 11 14:17:21 AEDT 2000


Hi

I was just considering a SAX (xml serialization interface) typeclass.
Here is an abstracted bit of the typeclass:

:- typeclass documentHandler(Handler) where [
    (pred startElement(string, list(pair(string)), Handler, Handler)),
    (mode startElement(in, in, SomeKindOfIn, SomeKindOfOut) is det)
].

Now, depending on what concrete type Handler takes, I might want different
input and output modes.

In some instances "in" and "out" might be sufficient.
In others it might be desirable to use "di" and "uo" (if the Handler
is the io__state, for example). Or you might want something in between
(such as when the io__state is stored in a structure which is a Handler).

Now, if the typeclass requires that the mode be "di", an
instance that uses "in" is legal in as much as any use of the arguments
by the caller will satisfy the mode constraints of the callee.
Unfortunately the same is not true of the "uo" argument, since the
caller is expecting the argument variable to be unique, when in fact
it is shared. This looks like a place that polymorphic ground modes
would be useful, but it needs to be trickier than anything I've seen
so far. You need the inst parameter to be a typeclass parameter or
something.

Suggestions? Comments?

-- 
 Thomas Conway              Mercurian )O+  
 <conway at cs.mu.oz.au>       Every sword has two edges.
--------------------------------------------------------------------------
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