I don't follow. Union types don't seem particularly structural to me.
They're the disjunction of other types, and if the other types are
nominative then so is the union of them. A type like String | Integer
contians all expressions that are Strings or Integers. The idea would be
that you can write the followig. Here I'm borrowing a touch of Scala syntax
to allow switch on runtime type and use | to indicate disjunction of types.
void foo(String | Integer argument) {
switch(argument) {
case s : String => "It was a String " + s
break;
case i : Integer => "It was an Integer " + i
}
}
The types of actual arguments would be checked statically. The type system
would allow foo("hello") and foo(42) but would not allow foo(false). For
backward compatibility, the argumenttype could be erased to the least upper
bound (in this case Object) in the bytecode.
Similarly, you could write
String | Integer foo(Boolean flag) {
if (flag) return 42;
else return "hello";
}
On Wed, Aug 19, 2009 at 4:21 AM, Ben Schulz <[email protected]> wrote:
>
>
>
> I'm not much of a PLTist, but I'm guessing the reason uions don't make
> it into general purpose, object oriented languages is that they're
> inherently structural. Just a guess though. (The alternative is having
> to check the runtime type and downcast, which pretty much defeats the
> purpose.)
>
> With kind regards
> Ben
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---