[bitc-dev] Reference struccture and union types
Jonathan S. Shapiro
shap at eros-os.org
Sun Aug 6 14:31:31 EDT 2006
This note is to wrap up an earlier thread, the last of which can be seen
at:
http://www.coyotos.org/pipermail/bitc-dev/2006-July/000745.html
The heart of the question is:
If x:T is a reference type, is it always okay to write (deref x)
The answer is no.
First, the answer was already "no" if T had dynamic size. For example,
if x had type (vector T), you can't write (deref x) because the size of
the vector is not known at compile time.
However, there is a more general problem that Swaroop has identified
that is making a big mess -- see the discussion thread that ends with
http://www.coyotos.org/pipermail/bitc-dev/2006-August/000763.html
So here is the resolution that I think we should adopt:
1. (dup x) can be applied to any value x of any type 'a, with
result type (ref 'a).
2. (deref x) can only be applied to things of type (ref 'a).
3. If T is a reference type (as opposed to a value type) [example:
the (list 'a) type defined in the prolog] then
3a) T does *not* unify with (ref 'a) [note: this is a change]
3b) (deref T) is *not* permitted [note: this is why]
This resolves the typing problem that Swaroop is wrestling with, but it
leaves us with a different problem: we need a way to introduce a type 'a
that matches any reference type.
Proposal:
We will introduce two additional built-in type classes:
(ValueType 'a) 'a is a value type. Includes built-in types and
any composite (structured) type that is declared
with :val [example: pair is a value type]
(ReferenceType 'a) 'a is a reference type. Includes the built-in
type Vector, any type of the form (ref 'b), and
any composite (structured) type that is declared
[implicitly or explicitly] with :ref
We *may* also want to introduce (ScalarType 'a) at some point.
Note that (ValueType 'a) and (ReferenceType 'a) are disjoint.
(ScalarType 'a), if we ever introduce it, is a subset of (ValueType 'a).
In consequence, (ScalarType 'a) and (ReferenceType 'a) are also
disjoint.
These new, built-in type classes will be closed type classes (in the
sense that no DEFINSTANCE is required or permitted for them) that are
defined in the standard prelude.
For the moment, I don't see any operations (methods) that make sense for
these type classes, but the back of my head is itching about EQ, EQL,
and EQUAL here, so that may change.
shap
More information about the bitc-dev
mailing list