I've been tinkering with the F# Interactive.
I keep getting weird results, but here's one I can't explain:
The following code returns 66, which is the value I expect.
> let f x = 2*x*x-5*x+3;;
> f 7;;
The following code throws a syntax error:
> let f x = 2*x*x - 5*x +3;;
stdin(33,21): error FS0003: This value is not a function and cannot be applied
As you can see, the only difference is that there are some spaces between the symbols in the second example.
Why does the first code example work while the second one results in a syntax error?
The problem here is the use of +3
. When dealing with a +/-
prefix on a number expression white space is significant
x+3
: x plus 3x +3
: syntax error: x followed by the positive value 3I've run into this several times myself (most often with -
). It's a bit frustrating at first but eventually you learn to spot it.
It's not a feature without meaning though. It's necessary to allow application of negative values to functions
myFunc x -3
: call function myFunc with parameters x
and -3
The error message says that you are trying to call a function x
with the argument +3
( unary + on 3) and since x is not a function, hence the This value is not a function and cannot be applied
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With