Type combinations

Lars T Hansen lth at acm.org
Sat Nov 24 11:35:39 PST 2007

On Nov 24, 2007 3:37 PM, Peter Hall <peter.hall at memorphic.com> wrote:
> Is there any way to express an "intersection" type, analogous to a
> union type?

None at present.  I toyed with similar things for a while, being able
to subtract types from unions and so on.

> I can see there may be fewer use cases that there are for
> union types, but they could be useful in the following cases:
> 1. An argument must implement two interfaces, but it's not practical
> to introduce a 3rd interface to unify them as a single type.
> 2. An argument must be some subtype of a given type, but also
> implement one or more additional interfaces.
> A trivial example (using dubious syntax):
> function replicateObject(obj:(DisplayObject & IClonable)):void
> {
>    var copy:DisplayObject = obj.clone();
>    parent.addChild(copy);
> }
> I know that proposals are closed now, but this seems simpler than -
> and complimentary to - union types.

I think TG1 should look into various kinds of type constraints for the
next iteration of the spec -- this would be interesting for the
parameterized types, also.  For now, proposals really need to be
closed if we're going to finish the spec within a reasonable time.  I
will write up this as a ticket in Trac and then immediately resolve it
as "Deferred"; the intent is that we will produce a document with
deferred ideas by and by.  There are lots of them.


More information about the Es4-discuss mailing list