【发布时间】:2020-11-11 09:53:51
【问题描述】:
使用 this 运算符评估管道中的副作用
let inline (|>!) a f = f a ; a
这个代码sn-p
if 1 = 1 then
"same"
else
"different"
|>! printfn "The numbers are %s."
|> printfn "Yes, they are %s."
这从不打印The numbers are same,但它确实打印Yes, they are same。
为什么这里忽略了副作用运算符|>!,但考虑了|>,尽管缩进相同?
我是否必须以不同的方式定义副作用运算符?
这样写它可以按预期工作。
if 1 = 1 then "same"
else "different"
|>! printfn "The numbers are %s."
|> printfn "Yes, they are %s."
代码实际上表现得好像写出来的那样对我来说只是不直观
if 1 = 1 then
"same"
else
"different"
|>! printfn "The numbers are %s." // with indent here
|> printfn "Yes, they are %s."
编辑:
另请参阅https://github.com/fsharp/fslang-suggestions/issues/806 以获得答案。
【问题讨论】:
标签: f#