You can write your own functions that never produce a value. Consider the following function:
never :: a -> b
never a = never a
It fails to terminate, so it is considered to be the value _|_
(pronounced bottom). All types in Haskell are actually the sum of the type and this special value.
You can also write a function that is only partially defined, like
undefinedForFalse :: Bool -> Bool
undefinedForFalse True = True
undefinedForFalse False
is undefined
, which is a special value that is semantically equivalent to _|_
except that the runtime system can stop execution, because it knows it will never finish.
error
is also special function that's result is always semantically equivalent to _|_
, it tells the runtime system that it can stop execution, knowing it will never finish, along with an informative error message.
Haskell is incapable of proving that a type can never take the value _|_
because it is always possible for a type to take the value _|_
. Values that can never be _|_
are called "total". Functions which always produce a value other than _|_
in a finite period of time are called "total functions". Languages that can prove this are called "total languages" or "total functional programming languages". If they can prove this for all types in the language, they are necessarily Turing incomplete.