14

Why is the Scala Option type not called Maybe, just as in Haskell?

Maybe makes a lot more "semantic sense" to me, but maybe Option has different behaviour I am not aware of.

Is there any particular reason why Option in Scala was not called Maybe?

2 Answers 2

24

Scala is also inspired by Ocaml, which uses Option.

Options are an Ocaml standard type that can be either None (undefined) or Some x where x can be any value. Options are widely used in Ocaml to represent undefined values (a little like NULL in C, but in a type and memory safe way)...

I think the name chosen is a matter of taste.

3
  • 8
    F# too. The page on Wikipedia is en.wikipedia.org/wiki/Option_type. Seems to be a more standard name than Maybe
    – KChaloux
    Aug 9, 2013 at 14:30
  • 3
    Ocaml gets the name from SML. In a quick glance through Landin's The Next 700 Programming Languages I didn't notice an option type, so SML might be the origin of the name. Aug 26, 2013 at 10:56
  • 1
    An argument in favor of Option is that it's an optional value (either you get it or you don't). Maybe implies some degree of uncertainty on the programmer's part. Maybe there is a value? I don't know.. Should I get a value? The wording optional value sounds more intentional in my opinion. Aug 27, 2019 at 15:20
7

A better question here would be why Haskell's option type is called Maybe. ML's option type is probably the grandaddy of all option types, and it's called option.

In any case, this is a terminological question, so it's not going to have a principled answer. The people who picked the name in Haskell liked it better, that's it.

5
  • 2
    What possessed you to repeat information in a new answer that's already well-covered by the accepted answer and its underlying comments? Sep 15, 2015 at 1:03
  • 6
    @RobertHarvey ML having set the precedent is new information, the real problem is that the answer is conjecturing even that.
    – djechlin
    Sep 15, 2015 at 1:04
  • OK. Do you have a reference, or something more than just an opinion? Because opinions are better represented as comments, not answers. Especially your second paragraph. Sep 15, 2015 at 1:09
  • 3
    Def. Option: The act of choosing; choice. Def. Perhaps; possibly; An uncertainity; An uncertain reply. For me that is eough to say Maybe is the much better name from a purely linguistic point of view. "Option" implies that there are (multiple) choices, while the monadic name "Maybe" is much more to the point: one thing or nothing. But yes, ML (and hence, Option) came first, so that may be the reason for the bad naming habbit (And see Peter Taylor's comment to the right answer above - he does reference ML).
    – fnl
    Sep 15, 2015 at 12:25
  • @fnl See my comment on the other answer; I think there's a reasonable case to make that option is an abbreviation for optional. In which case the (multiple) choices are reduced to just two: either it's there or it isn't. Aug 27, 2019 at 15:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.