I'm just getting started on F#, and when playing around with operator overloading, I've run into something I don't quite understand. Now, I understand that you can't use, for example, +*
as an overloaded prefix operator; it can only be an infix operator. Here's where I get confused, however:
let (+*) a = a + a * a;;
If I run this, fsi tells me that the function (+*)
is an int->int
. Great, I can dig that -- it's not an overloaded operator, just a normal function named (+*)
. So, if I do:
printf "%d" ((+*) 6)
I'll get 42, as I expect to. However, if I try:
printf "%d" (+*) 6
or
printf "%d" (+*)6
It won't compile. I can't put the exact error up right now as I don't have access to an F# compiler at this moment, but why is this? What's going on with the binding here?
It's interpreting this:
printf "%d" (+*) 6
Like this:
printf ("%d") (+*) (6)
In other words, passing three curried arguments to printf
, the second of which is a reference to the function +*
.
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