[m-dev.] cvs diff: Bug fix for layoutst
Fergus Henderson
fjh at cs.mu.oz.au
Thu Mar 20 13:06:52 AEDT 1997
Tyson Richard DOWD, you wrote:
>
> > I have been using the name `type_of' for the following function:
> >
> > :- type (type).
> > % `type' is another name for `type_info(T)'.
> > % ... some low-level magic to implement unification (etc.)
> > % of values of type `type' omitted ...
> >
> > % type_of(X) = T iff T is the type of X.
> > :- func type_of(T::unused) = ((type)::out) is det.
> > :- pragma c_code(type_of(_X::unused) = (Type::out),
> > will_not_call_mercury, "Type = TypeInfo_for_T;").
>
> Then you've changed your names slightly from when you asked for this to
> be implemented - you used type_info, not type. Otherwise it is much
> the same.
OK, good. The name type_info/0 is fine.
> The c_code basically does what you ask, but will also need to check for
> `univ' and give an error or something, (you can't do anything with a
> univ without some data),
Uh, why not?
If we had existential types, we could implement univ as follows:
:- module my_univ.
:- interface.
:- type univ.
:- pred type_to_univ(T::in, univ::out) is det.
:- pred univ_to_type(univ::in, T::out) is semidet.
:- implementation.
:- type univ ---> some [T] univ(T).
type_to_univ(X, univ(X)).
univ_to_type(univ(X), Y) :-
(if type_of(X) = type_of(Y) then
Y = unsafe_cast(X)
else
fail
).
Although we currently don't have existential types, it would make sense for
`univ' to behave as if it were implemented in this way.
--
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.
More information about the developers
mailing list