4 ms·
(&) = flip ($) in Haskell
- vitno 13y agowhile I recognize this is tongue-in-cheek, just as a PSA... When trying to hack something together, excellent. When trying to learn a new language, aim for idiomatic usage.
- Evbn 13y agoHaskell is like Lisp: so expressive that it supports many idiomatic styles of usage, depending on application domain.
- fosap 13y agoI guess F# and livescript use |> and <|. I like them better than $ and &. Like [3,1,2,3,41,2,4] |> sort (>) |> map \x->x*x
- lelf 13y agoYep, except that it is not there. There was quite a discussion about (&), (|>) and what not on the mailing list. No consensus… http://www.haskell.org/pipermail/libraries/2012-November/018832.html http://www.haskell.org/pipermail/libraries/2012-November/018... http://hackage.haskell.org/trac/ghc/ticket/7434 http://hackage.haskell.org/trac/ghc/ticket/7434
- nrlucas 13y agoF# obviously approves |>, but in my software project that has been continually maintained for ten years, we introduced -->. Now re-factoring our project we use |>. It kind of messes with my sight against pattern matching in OCaml though.
- gizmo686 13y agoBikesheddin at its finest. 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.
- tel 13y agoThis is included in the popular Control.Lens package since it sometimes has natural right-to-left composition. It's still unnatural for 99% of Haskell code you'll see, but (&) = flip ($) seems to be cemented as the "correct" representation now. It's a wontfix on the language spec itself, though.
- vimes656 13y agoIn Control.Lens package also comes with <&> which is the flipped version of <$> with the right infix priority, which I find it even handier than $. 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.
- PeterisP 13y agoMany current elements of modern languages have been wontfix'es in them for many years.
- gizmo686 13y agoIt was closed with the message: "I'm closing this ticket while the discussion is going on on the libraries list. Please reopen, or open a new ticket, if a positive decision is reached" [1] The discussion itself [2] is basically bikeshedding at this point. [1] http://hackage.haskell.org/trac/ghc/ticket/7434 http://hackage.haskell.org/trac/ghc/ticket/7434 [2] http://www.haskell.org/pipermail/libraries/2012-November/018832.html http://www.haskell.org/pipermail/libraries/2012-November/018... I took both of these links directly from lelf's comment in this thread.
- arianvanp 13y agoright-to-left application, not composition
- Tyr42 13y agoDiagrams defines # to be reverse function application.
- Evbn 13y agoYou'll flip your id ($) = 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)
- tel 13y agoNo, not strictly true! ($) has a compiler hack to let it handle impredicativity. 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 ())
- kenko 13y agoI used ¢ as flip ($).
- kenko 13y agoI guess this is too heavyweight, after all: Prelude GOA> (return [1..]) >>= return . map (^ 2) >>= return . takeWhile (< 64) [1,4,9,16,25,36,49]
- taejo 13y agoDiagrams uses (#) for this.