3 ms·
Minor point: Nullable types and Maybe are two completely different things, which can be used for some overlapping use cases.
by Uchikoma 13y ago
Minor point: Nullable types and Maybe are two completely different things, which can be used for some overlapping use cases.
- mhaymo 13y agoI don't understand the difference, and a quick search turned up nothing. Care to educate?
- timclark 13y agoThere is no major difference between a nullable type and a maybe - the big difference is between non-nullable types and maybe. If you have a maybe I in my ignorance can assign a null to it, if you have a non-nullable type the compiler will prevent me from assigning a null to it.
- mhaymo 13y agoOk, so in a default non-nullable type system, nullable types are equivalent to maybes.
- pestaa 13y agoAs far as I can tell, you are right, although in my view maybes are one step ahead: they form a monad. (Not saying there's anything stopping you from doing the same thing with nullables, but still they're a slightly different concept.)
- gavinking 13y agoActually we're just talking about two different ways to represent the same concept. In the ML-derived languages, which traditionally did not have first-class union types - which I assume derives from the fact that they don't have _subtyping_, the workaround for representing A|B is to create an algebraic sum type Either which wraps the actual value we're interested in. For the case of null|B, there's a specialized Maybe or Option type. Now, this pattern has recently been imported into object-oriented land by languages like Scala and now Java 8, because these languages also don't have first-class union types. But in my opinion, that's the wrong path to have taken. In OO-land, we _do_ have subtyping, so things like unions and intersections are well-representable within the type system, and we don't need these workaround wrapper types.