F# implementation