Haskell Language Function composition Composition with binary function


Example

The regular composition works for unary functions. In the case of binary, we can define

(f .: g) x y = f (g x y)          -- which is also
             = f ((g x) y)
             = (f . g x) y        -- by definition of (.)
             = (f .) (g x) y
             = ((f .) . g) x y   

Thus, (f .: g) = ((f .) . g) by eta-contraction, and furthermore,

(.:) f g    = ((f .) . g)
            = (.) (f .) g
            = (.) ((.) f) g
            = ((.) . (.)) f g

so (.:) = ((.) . (.)), a semi-famous definition.

Examples:

(map (+1) .: filter) even [1..5]      --  [3,5]
(length   .: filter) even [1..5]      --  2