In F#, infix operators (which include the logical operators, but also addition, subtraction, etc.) can be treated like normal functions if they are parenthesized. So 1 + 2 is the same as (+) 1 2, and therefore if you want to pass an operator to a function which expects a function argument, you must also wrap it in parentheses.

By on 6/1/2010 9:36 AM ()

Oh, thanks.

So in this example the call should be like pt (&&) not pt(&&) if i understood correctly because it's not like im calling pt() with &&, instead, i call pt with (&&).

Is there a way in F# to explicitly require x(arg) call instead of x arg? or accept both?

By on 6/1/2010 9:49 AM ()

In this case I don't think the space makes a difference.
In general, if you have a function of 1 arguments, using () or not is the same:

1
2
3
let f a = a*a
f 2
f(3)

This two functions, on the contrary are different:

1
2
3
4
5
6
let f  a  b  = a+b
let g (a, b) = a*b


f 2 3
g(2,3)

The first one takes 2 arguments, the second only one, typed as a tuple of two values.
The first notation allows partial application, the second doesn't.

HTH :)

By on 6/1/2010 11:02 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper