例如,这不键入检查
\cons nil -> 5 `cons` 3 `cons` nil
这也不是
\(#) -> 5 # 3 # nil
虽然这两个都做
\cons nil -> 5 `cons` nil
\(#) nil -> 5 # nil
有没有办法将不定点分配给 lambdas 中的运算符。我试过了
infixr 5 #
foo = \(#) nil -> 5 # 3 # nil
这给出了没有定义
#
的错误和foo = \(infixr 5 #) nil -> 5 # 3 # nil
这只是一个语法错误。
我能做些什么?
最佳答案
固定性声明可以是本地的,但必须伴随定义,所以你必须编写类似的东西
foo cons nil = 'a' # 'b' # nil
where (#) = cons
infixr 5 #
或者
foo = \cons nil -> let (#) = cons; infixr 5 # in 'a' # 'b' # nil
等等
关于haskell - 如何为 lambda 中的运算符赋予不定性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34109113/