F# Operator/Function Confusion
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 g开发者_C百科oing 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 +*
.
精彩评论