Parth Chitroda
Parth Chitroda

Reputation: 45

Unexpected infix operator in expression F#

I am trying to calculate the expression i and I can't figure out how to print the value as I'm new to f#.

let mutable sqSum = 0.0
    let mutable sqrRoot = 0.0 
    for i in [startNum..endNum] do
        for j in [i..(i+k-1)] do
            let x = j |> double
            sqSum <- x*x
        sqrRoot <- sqrt sqSum
         
        if <>sqrRoot % 1.0 > 0.0 then
            printfn "%i" i

Upvotes: 0

Views: 183

Answers (1)

user9631212
user9631212

Reputation:

The specific error message you are seeing should point to the exact location of the problem (at least for the compilers I use). So, specifically, it should be saying the infix operator located where "<>" is, is incorrect, which is true.

In many other languages, we use "!" to say the opposite of a boolean value. In F#, we may often use "<>" as a replacement for "not equal" or "!=". However, in your specific instance, we need to just simply use the keyword "not" and to surround the expression with parantheses (otherwise it will attempt to "not" a float value).

Specifically, you're code should look like this:

if not (sqrRoot % 1.0 > 0.0) then

As an additional note, you might want to fix your indentation as, like Python, indentation is very important in F# as it's not used for readability, but for specifying blocks of code. However, I cannot see all of your code, so it might be fine depending on how it is setup.

Upvotes: 3

Related Questions