Circuit a a mean-6ren">
gpt4 book ai didi

haskell - F# 中的箭头 "proc"符号

转载 作者:行者123 更新时间:2023-12-03 16:19:08 25 4
gpt4 key购买 nike

是否有 "proc" notation 的实现为 arrows在 F# 中?在 Haskell 中,它看起来像这样:

mean2 :: Fractional a => Circuit a a
mean2 = proc value -> do
t <- total -< value
n <- total -< 1
returnA -< t / n
请注意 proc关键字和 -<象征。
理想情况下,这可能会以某种方式使用计算表达式,但我也对其他方法持开放态度。

最佳答案

我还没有在 F# 中看到任何等效的符号。我认为原因是 F# 并没有试图变得纯粹,因此不存在 proc 的问题。和 -<正在解决。
等效的 F# 只是:

let mean2 input = 
let mutable total = 0.
let mutable count = 0.
seq {
for i in input do
total <- total + i
count <- count + 1.
yield total / count
}
也许我误解了 proc关键字提供了比这个简单示例更多的功能。

关于haskell - F# 中的箭头 "proc"符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67201613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com