3 ms·
Because whether foo's value is null is for most cases only detectable at runtime precisely because java doesn't have the capability to express disjoint type set
by zaphar 10y ago
Because whether foo's value is null is for most cases only detectable at runtime precisely because java doesn't have the capability to express disjoint type sets in it's type system the way that say Haskell or F# do. This inability means that the programmer can't tell the compiler what code paths produce null vs what code paths produce string. As a result the compiler has to assume that all codepaths could produce both.
There are some trivial cases where the compiler could figure it out for you but most of those cases are not very useful in practice.
- bogomipz 10y agoInteresting, is there a formal name for this kind of type system that has the ability to look at the code paths and express disjoint type sets? Is this a trend in newer languages in general or an FP specific thing?
- airless_bar 10y ago> formal name non-shitty > a trend in newer languages yes, only discovered a few decades ago :-D
- bogomipz 10y agoI understand making a snarky comment in addition to some meaningful commentary but really two useless comments? Why even take the time to do so?
- airless_bar 10y agoSorry, was meant to be a light-hearted response.
- zaphar 10y agoTypically it's referred to as an Algebraic Data Type https://en.wikipedia.org/wiki/Algebraic_data_type https://en.wikipedia.org/wiki/Algebraic_data_type. Any Type System that can express this type will be able to do the above. It's not necessarily new since the ML family of languages has had it for a while now. It's also not limited to FP languages but it best known from ML the ML family. Rust has it though as well as Swift i think.
- bogomipz 10y agoI see. Thank you for the follow up. This is really helpful. Haskell implements this data type which is why it has come up in this discussion. I need to spend some time with something from the ML family.