Flipped function application

Heinrich Apfelmus apfelmus
Fri Oct 11 09:13:44 UTC 2013


Simon Peyton-Jones wrote:
> I quite like that.  ($$), that is.  Better than (&)
> 
> Simon
> 
> | > we don't need new name suggestions at this point, but:
> | >
> | > Consider <**> :: f a -> f (a -> b) -> f b.
> | >
> | > That suggests <$$> :: f a -> (a -> b) -> f b by analogy,

I strongly prefer (#) . It's used by the diagrams [1] library

    example1  =   circle 1 # fc red   # lw 0
              ||| circle 1 # fc green # lw 0

and by my own threepenny-gui package [2]

    example2 = do
         button <- UI.button # set text "Doorbell"
         status <- UI.span
                   # set text "Thinking"
                   # set style [("color","blue")]

         on UI.click button $ do
             element status # set text "Disturbed"


A year ago, I might have opposed the proposal altogether, but diagrams 
has convinced me that it's quite useful. In particular, I think it's 
great when you want to put the emphasis on the argument and treat the 
functions as styling. For instance, in  example2  , the focus is on the 
fact that  status  is a new span element, whereas the specific styling 
of the span is secondary.

In my opinion, only (#) looks "right" for this purpose, though.

I don't think it's a good idea to add it to the Prelude, but I would 
appreciate it in Data.Function or thelike.


   [1]: http://hackage.haskell.org/package/diagrams
   [2]: http://www.haskell.org/haskellwiki/Threepenny-gui

Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com





More information about the Libraries mailing list