Seeing the Maybe type is isomorphic to a multitude of null and singleton lists, why would anyone ever want to use the Maybe type when I could just use the lists to accommodate the absence?
Based on the existing (and correct) answers, I mentioned a style based answer.
Different types convey different intentions - a return Maybe ais a computation with the possibility of failure, and [a]may be non-determinism (or, more simply, a lot of possible return values).
Maybe a
[a]
, typeclasses - , . Alternative (<|>), , ( ) .
Alternative
(<|>)
Nothing
, , , (<|>) -. , , (<|>) - , Haskell: -.
, . , , .
, [] [x], , , , .
[]
[x]
Maybe Nothing Just x . , .
Maybe
Just x
, , , , , . "" , , .
. , , . "none" null.
Maybe, . , . "", .
Lisp, Scheme, Python, Ruby, JavaScript .., , Haskell . , JavaScript ( ), , , , .. , - . , , Haskell, , . , ( ) . , .
Maybe. - - .
. , , , , Maybe s, listToMaybe :
listToMaybe
listToMaybe :: [a] -> Maybe a listToMaybe [] = Nothing listToMaybe (a:_) = Just a
, .
, , , , , , , , . , , - , a -> [b], ( ) . , , , , :
a -> [b]
Maybe, , none, .
, , QuickCheck - .