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.

0


source to share


3 answers


Note also that you can use parens for the function call socket the way you tried, for example

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

      



(Without the inner set of partners above, it looks like you are trying to pass 4 arguments to PerWord loops, which is not what you want.)

+3


source


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

      

+3


source


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.

0


source







All Articles