[Haskell-beginners] Maybe perform an action

Tim Baumgartner baumgartner.tim at googlemail.com
Sun Dec 5 12:23:52 CET 2010


Hi Haskellers,

I have another simple question in order to improve my coding style.
I'm using the following function, e.g. when a dialog returned Maybe
NiceStuff:

performMaybe :: Monad m ⇒ Maybe a → (a → m b) → m ()
performMaybe x action = when (isJust x) (action (fromJust x) >> return ())

example use:
main = performMaybe (Just "Hello") print

Now I wonder if others use such a function as well, if it's already
defined in the standard libraries (didn't find it using Hoogle) and
perhaps how to implement it a little nicer.

Regards
Tim



More information about the Beginners mailing list