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?
As the msdn page for F# functions says,
Functions in F# can be composed from other functions. The composition of two functions
function1
andfunction2
is another function that represents the application offunction1
followed the application offunction2
.
It can be thought of as similar to the pipe operators, just without specifying the last/deepest parameter. For example, the following are all equivalent:
// forward style
let composed = f1 >> f2
let piped x = x |> f1 |> f2
// backward style
let applied x = f2 (f1 x)
let composed2 = f2 << f1
let piped2 x = f2 <| f1 <| x
Also see this question for more information.