What’s the difference between Unit and Nothing?

Unit is a type that has exactly one value ‒ see Unit type. On the other hand, Nothing has no possible value – see Bottom type.

A function that doesn’t return anything must have the return type Unit. If it were Nothing then the function could not return a result. The only way to exit the function would be by an exception.


Nothing is used in a different way. It is characterized by two properties:

  1. Nothing is a subtype of every other type (including Null).
  2. There exist no instances of this type.

When is this useful? Consider None:

object None extends Option[Nothing]

Because Option is covariant in its type parameter and Nothing is a subtype of everything, Option[Nothing] is a subtype of Option[A] for every type A. So, we can make one object None which is a subtype of Option[A] for every A. This is reasonable, since Nothing cannot be instantiated so Option[Nothing] will always be without a value. Similarly

object Nil extends List[Nothing]

Unit corresponds to logical true and Nothing corresponds to logical false under the Curry-Howard isomorphism, where we view types as propositions and functions as proofs, .

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)