|
|
|
|
|
by gavinking
4574 days ago
|
|
> While this is interesting, is it enforced by the compiler? Of course. That's the whole point. I really think you've missed the nature of Ceylon. Don't imagine, that just because it has a syntax that looks friendly and harmless and familiar, that it doesn't have a really killer type system under the hood. > i.e. is the following a runtime, or compile time error? A compile-time error, of course. |
|
I read the definition as (ignoring the implementation):
Correct me if I am wrong, but there doesn't appear to be anything linking the nullability of the return value based on the possible emptiness of the input value. How does the compiler check this constraint (which sounds a lot like a dependent type relation)?Upon further reading of the Iterable type[2], I have more questions, does "Nothing" satisfy "Null"?
| If not, then it looks to me like passing in a non-empty iterable (Iterable<X,Nothing>) is a type error.
| If so then I would imagine that it becomes harder to enforce the constraint, likely because the return type can still be Null regardless of input restrictions. Does this use extra type inference on the expressions inside the function to do the enforcement, for instance using the "exists" operator to perform type set subtraction between {Value|Null} and {Null} on the true branch. This implies that if I re-write the max function to have a single exit point (`ret = Null; if (exists values.first) { ...; ret = ...; } return ret;`) then I don't get the same guarantees?
Also the fact that Null is referenced by the "exists" operator also implies that it is part of the language specification, and not actually definable in any meaningful way as a user type.
Digging a bit deeper, I was very disappointed to read this snippet [3]:
If I read correctly, that means that I cannot implement the same behaviour/enforcement with completely user defined types.[1]: http://modules.ceylon-lang.org/repo/1/ceylon/language/1.0.0/...
[2]: http://modules.ceylon-lang.org/repo/1/ceylon/language/1.0.0/...
[3]: http://modules.ceylon-lang.org/repo/1/ceylon/language/1.0.0/...