[Haskell-cafe] Is 'flip' really necessary?

Daniel Fischer daniel.is.fischer at web.de
Sun Jul 25 17:27:32 EDT 2010


On Sunday 25 July 2010 23:13:16, aditya siram wrote:
> Eta-reducing is nice, and sometimes it makes code more readable. But
> 'flip' is one of those functions that always seems to hinder rather than
> help readability, conversely factoring out flip always makes code easier
> to comprehend. I don't see a need for its existence - maybe I'm missing
> something and more experienced Haskellers can comment.
>
> -deech

For example,

sortBy (flip compare)

is very convenient (easier to parse¹ and it provides fewer opportunities 
for error than (\a b -> compare b a)).
Also

foldl' (flip Set.insert) Set.empty values

and such stuff.

Sometimes, functions have the wrong argument order for what you want to do, 
then flip is very handy.

¹ This is of course not a universal truth but a personal preference.


More information about the Haskell-Cafe mailing list