News for hackers. Stuff that matters.
Re:Functions Should Be Short And Sweet, But Why? by chongli on Wednesday January 22, 2014 @05:56PM (#7105970)
Pointfree style is a tricky style to get right. There is a bot on the #haskell IRC channel (lambdabot) that has a function which will transform any valid Haskell function definition into pointfree style. The results that come out of this are often totally ridiculous! Here's an example (stolen from the IRC channel, @pl is the bot command to do the transformation):

    @pl transform k z = reverse (foldr (\x y -> y ++ [fst(head(filter (\a -> snd a == k-1) (zip x [0..])))]) [] z)
Transformed into:

    transform = (reverse .) . flip foldr [] . (flip (++) .) . flip flip [] . (((:) . fst . head) .) . (. flip zip [0..]) . filter . (. snd) . (==) . subtract 1
Yeah, neither is readable. This function ought to be broken up into cleaner, more declarative parts. In fact, the whole function can be reduced to this:

    transform k = map (!! k)
Much more readable, wouldn't you agree? Now all you need to know is what map and !! do.

There are no comments on this comment yet.