有人可以解释如何将此 FSharpx stm 编写为管道吗?
stm {
let! allTops = readTVar tAllTops
let! thisPlayerTops = mapM removeOtherPlayersScores allTops
let! markedTops = mapM markAsNonEmpty thisPlayerTops
return
markedTops
|> Seq.filter fst
|> Seq.map snd
|> List.ofSeq
}
我正在考虑类似haskell的>>=管道。
谢谢!
更新:为了避免混淆,做一点澄清:
我在想应该能够根据 stm.Bind 和 stm.Return 在 F# 中定义 >>= 运算符。我迷路了,我试图自己做到这一点。
UPDATE2:在Thomas 的回答之后,我发布了我认为看起来还不错的更新版本。如果我理解正确,由于缺少类型类,运算符 >>= 没有与 Haskell 相同的功能。
我同意这对于 F# 来说不是惯用的,但它可能是一个很好的练习。
readTVar tAllTops
>>= mapM removeOtherPlayersScores
>>= mapM markAsNonEmpty
>>= stm.Return >> Seq.filter fst >> Seq.map snd >> List.ofSeq
|> atomically
谢谢!