The >>=
operator in Haskell is just a symbolic name for the bind operation, so you can define it in F# just as an alias for stm.Bind
:
let (>>=) v f = stm.Bind(v, f)
Using the operator, you could rewrite the code as follows:
readTVar tAllTops >>= fun allTops ->
removeOtherPlayersScores allTops >>= fun thisPlayerTops ->
mapM markAsNonEmpty thisPlayerTops >>= fun markedTops ->
markedTops
|> Seq.filter fst
|> Seq.map snd
|> List.ofSeq
|> stm.Return
This is certainly an interesting thing and a good way to learn about monads in F# (especially if you are coming from the Haskell background), but it is not an idiomatic style - the idiomatic style in F# is to use the computations explicitly.
One limitation of this approach (compared to Haskell) is that >>=
is not polymorphic over monads, so you're not gaining anything. Also, I think that there is a general consensus that using the computation blocks is more readable (for F# developers)