Search code examples
f#pointfreefunction-composition

Understanding the F# Composition Operators


I am well-versed in using the >> and << operators in F#. However, after looking in the F# source to establish a deeper understanding I became confused with this:

let inline (>>) f g x = g(f x)
let inline (<<) f g x = f(g x)

How do I interpret these expressions conceptually? Also, how would you describe these expressions? Are they defining a type?


Solution

  • As the msdn page for F# functions says,

    Functions in F# can be composed from other functions. The composition of two functions function1 and function2 is another function that represents the application of function1 followed the application of function2.

    It can be thought of as similar to the pipe operators, just without specifying the last/deepest parameter; e.g. the following two lines are equivalent:

    let composed = f >> g
    let piped x = g <| f x
    

    Also see this question for more information.