gpt4 book ai didi

function - 在 f# 中定义函数

转载 作者:行者123 更新时间:2023-12-03 13:24:57 25 4
gpt4 key购买 nike

在 F# 中我可以定义这样的函数

let (-+->) x y = x + y

然后像这样调用

let z =  5 -+-> 6

我什至可以做这样的事情

let (-++->) x y z = x y z
let p = ((fun x -> fun y -> x + y) -++-> 5 ) 6

但是为什么我不能这样做呢?

let (nafis) x y = x + y
let p = 5 nafis 6

它给了我这个错误绑定(bind)中的意外标识符。应为“=”或其他标记

let (-+->) x y = x + y 这样的函数是任何特殊类型的函数吗?

最佳答案

F# 规范中定义了运算符的词法约束:

3.7 符号运算符

User-defined and library-defined symbolic operators are sequences of characters as shown below, except where the sequence of characters is a symbolic keyword(§3.6).

regexp first-op-char= !%&*+-./<=>@^|~
regexp op-char= first-op-char | ?
token quote-op-left =
| <@ <@@
token quote-op-right =
| @> @@>
token symbolic-op=
| ?
| ?<-
| first-op-charop-char*
| quote-op-left
| quote-op-right

如您所见,-++-> 有效,而 nafis 无效。

关于function - 在 f# 中定义函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57413593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com