Add flipped fmap

Felipe Lessa felipe.lessa at gmail.com
Wed Apr 7 09:58:27 EDT 2010


On Wed, Apr 07, 2010 at 03:33:51PM +0200, Johan Tibell wrote:
> Hi Felipe,

Hello! :)

> On Wed, Apr 7, 2010 at 3:09 PM, Felipe Lessa <felipe.lessa at gmail.com> wrote:
> > I've needed <$$> many times and had to use 'flip fmap' instead.
>
> In my opinion this is not a good criteria for including a function.
[snip]

I think I understand your point very well.  I'm also not fond of
adding shortcuts, and that's why I said I used 'flip fmap' while
I could have defined <$$> myself instead.  My reasons for adding
this particular function are:

1) <$> is very useful because it is infix, while `fmap` is ugly
   and doesn't have a nice fixity.

 --
   Prelude> :t \f g x -> f . g `fmap` x
   <interactive>:1:10:
       Precedence parsing error
           cannot mix `.' [infixr 9] and `fmap' [infixl 9] in the same infix expression
 --
   Prelude Control.Applicative> :t \f g x -> f . g <$> x
   \f g x -> f . g <$> x
     :: (Functor f) => (b -> c) -> (a -> b) -> f a -> f c
 --

   <$$> will be as concise and useful as <$>, maybe even more,
   because `flip fmap` isn't valid.

2) Simmetry, as the ticket says.


> Yet, if we add all the function compositions that some group of
> people use in their code our APIs get much more complicated.

I completely agree, but I think you're overreacting to this
proposal (no offense intended, please :]).  I don't see a
tendency of adding every combinator to the libraries, and I don't
think this proposal will change anything.

Cheers,

--
Felipe.


More information about the Libraries mailing list