Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.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
F# 在F中创建否定谓词#_F# - Fatal编程技术网

F# 在F中创建否定谓词#

F# 在F中创建否定谓词#,f#,F#,例如,我在F#中有一个谓词 let myFunc x y = x < y 但是通过使用原始的myFunc let otherFunc = !myFunc // not valid F#中的否定是通过函数not完成的。运算符用于取消引用ref单元格 let otherFunc x y = not (myFunc x y) 你要做的就是所谓的“函数合成”。检查f#的函数复合运算符: 我没有可用的编译器进行实验,但您可以从 let otherFunc = myFunc >&

例如,我在F#中有一个谓词

let myFunc x y = x < y
但是通过使用原始的myFunc

let otherFunc = !myFunc  // not valid 
F#中的否定是通过函数
not
完成的。
运算符用于取消引用
ref
单元格

let otherFunc x y = not (myFunc x y)

你要做的就是所谓的“函数合成”。检查f#的函数复合运算符:

我没有可用的编译器进行实验,但您可以从

let otherFunc = myFunc >> not
努力克服错误

EDIT:Max Malook指出,这对当前的
myFunc
定义不起作用,因为它需要两个参数(从某种意义上说,这是函数land)。因此,为了实现这一点,
myFunc
需要更改为接受元组:

let myFunc (a, b) = a > b
let otherFunc = myFunc >> not
let what = otherFunc (3, 4)

只有当您提供第一个参数时,它才会起作用。让otherFunc x=myFunc x>>not@MaxMalook这取决于函数的类型和上下文。如果可以推断出最终的类型(在实际用例中经常是这样),那么组合是有效的。为了简洁起见,我更喜欢函数组合,因为需要注意附加的命名值。为了完整性和可能的娱乐性(如果不清楚的话),也可以编写
let myFunc (a, b) = a > b
let otherFunc = myFunc >> not
let what = otherFunc (3, 4)