[haXe] Not unifying type parameters.
Nicolas Cannasse
ncannasse at motion-twin.com
Sat Aug 12 15:08:24 CEST 2006
> I've been playing with haXe for a couple of days, and I've found that
> the compiler doesn't always unify types when I expect it to. In the
> last of the examples below, the only way I can find to successfully
> compile is with an unsafe cast. Is this a bug or a feature?
This is a feature.
In fact, there is no variance in haXe right now.
Even if "B implements A", it does not mean that "Enum<B> is a subtype of
Enum<A>".
Here's an counter-example, if you define :
class F<T> {
function f() : T;
}
Then while Int is a subtype of Float (any Int is also a Float), F<Float>
is a subtype of F<Int> (since where function that returns a Float is
accepted, a function that returns an Int will work also).
When the type parameter is only used in function parameters (for both
classes and enums) - like in your Enum case - it's true that the
parameter is covariant. It's just that the compiler is not smart enough
to guess it right now.
I'm planning to work on the subject for future haXe releases, after I'm
done with Flash9 support.
Nicolas
More information about the Haxe
mailing list