views:

267

answers:

3

I found defining the following

(%)  = flip fmap

I can write code like the following:

readFile "/etc/passwd" % lines % filter (not . null)

to me it makes more sense then the alternative

filter (not . null) <$> lines <$> readFile "/etc/passwd"

Obviously its just a matter of order, does anyone else do this? is there a valid reason not to write code like this?

+3  A: 

There is a similar function for the Applicative typeclass called <**>; it's a perfectly reasonable thing to want or use for Functor as well. Unfortunately, the semantics are a bit different for <**>, so it can't be directly widened to apply to Functor as well.

bdonlan
+4  A: 
-- (.) is to (<$>) as flip (.) is to your (%).

I usually define (&) = flip (.) and it's just like your example, you can apply function composition backwords. Allows for easier to understand points-free code in my opinion.

codebliss
There's also the Arrow combinator (>>>) which is the same as (flip (.)) for functions
Will
Why thank you sir! Other than the import boilerplate, this will be useful so I can keep standard code.
codebliss
+3  A: 

Personally I wouldn't use such an operators because then I have to learn two orders in which to read programs.

Martijn
Not sure I find this argument compelling enough, but it's an interesting point of view, so +1. Out of curiosity: do you prefer `=<<` over `>>=` for that same reason?
Stephan202
I certainly do!
pumpkin
I never understood the previous statement. It seems to make sense using standard notation because then it's like unix piping?
codebliss
I prefer =<< to >>= because the form has a clear interpretation in terms of the Kleisli category of your monad which can be inverted to give an understandable definition for comonads.
Edward Kmett
Stephan: that said your argument seems I'll posed. Preferring >>= to =<< would be more appropriate as you are given the former and the other is derived. I realize you were after the argument order though.
Edward Kmett