In addition to Telastyn's answer:
Maybe
never "silently fails". In contrast to null, which might be what the OP's is comparing it to, a Haskell function which can return Nothing
must explicitly do so in its type.
For comparison: a method returning String
in Java might return a String or null, and you cannot tell just by looking at its type:
public String myFunc(int x) { /* do something, might return null! */ }
In Haskell a function which returns a String
has a type similar to this:
myFunc :: Int -> String
You know it cannot return Nothing
, because if it did, its type would be:
myFunc :: Int -> Maybe String
This means Nothing
can never sneak up on you and "cause headaches down the line"!
Nothing
is a silent fail. Unlikenull
in other languages, functions that may returnNothing
will say so in their type and the type system will force you to handle the possibility ofNothing
in some way.Nothing
indicates the successful computation of a result. Example: if you look up a customer in a database you returnNothing
if you do not find the customer, you throw an exception if there is not database connection.