3 ms·
> `Foo?` as a type is still less explicit than having `Maybe<Foo>` as a type. I actually disagree with this. As long as `Foo?` is checked by the compiler, I th
by nicoburns 7y ago
> `Foo?` as a type is still less explicit than having `Maybe<Foo>` as a type.
I actually disagree with this. As long as `Foo?` is checked by the compiler, I think are almost identical in use. It doesn't matter if you don't notice the `?` if it's a compile error to miss the null check.
- smichel17 7y agoIt's the same if your Maybe<Foo>=Just<Foo>|Nothing, and in fact in that case I often prefer the nullable version, unless there's a dedicated, terse syntax for Maybe-checking built in to the language, the equivalent of null coalescing (Kotlin's ?: (Elvis operator), Typescript's ??), along with optional chaining calls (?.). If you made a Maybe with a Nothing<String> that comes with a reason why nothing was returned, or any more complicated structure like that, then it's better[1] to use that instead of approximating it with exceptions, null, callbacks with an optional error argument, etc. [1] In most cases. There's always exceptions, no pun intended.
- nicoburns 7y agoMy view is that `foo?` is a nice sugar for the common Option/Maybe/null case, but that a language is severely missing out if it doesn't also offer general sum types. I don't understand why more languages don't offer them, it seems like it'd be a fairly easy feature to add without breaking backwards compatibility.
- cdmcmahon 7y agoRich Hickey's talk "Maybe Not" has some interesting thoughts on this: https://youtu.be/YR5WdGrpoug https://youtu.be/YR5WdGrpoug