Leo Zhang
Leo Zhang

Reputation: 3230

In Haskell, if Maybe is a Type or an Union Type, how do you call `Nothing`?

In Haskell, a Maybe type can be either a Nothing or a Just a

data Maybe = Nothing | Just a

If we call Maybe Union Type, what is Nothing then? a Type? No, it's not a type, you can't declare a variable to be Nothing type.

Maybe you would say type constructor, true, but I want to express the fact that Nothing and Just are different cases.

a type value? a type instance? a type case?

Upvotes: 2

Views: 832

Answers (2)

Li-yao Xia
Li-yao Xia

Reputation: 33509

Nothing is also called a "case" of the "variant" (or "variant type") Maybe a. This terminology is used more frequently in OCaml than in Haskell, e.g., Real World OCaml chapter of variants (I don't know what is common in other languages).

Upvotes: 4

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477190

It is a data constructor. Since it has no arguments, it is also called a constant and nullary data constructor.

These data constructors group values (well here there are no values) together, together with a tag: some sort of identifier that identifies that it is a Nothing, and not a Just.

Upvotes: 10

Related Questions