gpt4 book ai didi

.net - 管道 pow 运算符问题

转载 作者:行者123 更新时间:2023-12-04 14:46:08 29 4
gpt4 key购买 nike

我想使用管道编写下一个函数:

A = 1/Sum[1-k](x^2)

所以当我写:
//Adaptive step
let a_Adaptive x =
x
|> Array.map (fun x -> x ** 2.0)
|> Array.sum
|> (**) -1.0

f# 解释 (**)作为多行注释,但我想将其用作函数。
有什么建议?

最佳答案

您只需要在 ** 之前添加一个空格:

let a_Adaptive x =
x
|> Array.map (fun x -> x ** 2.0)
|> Array.sum
|> ( ** ) -1.0

从 F# 规范:

To define other operators that begin with *, whitespace must follow the opening parenthesis; otherwise (* is interpreted as the start of a comment:

let ( *+* ) x y = (x + y)

关于.net - 管道 pow 运算符问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18946025/

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