Mok*_*sha 6 haskell arrows frp netwire
我仍然试图弄清楚箭头表示法和Haskell中定义的箭头类型类的语义之间的相似之处.特别是,这个问题似乎有一个用箭头符号写的小计数器的非常规范的例子:
counter :: ArrowCircuit a => a Bool Int
counter = proc reset -> do
rec output <- returnA -< if reset then 0 else next
next <- delay 0 -< output+1
returnA -< output
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何在没有箭头符号的情况下将其转换回Haskell2010吗?
Pet*_*lák 11
{- |
+---------+
>Bool>--------------> |
| >------------------>Int>
+---------+ | arr f |
/----> delay 0 >---> >---------\
| +---------+ | | |
| +---------+ |
| |
\--------------------------------------/
-}
counter' :: ArrowCircuit a => a Bool Int
counter' = loop $ second (delay 0) >>> arr f
where
f (reset, next) = let output = if reset then 0 else next
next' = output + 1
in (output, next')
Run Code Online (Sandbox Code Playgroud)
递归rec部分使用loop.转换reset为output使用next(并产生新next值)的内部部分只是一个具有两个输入和两个输出的纯函数.