4 ms·
We have that in JavaScript with undefined. It's awful. Here is different proposal. Let's allow people to define their own types of missing values. We'll call i
by Ygg2 6y ago
We have that in JavaScript with undefined. It's awful.
Here is different proposal. Let's allow people to define their own types of missing values. We'll call it Nullable<T> or Maybe<U>.
- wruza 6y agoA usual Maybe(Just, Nothing) doesn’t cover these use cases, because Nothing is just a typesafe null as in “unknown unknown”. Case(Data T, Later T, None E, Error E) could do. It is all about return/store values, because you get values from somewhere, and it’s either data of T, promise of T, okayish no value because of E, or error because of E. Where E is a structured way to signal the reason. No other kinds of code paths exist, except exceptions, it seems. (The latter may be automatically thrown on no type match, removing the need for try-catch construct.)
- Ygg2 6y agoMy point is, there is no size fits all. Maybe you only have Some(data)/Nothing. Maybe you have a Some(data)/NoData/MissingData/Error(err)/CthuluLivesHere. It's better you develop one for you and that suits you, rather than just a set of null-likes that are similar in meaning, but different in semantics.
- Smaug123 6y agoIndeed: your language needs to support the ad-hoc creation of these primitives in a first-class way. (Which is why I still consider a typed language without union types to be fundamentally crippled.)
- TheCoelacanth 6y agoundefined is awful because you can use it anywhere. Done properly you would only be able to use it in APIs that specifically need to deal with that form of null.
- runeks 6y agoIt’s also awful because it’s unnecessary when we can just define e.g. Option<T> at the library level.