[Haskell-cafe] ANN: Control.Monad.IfElse

Jeff Heard jefferson.r.heard at gmail.com
Mon Dec 22 09:24:53 EST 2008

Provides useful anaphoric and monadic versions of if-else and when, as
well as infix operators for the actions to allow things like this:

-- Allow the clause to be in m a
whenM (Gtk.widgetIsFocus win) $ do

-- anaphoric if.  If the condition is nonempty, pass the conditional
value to the "then" clause, otherwise do an action that requires no
aif (lookup name list)
  (\file -> Right `liftM` hGetLine file)
  (do f <- openFile name
       l <- hGetLine file
       return $ Right (f,l))

-- infix version of Control.Monad.When
(x>5) >>? putStrLn x

-- infix version of anaphoric when
lookup name list >>=? \value -> putStrLn value

-- infix version of anaphoric whenM
Gtk.widgetIntersect win rect >>=>>? \intersectingRectangle' ->
Gtk.invalidate intersectingRectangle'

More information about the Haskell-Cafe mailing list