|
Currently, no. I do plan on adding warnings (not errors) on a statically-calculated type issue. One thing is that I don't plan on it erroring if you call a function with a value whose type might be an "any" type or a "union" where it expects a specific type. If there's some overlap, it would allow, to make things easier and give the programmer the benefit of the doubt. Thus, the following would compile without warning: let double(x as Number) x * 2
let repeat(x as String) x & x
let fun(x as Number|String)
if is-number! x
double x
else
repeat x
let fail(x as Boolean)
// this should fail at compile-time
double x
I could write the compiler to be a lot smarter and have it track types through conditional branches (which would be very hard, but possible), or allow it in those cases where it is possible that the types overlap.I also might add a "cast", i.e. a runtime type check. I'm not sure what the best syntax for it would be, but it would act like the following: CAST(x, Number) // validate that x is a Number or throw a TypeError
CAST(x, Number|String) // validate that x is either a number or a string, otherwise throw TypeError
CAST(x, Number, 0) // validate that x is a Number, otherwise evaluate to 0.
Of course, in the cases where `x` could not fit the type requested, then that could error at compile-time.I would love some feedback on this, especially from the perspective of "what would I use to help me develop", not "I need my program to be 100% statically type-safe without having to do any testing". |