[m-dev.] existential types, RTTI & class casts (was: new release of Mercury)

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Oct 6 05:43:21 AEST 1999


On 06-Oct-1999, David Glen JEFFERY <dgj at cs.mu.OZ.AU> wrote:
> On 05-Oct-1999, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > 
> > One thing that would be nice to do before the release is RTTI support
> > for existential types.  I guess that is not _essential_, but it seems
> > a shame to release with existential types in a half-supported state.
> 
> Should I work on this?

That would be great.

By the way, I realized the other day that we already have a syntax for
dynamic type class casts: you can use `std_util:construct' to dynamically
construct an existential data type with a class constraint.

In fact the existing syntax is actually quite nice:

	:- typeclass foo(T) where [ func foo_method(T) = int ].

	:- type any_foo ---> some [T] foo(T) <= foo(T).

	:- func bar(T) = int.
	bar(X) =
		(if class_cast(X) = foo(X_as_Foo) then	
			foo_method(X_as_Foo)
		else
			42
		).

Here `class_cast' can be defined as follows:

	:- func class_cast(T1) = T2.
	:- mode class_cast(in) = out is semidet.
	class_cast(Arg) = Result :-
		construct(type_of(Result), 0, [univ(Arg)], ResultUniv),
		det_univ_to_type(ResultUniv, Result).

So, all we need to do is to implement the RTTI support to make this work ;-)

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