Thursday, May 29, 2008

Eschewing flip

I realized recently that I've developed a small dislike of the Haskell function flip, which reverses the order of arguments of a binary function:
mod 3 5 ==> 3
flip mod 3 5 ==> 2
flip is generally used in place of a lambda expression, when constructing a specialized function:
map (\x -> mod x 17) [1..] -- with lambda
map (flip mod 17) [1..] -- with flip
Unfortunately, my brain really doesn't like that reversal. When reading any non-trivial expression using flip, I have to stop and think about which argument is now where.

I've found that I prefer sections. You need to have one of the arguments handy, but I find that's often the case:
map (`mod` 17) [1..] -- with section
I like this form better because it preserves the visual ordering of the arguments, which seems to be deeply seated in my reasoning process. Because of Haskell's flexibility with switching between prefix and infix application, it's easy for me to adopt a style to suit this preference.

Tuesday, May 13, 2008

Paul McCartney was in a band before Wings?

Jeremy Shaw observed today that "Haskell is moving up in the world." His evidence was that a Google search for "haddock" now puts the Haskell documentation tool third on the list.

I guess we'll know that Haskell is a complete and total success when we overhear some kid in a supermarket asking, "Haddock is a fish?"