The Point Free Style

here come two interesting examples:

f, jf1, jf2 :: a -> Bool
f x = (jf1 x) && (jf2 x) 
f = liftM2 (&&) jf1 jf2

f c b = (head c) * b : c
f = flip (join . ((:) .) . (. head) . (*))
------
f = flip =<< ((:) .) . (*) . head
------
f = join ((. ((*) . head)) . (.) . (flip (:)))
------
f = liftM2 (.) (flip (:)) ((*).head)

actually, we can find that
  • ((:) .) . (. head) . (*) :: a -> [a] -> [a] -> [a]
    • it equals to f a as as' = (head as) * a : as'
  • ((:) .) . (*) . head :: [a] -> a -> [a] -> [a]
    • it equals to f as a as' = (head as) * a : as'
  • (. ((*) . head)) . (.) . (flip (:)) :: [a] -> [a] -> a -> [a]
    • it equals to f as as' a = (head as) * a : as'
  • the last method just distrubes the [a] to both (filp (:)) and ((*).head) which generate two functions, and later (.) will combine the two function into one , which takes an a.

lambdabot on the irc channel can transform a pointwise expression into a pointfree one in a really smart way by the command @pl. Try it!

Page tags: haskell
page_revision: 19, last_edited: 1215859982|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License