Forgot to CC the list:

I'd be -1 on an operator, I think having a named function for this is a good thing for readability of code.

As far as good style: I personally think it is. In classy-prelude, I actually export the Foldable-based `mapM` by default, and will regularly use that (or forM) for this kind of code.

On Tue, Sep 23, 2014 at 8:27 AM, Kazu Yamamoto <kazu@iij.ad.jp> wrote:
Hi,

Recently, I need to write the following code:

    getModTime :: Maybe FilePath -> IO (Maybe UTCTime)
    getModTime mfile = case mfile of
        Nothing -> return Nothing
        Just file -> Just <$> getModificationTime file

I feel that this is redundant. So, I used 'traverse' instead:

    getModTime :: Maybe FilePath -> IO (Maybe UTCTime)
    getModTime mfile = getModificationTime `traverse` mfile

First, I would like to know whether or not this is a good coding style.

Second, if this is acceptable, why don't we define an operator? For
instance,

   (<:>) :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b)
   (<:>) = traverse

    getModTime :: Maybe FilePath -> IO (Maybe UTCTime)
    getModTime mfile = getModificationTime <:> mfile

Is there such an operator already?

Regards,

--Kazu
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe