How to Pipeline Arithmetic Operators in F#

I’ve been playing around with F# lately and have been using it to implement the MurmurHash3 algorithm. Once I got the hang of the pipeline and composing functions correctly, it turned out to be pretty straightforward to implement the 32 bit version. They key to my whole implementation was figuring out how to properly pipeline all the operators so I could create a simple function that mapped the byte array to integers and then reduced those to a single 32 bit hash.

Without further introduction, the trick is trivial once you learn it – all the operations are first-class functions under Operators. So instead of writing

a + b

you can write

Operators.(+) a b

This works for all the other operators too – now we can use these operators in pipelined operations just like any other function, so

(a + b) * c

becomes:

a + b
|> Operators.(*) c

That’s all there is to it!