(&) = flip ($) in Haskell
vemod.net
vemod.net
It's a wontfix on the language spec itself, though.
AFAIK, there is very little sample code out there with these flipped operators, but to a programmer used to OOP, using them may be more natural.
The discussion itself [2] is basically bikeshedding at this point.
[1] http://hackage.haskell.org/trac/ghc/ticket/7434 [2] http://www.haskell.org/pipermail/libraries/2012-November/018...
I took both of these links directly from lelf's comment in this thread.
There was quite a discussion about (&), (|>) and what not on the mailing list. No consensus…
http://www.haskell.org/pipermail/libraries/2012-November/018...
When I was first learning haskell, I thought I was missunderstanding how to use the language because I would define (|>) a f = f a in every project I do. I thought that such an operator seemed so obvious that it couldn't possibly not be standard. The fact that it wasn't seemed to suggest that I was doing Haskell badly, and that there was some deep reason I should only work right to left using operators such as ($), which I still do use a fair amount.
Like
[3,1,2,3,41,2,4] |> sort (>) |> map \x->x*x
When trying to hack something together, excellent.
When trying to learn a new language, aim for idiomatic usage.
Prelude GOA> (return [1..]) >>= return . map (^ 2) >>= return . takeWhile (< 64)
[1,4,9,16,25,36,49]($) = id Except that id works on values and functions, but $ only works on functions.
(&) = flip id
$ is just an less-expressive alias for id that looks prettier (and has different precedence/associativity when used infix)
import Control.Monad.ST
infix 0 %
(%) = id
runST $ return () -- :: ()
runST % return () -- Type error!
Couldn't match expected type `forall s. ST s a0'
with actual type `m0 a1'
In the return type of a call of `return'
In the second argument of `id', namely `(return ())'
In the expression: runST `id` (return ())