[m-dev.] Insts and abstract types.

Ralph Becket rafe at cs.mu.OZ.AU
Tue May 14 15:33:13 AEST 2002


In most cases, for values of abstract types, the insts as far as the
outside world are concerned can be considered as either free, ground or
unique.  One can also imagine situations where the inst might carry
extra information, for example in subtyping, but so far such uses are
very rare.

It occurs to me that we could arrange a (default) inst mapping across
the interface/implementation boundary in these cases.

Conjecturally...

:- interface.

:- type hash_table(K, V).

	% I know this isn't (yet) legit. syntax, but...
	%
:- func hash_table(K, V) ^ elem(K) = V.
:- mode ui ^ in = out is det.

:- func (hash_table(K, V) ^ elem(K) := V) = hash_table(K, V).
:- mode (di ^ in := in) = uo is det.
...

:- implementation.

:- type hash_table(K, V) ---> ht(..., hash_pred(K), bitmap, array(V), ...).
:- inst hash_table       ---> ht(..., hash_pred, bitmap, uniq_array, ...).

:- inst_translation external(ground) = internal(hash_table).
:- inst_translation external(unique) = internal(unique(hash_table)).

Under this scheme, the implementation section of this module would
perceive the access/update function modes as

:- mode ui(hash_table) ^ in = out is det.

and

:- mode (di(hash_table) ^ in := in) = uo(hash_table) is det.

The outside world can then pass hash_tables around in the standard map,
fold, etc. operations.  Currently we can't do this because the modes for
those predicates are not polymorphic and even if they were, mode
polymorphism doesn't handle uniqueness (as far as I recall.)

We could do the same thing for arrays and do away with the unforunate
and awkward array_{di,ui,uo} modes, for instance.

Any takers?  Any showstoppers?

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