[Haskell-cafe] Maybe a, The Rationale

Jules Bean jules at jellybean.co.uk
Wed May 14 09:49:30 EDT 2008

PR Stanley wrote:
>>         Paul:   What is the underlying rationale for the Maybe data type?
>> It is the equivalent of a database field that can be NULL.
>         Paul: shock, horror! the null value or the absence of any value 
> denoted by null is not really in harmony with the relational model.

Ketil should have said:

It is the equivalent of the extremely common way of misusing NULL.

It doesn't bring in all the unpleasant baggage of three valued logic, 
but simple indicates an exceptional value. This use of NULL, very common 
in practical databases, frowned on by DB designers who understand about 
relational theory and normalisation, is prevalent precisely because 
common SQL dialects really make it a pain to invent your own datatypes, 
so it's hard to "add an exceptional value".

Practical programming needs a particular exceptional value very often 
indeed, to model things like optional parameters.

If common SQL dialects supported types like 'Maybe Int' natively, then 
NULL could be used much less.


PS Students of NULL and 3-valued logic will note that some of the 
problem therein can be studied in Haskell by comparing (==) and liftM2 
(==) as functions on Maybe Bool, or (>) vs liftM2 (>) on Maybe Int.

More information about the Haskell-Cafe mailing list