[Haskell-beginners] [Haskell-Beginners] Just

Yitzchak Gale gale at sefer.org
Tue Jun 14 18:35:35 CEST 2011


Michael Xavier wrote:
> You can pattern match to get the value
> out of it...

That is certainly true. But I find that I rarely
do that, because we have so many nice
functions for using Maybe values.

The two most common and simplest are already
enough that you almost never need to pattern match
a Maybe:

maybe :: a -> (b -> a) -> Maybe b -> a

This applies a function to the value inside Just, or
gives a default value when it's a Nothing.

fromMaybe :: a -> Maybe a -> a -- from Data.Maybe

Like "maybe", but just gives you the value inside
the Just without applying a function.

There are so many others.

Regards,
Yitz



More information about the Beginners mailing list