Add flipped fmap

Heinrich Apfelmus apfelmus at quantentunnel.de
Wed Apr 7 13:22:53 EDT 2010


Johan Tibell wrote:
> Bas van Dijk wrote:
>>
>> Indeed, I would like to emphasize that my main reason for adding a
>> flipped fmap is symmetry. I find it hard to explain why <$$> shouldn't
>> be in this list:
>>
>> (<$>)  ∷ Functor f ⇒ (α → β) → (f α → f β)
>> (<$$>) ∷ Functor f ⇒ f α → (α → β) → f β
>>
>> (<*>)  ∷ Applicative f ⇒ f (α → β) → (f α → f β)
>> (<**>) ∷ Applicative f ⇒ f α → f (α → β) → f β
>>
>> (>>=)  ∷ Monad f ⇒ f α → (α → f β) → f β
>> (=<<)  ∷ Monad f ⇒ (α → f β) → (f α → f β)
> 
> I think the argument I would make is that (<**>) and (=<<) shouldn't
> have been added in the first place.

Concerning the addition of (=<<), I'm actually using it more often than
the original (>>=). That's because it plays well with function
composition, which is left to right. Here an example taken from some
code I wrote:

    runMaker m =
       sequence_ . G.topsort' . rules2Graph . snd =<< runWriterT m

(Arguably, I should should have used (<=<) and tacked a ($) at the end
if want an explicit argument, but I'm unclear about the fixities of (<=<).)


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



More information about the Libraries mailing list