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#_Syntax Error_Function Calls - Fatal编程技术网

F#语法错误

F#语法错误,f#,syntax-error,function-calls,F#,Syntax Error,Function Calls,我有一个语法错误。 我想讨论一个返回浮点数的函数 我想这会给我一个正确的答案 let cyclesPerInterrupt bps bpw cpu factor = floor (fudge (float(factor) cyclesPerWord cpu wordsPerSec bps bpw)) 但事实并非如此。我已经尝试了我能想到的一切,但对我来说,这一切都没有实现。我知道这很愚蠢,但我想不起来 作为参考,福吉接受一个浮点和一个整数,CycleSPerford接受2个整数,words

我有一个语法错误。 我想讨论一个返回浮点数的函数

我想这会给我一个正确的答案

let cyclesPerInterrupt bps bpw cpu factor = 
 floor (fudge (float(factor) cyclesPerWord cpu wordsPerSec bps bpw))
但事实并非如此。我已经尝试了我能想到的一切,但对我来说,这一切都没有实现。我知道这很愚蠢,但我想不起来


作为参考,福吉接受一个浮点和一个整数,CycleSPerford接受2个整数,wordsPerSec接受2个整数。Floor接受一个泛型并返回一个浮点。

另外请注意,您可以使用paren来嵌套函数调用,就像您最初尝试的那样,例如

...(cyclesPerWord cpu (wordsPerSec bps bpw))

(如果没有上面的内部参数集,就有点像您试图将4个参数传递给CycleSPerford,这不是您想要的。)

还请注意,您可以使用参数来嵌套函数调用,就像您最初尝试的那样,例如

...(cyclesPerWord cpu (wordsPerSec bps bpw))

(如果没有上面的内部参数集,就有点像您试图将4个参数传递给cyclesPerWord,这不是您想要的。)

或者,为了避免盲目性和括号瘫痪,请使用一些管道:

let fudge (a : float) (b : int) =
    a

let cyclesPerWord (a : int) (b : int) =
    a

let wordsPerSec (a : int) (b : int) =
    a

let cyclesPerInterrupt bps bpw cpu factor =
    wordsPerSec bps bpw
    |> cyclesPerWord cpu
    |> fudge factor
    |> floor

或者,为了避免盲目性和括号瘫痪,使用一些管道|>:

let fudge (a : float) (b : int) =
    a

let cyclesPerWord (a : int) (b : int) =
    a

let wordsPerSec (a : int) (b : int) =
    a

let cyclesPerInterrupt bps bpw cpu factor =
    wordsPerSec bps bpw
    |> cyclesPerWord cpu
    |> fudge factor
    |> floor

查看函数定义,似乎您正在使用类似C#的语法来调用函数,函数名位于()之前,该函数的相关参数位于()中。例如FunctionName(参数1参数2)。F#不使用那种风格。相反,它使用一种样式,其中函数名和关联参数存在于()中。例如(FunctionName参数1参数2)

表达代码的正确方法是

  let cyclesPerInterrupt bps bpw cpu factor = 
    (floor (fudge (float factor) (cyclesPerWord cpu (wordsPerSec bps bpw) ) ) )

尽管最外面的()不是必需的。

查看函数定义,似乎您正在使用类似C的语法来调用函数,函数名就在()之前,该函数的相关参数在()中。例如FunctionName(参数1参数2)。F#不使用那种风格。相反,它使用一种样式,其中函数名和关联参数存在于()中。例如(FunctionName参数1参数2)

表达代码的正确方法是

  let cyclesPerInterrupt bps bpw cpu factor = 
    (floor (fudge (float factor) (cyclesPerWord cpu (wordsPerSec bps bpw) ) ) )

虽然最外面的()不是真的需要。

Aaah。我一直在想办法。我一直在想办法。