特殊括号(| ... |)desugar是什么?

sha*_*ang 10 syntax haskell arrows

我已经阅读了箭头符号文档页面,但我并不完全清楚"7.10.3.定义自己的控制结构"中使用的"管道括号"是什么.

鉴于上述文件中的例子

proc x -> do
    y <- f -< x+1
    (|untilA (increment -< x+y) (within 0.5 -< x)|)
Run Code Online (Sandbox Code Playgroud)

没有使用箭头符号的等效代码是什么?

por*_*ges 14

所述(| ... |)支架(通常称为香蕉括号内)是用于施加操作上的命令,内部的功能PROC符号.它们用于消除从正常命令操作命令(称为"操作符")的函数的歧义.二进制中缀运算符是特殊的,所以你不需要写(| (&&&) x y |).

至于desugaring,它们是来自Arrows论文的 GHC版本的form关键字.

表格定义如下:

proc p - > form e c1 c2 ... cn

=

e(proc p - > c1)(proc p - > c2)...(proc p - > cn)

那么,proc x -> (|untilA (increment -< x+y) (within 0.5 -< x)|)会变成:

untilA (proc x -> increment -< x+y) (proc x -> within 0.5 -< x)
Run Code Online (Sandbox Code Playgroud)

如果你想完全去除它,那么没有箭头语法,它会变成:

untilA (arr (\x -> x+y) >>> increment) (arr (\x -> x) >>> within 0.5)
Run Code Online (Sandbox Code Playgroud)