[m-dev.] For review: Add implementation of reference types (global heap)

Peter Schachte pets at students.cs.mu.OZ.AU
Wed Jun 10 16:35:02 AEST 1998


On Wed, 10 Jun 1998, Fergus Henderson wrote:

> On 10-Jun-1998, Peter Schachte <pets at students.cs.mu.oz.au> wrote:
> > Now that I think about it,
> > 
> > 	:- type nb_reference(T) == c_pointer.
> > 
> > isn't really what I want to write.  In fact
> > 
> > 	:- type nb_reference(T) ---> nb_reference(c_pointer).
> > 
> > isn't quite right, either, because I don't want even this module to be
> > trying to poke around inside it.
> 
> The declaration you're talking about doesn't let this module
> poke around inside it.  So I don't see what you're complaining about.

Well, I can confuse myself by doing:

	X = nb_reference(Y)

That's really nonsensical and shouldn't be allowed.

> > The type should be abstract even in this
> > module. What I'd really rather write is just
> > 
> > 	:- type nb_reference(T).
> > 
> > (which already appears in the interface section).  The type is defined
> > entirely in C, and as far as Mercury is concerned, it's a Word and that's
> > all it needs to know. 
> 
> Well, if we were going to allow something like this, I think we should
> require some kind of explicit declaration, rather than just
> assuming that if it is not defined here then it is defined elsewhere.

But as far as this module, and in fact all the Mercury code, is concerned,
it doesn't matter whether or not it is defined.  Maybe I'm interfacing to
assembler code, and there is no explicit type declaration anywhere.

> Declaring a type and not defining it ought to be an error
> (just as declaring a predicate or function and not definition it is
> an error).

That's the status quo I'm proposing to change.  Same principle as a
regular old abstract type:  as long as I don't try to look inside any
instance of the type, who really cares what the type is?

> The declaration to say that a type is defined in a different language
> could be something similar to `pragma import', but for types, i.e.
> 	:- pragma import_type(nb_reference).
> or
> 	:- pragma import_type(nb_reference, "C").

Sure, that'd be a good feature to have, but it's not what I want here.  As I
said, I don't want to import the type declaration in any way.  I just want a
type name I can use which won't be confused with any other type name. 

> But you can already accomplish basically the same thing, using the
> `c_pointer' abstract data type, so I don't think this sort of
> extension would be worthwhile.

It's not really the same thing.  The current way is really a lie.  I'm
saying that this type has terms of the form nb_reference(X), which I can
unwrap if I want. That's certainly not how I've been thinking of that type. 
The old way (using == c_pointer)  wasn't a lie, but it currently doesn't
work, either.  And, as you pointed out, even if it did, it would let me
accidentally unify nb_references with other c_pointer types.

Right now, Mercury has no straightforward way (that I know of) to declare a
type all instances of which are opaque (to Mercury code) and can't be
unified or otherwise confused with other such types.  Have I missed
something?


-Peter Schachte               | We hang the petty thieves and appoint the
mailto:pets at cs.mu.OZ.AU       | great ones to public office.
http://www.cs.mu.oz.au/~pets/ |     -- Aesop 
PGP: finger pets at 128.250.37.3 | 





More information about the developers mailing list