
Perhaps we should have a dummy module in Hackage that includes commonly
searched for functions, but instead of actually implementing them the
documentation would say don't use this and suggest an alternative and
explains why. Then you could find them in Hoogle and Hackage seems to be
highly ranked on Google so they'd be found there as well.
So a programmer would Google or Hoogle whenJust, find what they think is a
module, take a look at the documentation, and find the alternative
suggestion.
Chris
On 10 May 2013 11:44, Gabriel Gonzalez
How about I just write a blog post teaching people how to use `for_` (and more generally, how to use `Maybe`'s `Foldable` instance)? I know Oliver Charles wrote a similar post in his 24 days of Hackage, and maybe I could build on that a bit more and perhaps make it as Google-able as possible so it comes up as the top result when people search for keywords like `whenJust` and other `Maybe` idioms.
On Fri, May 10, 2013 at 11:25 AM,
wrote: Send Libraries mailing list submissions to libraries@haskell.org
To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/libraries or, via email, send a message with subject or body 'help' to libraries-request@haskell.org
You can reach the person managing the list at libraries-owner@haskell.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Libraries digest..."
Today's Topics:
1. Re: Control.Monad proposal: Add whenJust (Edward Kmett) 2. Re: Control.Monad proposal: Add whenJust (Evan Laforge) 3. Re: Control.Monad proposal: Add whenJust (Simon Hengel) 4. Re: Control.Monad proposal: Add whenJust (Andreas Abel) 5. Re: Control.Monad proposal: Add whenJust (Ivan Lazar Miljenovic) 6. Re: Control.Monad proposal: Add whenJust (Ganesh Sittampalam) 7. Re: Control.Monad proposal: Add whenJust (Petr Pudl?k)
----------------------------------------------------------------------
Message: 1 Date: Fri, 10 May 2013 07:16:53 -0400 From: Edward Kmett
Subject: Re: Control.Monad proposal: Add whenJust To: Niklas Hamb?chen Cc: Haskell Libraries Message-ID: < CAJumaK8XJrtdrXQfVb3pdi193ghz9ZEX8Q-MnVd435tDt5YFbg@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I'm -1 on this, due to it just further obfuscating the fact that Data.Foldable.for_ already exists.
On Fri, May 10, 2013 at 2:13 AM, Niklas Hamb?chen
wrote: I would like to propose the addition of
whenJust :: Monad m => Maybe a -> (a -> m ()) -> m () whenJust (Just x) f = f x whenJust _ _ = return ()
to Control.Monad, in the section
"Conditional execution of monadic expressions"
next to
guard :: MonadPlus m => Bool -> m () when :: Monad m => Bool -> m () -> m () unless :: Monad m => Bool -> m () -> m ()
Why?
It would allow us to write more readable code and fit well into the group of similar functions of this style.
Compare
mUser <- lookupUser
whenJust mUser email
or
whenJust mUser $ \user -> do putStrLn "Mailing!" email user
with some currently available alternatives:
case mUser of Just user -> do putStrLn "Mailing!" email user Nothing -> return ()
(Default base case clutter.)
import Data.Foldable
forM_ mUser $ \user -> do putStrLn "Mailing!" email user
(Not too intuitive/well-named here and "Ambiguous occurrence forM_" clash with Control.Monad.)
Some more dissatisfying alternatives:
maybe (return ()) (\user -> do putStrLn "Mailing!" email user ) mUser
flip (maybe (return ())) mUser $ \user -> do putStrLn "Mailing!" email user
import Control.Monad.Trans.Maybe import Control.Monad.Trans (lift)
_ <- runMaybeT $ return mUser >>= \user -> lift $ do putStrLn "Mailing!" email user return ()
Alternative names:
- withJust, analog to withFile and withForeignPtr
Any comments?
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries