F# 语法错误
我遇到语法错误。 我想获取返回浮点数的函数的下限。
我认为这会给我正确的答案
let cyclesPerInterrupt bps bpw cpu factor =
floor (fudge (float(factor) cyclesPerWord cpu wordsPerSec bps bpw))
,但事实并非如此。 我已经尝试了我能想到的一切,但对我来说还是不行。 我知道这是愚蠢的事情,但我想不出来。
作为参考,fudge 采用浮点数和整数,cyclesPerWord 采用 2 个整数,wordsPerSec 采用 2 个整数。 Floor 采用泛型并返回浮点数。
I'm having a syntax error.
I want to take the floor of a function that returns a floating point number.
I thought this would give me the right answer
let cyclesPerInterrupt bps bpw cpu factor =
floor (fudge (float(factor) cyclesPerWord cpu wordsPerSec bps bpw))
But it doesn't. I've tried everything I can think of, and it's just not coming together for me. I know it's something stupid, but I can't think of it.
For reference, fudge takes a float and an integer, cyclesPerWord takes 2 integers and wordsPerSec takes 2 integers. Floor takes a generic and returns a float.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另请注意,您可以按照您最初尝试的方式使用括号来嵌套函数调用,例如
(如果没有上面的内部括号集,这有点像您试图将 4 个参数传递给 CyclesPerWord,这不是您想要的.)
Note also that you can use parens to nest the function calls the way you were originally trying to, e.g.
(Without the inner set of parens above, it's kinda like you're trying to pass 4 arguments to cyclesPerWord, which is not what you want.)
或者,为了避免盲目性和括号瘫痪,请使用一些管道 |> :
Alternatively, to avoid let blindness and parenthesis paralysis, use some pipelining |> :
查看您的函数定义,您似乎正在使用类似 C# 的语法来调用函数,函数名称位于 ( ) 之前,并且该函数的关联参数位于 ( ) 内。 一个例子是 FunctionName(Parameter1 Parameter2)。 F# 不使用这种风格。 相反,它使用函数名称和关联参数存在于 ( ) 内的样式。 例如 (FunctionName Parameter1 Parameter2)。
表达代码的正确方法是,
尽管最外面的 ( ) 并不是真正必要的。
Looking at your function definition, it seems like you are using a C# like syntax for calling your functions, the function name exists right before the ( ) and the associated parameters for that function are within the ( ). An example would be FunctionName(Parameter1 Parameter2). F# doesn't use that style. Instead it uses a style where the function name and associated parameters exist inside the ( ). An example of this would be (FunctionName Parameter1 Parameter2).
The correct way to express your code would be
though the outermost ( ) are not really necessary.