I think the trick to understanding this is to appreciate that F# treats function application and method invocation as different operations and parses each situation slightly differently.

  1. f is a method. But (x.f) turns f applied on x into a closure (or a function value as opposed to a method). So the argument () can be applied like a function application.
  2. Here f is being invoked as a method. The syntax of method invocation is that the open parenthesis after method name is the start of an argument list (à la C#). So here () is interpreted as an empty argument list and not as the unit value. Of course the method f requires an argument so this is a type error.
  3. Same situation as 2. To pass the unit value as the first argument of a method you must use this syntax x.f(()). The first parenthesis opens the argument list and the second parenthesis is the unit value itself.
  4. As a variation of method invocation syntax, if the method has curried arguments then you can omit the argument list parentheses. So here the value is 8 is passed to the method.
  5. Same situation as 4, but here the value [] (i.e., the empty list) is passed to the method. The only reason why the unit value can't be used like this is because of the parsing ambiguity of open parenthesis being the start of this value and the start of an argument list.
  6. So this is an interesting one... The _ is a quotation expression hole. However I don't know what this means when it's not used inside a quotation.
By on 8/17/2008 2:33 AM ()

Thank you for the fine explanation. It's a good point you make that the ambiguity can be solved by x.f(()) .

By on 8/17/2008 2:10 PM ()

Just to mention that the F# CTP release will make a design cleanup here. Non-overloaded methods will be usable in the same way as functions. Thus all of the above will work as written.

Thanks

Don

By on 8/22/2008 10:34 PM ()
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