Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Jeff Heard <jefferson.r.heard <at> gmail.com>
Subject: ANN: Control.Monad.IfElse
Newsgroups: gmane.comp.lang.haskell.cafe
Date: Monday 22nd December 2008 14:24:53 UTC (over 8 years ago)
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
  this
  that

-- anaphoric if.  If the condition is nonempty, pass the conditional
value to the "then" clause, otherwise do an action that requires no
parameter.
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'
 
CD: 3ms