[Haskell-cafe] Maybe a, The Rationale
philip.weaver at gmail.com
Sat May 10 19:02:53 EDT 2008
On Sat, May 10, 2008 at 3:56 PM, PR Stanley <prstanley at ntlworld.com> wrote:
>>> Paul: Hi folks
>>> data Maybe a = Nothing | Just a
>>> What is the underlying rationale for the Maybe data type? is it
>>> safe style of programming it encourages/
>>> Something tells me this is going to start a lengthy discussion. :-)
>> Bob: Pure and simple -- it allows you to represent partial
Here's one simple example that popped into my head...
maybeHead :: [a] -> Maybe a
maybeHead  = Nothing
maybeHead (x:xs) = Just x
>> Looking up a map will only sometimes find a value, so we either return
>> Nothing, or Just that value.
> Paul: Would yu like to demonstrate this in an example?
See the 'lookup' function (
) or just abut any other function on Hoogle that uses a Maybe type.
> Cheers, Paul
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe