Why “Just” for Maybe?

I assume that this was taken directly from Haskell, so maybe it’s really a question for that community, but “Just” seems like an odd choice. To me Just a suggests that there might be times when there is even more than the value of a associated with a valid value of the given Maybe. “Some” seems more correct to me. (Obviously not a huge deal)

Hi,
Maybe = Nothing | Just a is a common notation for a fundamental functional programming concept:

Haskell indeed uses that notation, so I would assume that this is where it came from in Elm.
I personally prefer Just a to Some a for instance but it’s OK to feel differently :slightly_smiling_face:

Hope this helps!

2 Likes

Naming things is one of the two hard problems of computer science :slight_smile:

Another suggestion is Have a.

3 Likes

I wonder what people would think of

type Maybe a
= Yes a
| No

I find Nothing and Just to be the best nowdays, but in the beginning I was confused. I guess the simplest way for me to understand it when I was a beginner would be:

type Maybe a
= Value a
| NoValue
4 Likes

I didn’t really get it until after spending time on Rust where the type name Option made more sense than Maybe to me. That was more of a stumbling block than the Just/Nothing vs Some/None difference. I think because Option is a more concrete noun where Maybe is an adverb. (I do recognize that maybe gets used as a noun but that is less common and almost slang.)

I’m fine with the concept (I’ve done a bit of F# so that made it easy). Some parts of the naming choices are subjective; I actually like “Maybe” better than F#’s “Option”. However, I think there’s a fairly objective case to be made that the word “Just” doesn’t really make sense in the context of a Maybe.

Perhaps I’m crazy.
Just, nothing, maybe so. :wink:

I actually suggested Yes and No as alternate names in this thread in 2013. I agree with the root feeling here, but the cost to change felt pretty high even then. I like Value and NoValue as well. That is one of the ones I suggest when folks ask me about Just not making any sense.

I think the next step on this question would be to teach a bunch of people the concept using different names and see if you can observe anything different.

5 Likes

For completeness sake, Rust uses Option a : None | Some a, and this is also the naming that Scala uses.

OCaml also uses Option, None and Some.

IMHO Maybe, Nothing and Just are good choices because those words are relatively unambiguous. Option is a word can mean many things (optional arguments, command line options, configuration options, etc.) Some is sometimes the name of a function that says whether or not there exists a value in a collection satisfying the given test. Yes and No are sometimes used as alternative names for the boolean values true and false (e.g. in YAML).

It’s quite tricky to find words that are short, evocative and unambiguous.

2 Likes

Well the Maybe package is simple enough that I wonder what cost there would be to just building alternate packages with identical functionality but different naming conventions, and then submitting those?

type YesNo = Yes a | No
type MaybeValue = Value a | NoValue
type Option = Some a | None

If one becomes popular enough in the community then perhaps it could challenge the incumbent core/default included convention. :slight_smile:

It’s not that easy: Lot’s of functions in other packages return Maybes, for example List.head. As long as those don’t provide alternatives, you would have to write wrappers yourself or live with a mixture of different Maybe types. In the latter case, you can’t use chaining with Maybe.andThen anymore unless the types happen to line up. I don’t think adoption would be high.

3 Likes

Meh, we have elm-format, I wouldn’t be surprised if some other tool to root through your elm-stuff folder and search/replace terms would be that challenging either. Then every module using Maybe could use your preferred terminology instead. :wink:

But yeah, I agree it does get to be a bit of a stretch. I just hate when networking effects lock us into decisions that may later (and after sufficient experience) prove to be sub-optimal. IIUC that’s the whole reason that Evan introduces new features into the language as slowly as he does: because those are genies you can’t put back into bottles.

Sure, you can have a tool replace everything by your preferred terminology. But then there really is no need for a package: just do that locally and publish using Maybe. Explaining to newcomers that Elm has five different, incompatible ways of denoting basically the same thing and introducing them to a tool that makes those things work together seems worse than just having to explain that they are called Just and Nothing for historic reasons, even long term.

On further thought, what bothers me is the Just. I can’t really think of a context in which Just is the opposite of None or Nothing. It’s not a quantifying modifier. It typically is a modifier signalling a lesser importance. “That’s just my little brother.” “It’s just a flesh wound.”

In contrast, Some is a reasonable complement to None.

1 Like

I agree Just feels a little weird. Some also implies some plurality like “O, I got some apples”.

Only might make more sense as it’s singular.

type Maybe thing = Nothing | Only thing

There is also:

type Maybe a 
= Thing a
| NoThing

But “Thing 5”, “Some 5” and “Yes 5” all sounds strange compared to “Just 5”.
I guess “Value 5” sounds ok.
The problem with Value is that its already in use as rawJsValue.
And keeping “Just” is actually not a problem when used to it. The cost of replacing it is much higher than gain in my opinion.
Once you first understand the concept and that the maybe type is just a normal Custom type like any other, the names is not important.
But for a beginner, I guess the Value a/NoValue would help self explain the concept.
Edit:
You could also keep the Nothing:

type Maybe a
= Value a 
| Nothing

True about Some except when used for modifying collective nouns. While you would not say having one apple means you have some apples, you might say that you have some fruit. That makes it more sensible to me than Just.

I think, too, that Just is the confusing bit.

How about Maybe a = Nothing | One a?

1 Like

I think @evancz is right in that trying out the ideas is the best way to vet them, but I have also been trying to think about exactly why terms like Just and Some feel awkward to people. After considering it for a while, I’ve managed to frame the problem in a way that makes sense to me and that hopefully will be of use to others, so I wanted to share it. It also led to another option I haven’t seen suggested before.

The short version is that I think the reason that Just and Some are confusing is that they carry additional meaning in normal usage that doesn’t apply in the context of the Maybe type.

Just implies an alternative to a different state, but usually one that is more interesting/surprising. Consider:

  • I thought there might be a bear outside the tent, but when I looked it was just a rabbit.
  • I thought there might be nothing outside the tent, but when I looked it was just a rabbit.

I’m not sure if the second of those is wrong, but I’ve never heard anyone speak like that. Additionally, “just” has a lot of other meanings that aren’t relevant in most contexts in a program.

Some has a similar problem with the additional wrinkle that the meaning changes based on context and whether it’s used with a singular or plural noun:

  • Some person may object
  • Some people may object
  • Some people were here

When used in the singular, “some” usually means an indefinite, unspecified, or arbitrary item. It can also mean that in the plural case, or it can mean a specific group based on some predicate. Each of those meanings is relevant in code sometimes, but not in every context, which can lead to confusion.

At the root of this issue is that both “some” and “just” are adjectives. They’re intended to modify the meaning of the noun they accompany, but the variant case of Maybe where the item is present doesn’t really modify the meaning of the item.

Because of all that, I think that The is a potential alternative to Just:

  • It’s an article, not an adjective, so it doesn’t modify the meaning of the associated noun
  • It works equally well with the singular and plural cases

p.s. I ran this idea past my wife to see how crazy it sounded, and she suggested 'Tis :smile:

3 Likes