Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 899
Leo Zhang Avatar asked Dec 02 '25 09:12

Leo Zhang


2 Answers

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.

like image 73
Willem Van Onsem Avatar answered Dec 04 '25 23:12

Willem Van Onsem


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).

like image 25
Li-yao Xia Avatar answered Dec 04 '25 22:12

Li-yao Xia