3 ms·
This is why I appreciate that Haskell calls this type 'Maybe'. I think this better captures the types semantics. I mean, an 'Option' or and 'Optional' makes it
by ch 12y ago
This is why I appreciate that Haskell calls this type 'Maybe'.
I think this better captures the types semantics. I mean, an 'Option' or and 'Optional' makes it seem like you are given a choice... but a 'Maybe' implies more that what you are declaring exists only with some probability!
Q. Will this function give a result? A. Maybe.
Q. Will this function give a result? A. Option.
The choice is obvious.
- krick 12y agoTotally agree. I wondered the same way about why they chose Option over Maybe in Rust. There're so many things in the world that actually can be called Option (I could imagine <select> children or name of some business object) but pretty much none of them are about being null or not. When Maybe is so intuitive that I'm now using this word for the similar cases even in dynamic languages.
- eridius 12y agoThe choice is only obvious because you tailored the question to the Haskell type name. But that's not the question you're asking. The question is "What result will this function give me?". The Haskell answer is "Maybe a". It will give me something that might be an `a`? The Swift answer is "Optional<T>". That makes a bit more sense than "Maybe". The name makes even more sense when you talk about function arguments instead of function result types. Q. What argument does this take? A. Maybe a. It takes an argument that might be an `a`? Q. What argument does this take? A. Optional<T> Still not natural english, but the interpretation here is a bit cleaner: It takes an optional value of type `T`.
- ch 12y agoI'm not sure I totally agree. Well I do agree that I tailored the question to suit my point! But to your reply, I think you've changed the semantics of my meaning. My questions were more from the perspective of the caller, and even then it was a bit abstracted from the actual type and implementation ... just more of a conversational "Does it? Maybe!" You're rephrasing is still looking at it from the caller, but now takes into account the language semantics (which mine conveniently didn't :) ). I would rephrase your questions, and look at them from the callee's perspective: "Will I get an argument? Maybe!" And really, shouldn't we be saying that the function takes Just a to ... and takes Nothing to ... ? Perhaps this has stretched as far as it might go. Maybe?