Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 如何给lambda中的算子赋予下验性?_Haskell_Syntax_Lambda_Infix Notation_Infix Operator - Fatal编程技术网

Haskell 如何给lambda中的算子赋予下验性?

Haskell 如何给lambda中的算子赋予下验性?,haskell,syntax,lambda,infix-notation,infix-operator,Haskell,Syntax,Lambda,Infix Notation,Infix Operator,例如,这不会进行类型检查 \cons nil -> 5 `cons` 3 `cons` nil 这也不是 \(#) -> 5 # 3 # nil 虽然这两个都有 \cons nil -> 5 `cons` nil \(#) nil -> 5 # nil 是否有一种方法可以将infixites分配给lambdas中的运算符。我试过了 infixr 5 # foo = \(#) nil -> 5 # 3 # nil 它给出了一个错误,没有定义#和 foo = \

例如,这不会进行类型检查

\cons nil -> 5 `cons` 3 `cons` nil
这也不是

\(#) -> 5 # 3 # nil
虽然这两个都有

\cons nil -> 5 `cons` nil
\(#) nil -> 5 # nil
是否有一种方法可以将infixites分配给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 #


等等。

真不错!这是Haskell 98、Haskell 2010还是GHC的一部分?我特别喜欢let版本。它是Haskell 98。let和where的语法涉及“decls”,其中包括类型签名、固定性声明以及函数和模式绑定。请不要编写
let
版本
foo = \cons nil -> let (#) = cons; infixr 5 # in 'a' # 'b' # nil