F # syntax error
I have a syntax error. I want to take a word of a function that returns a floating point number.
I thought this would give me the correct answer
let cyclesPerInterrupt bps bpw cpu factor =
floor (fudge (float(factor) cyclesPerWord cpu wordsPerSec bps bpw))
But this is not the case. I tried everything I could think of and it just wasn't going to work for me. I know this is something stupid, but I cannot think about it.
For reference, fudge accepts floats and integers, cyclesPerWord accepts 2 integers and PerSec accepts 2 integers. Paul takes a generic and returns a float.
source to share
Alternatively, to avoid blindness and brace paralysis, use some pipelining | >:
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
source to share
Looking at your function definition, it looks like you are using C # syntax to call your functions, the function name exists before () and the corresponding parameters for that function are within (). An example is FunctionName (Parameter1 Parameter2). F # does not use this style. Instead, it uses a style where the function name and associated parameters exist inside (). An example of this would be (FunctionName Parameter1 Parameter2).
The correct way to express the code would be
let cyclesPerInterrupt bps bpw cpu factor =
(floor (fudge (float factor) (cyclesPerWord cpu (wordsPerSec bps bpw) ) ) )
although external () are not needed.
source to share