Ah I just realized, that would also be why, for member functions that take a bool argument, you have to put an extra set of parentheses when passing an equality expression directly in:

1
2
3
4
5
6
q(a = b);; //legal - passes the result of "a equals b" to q

t.q(a = b);; //illegal unless q has a parameter named a

t.q((a = b));; //legal - passes the result of "a equals b" to q

It's because regular functions can't have optional arguments, and thus the "a = b" expression can only be one thing: an equality operation.

By on 3/18/2009 10:54 PM ()

I've just noticed that you can pass a tuple into a member function using piping. Given the code from the first post, you can do:

1
2
v |> C.h;;

However, when I try adding optional parameters, I cannot set the value of the optional parameter in the tuple itself:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
> type D () =

    static member f (x, y, ?z) =

        let z = defaultArg z 5

        x + y + z

> (5, 6) |> D.f;;

val it : int = 16

> (5, 6, 7) |> D.f;;

  (5, 6, 7) |> D.f;;

  -------------^^^^

stdin(8,14): error FS0001: Type mismatch. Expecting a

	int * int * int

but given a

	int * int.

The tuples have differing lengths of 3 and 2.
By on 3/18/2009 11:19 PM ()

F# spec section 8.4.6 says:

Callers may specify values for optional arguments using the following techniques:
 By name, e.g. arg2=1
 By propagating an existing optional value by name, e.g. ?arg2=None or ?arg2=Some(3) or
?arg2=arg2.
 By using normal, unnamed arguments matched by position.

This fits in with how named arguments work and member calling in general with .NET. You can't pass in tuples to members when they are named or optional args, or something like that -- I haven't found the part in the spec that spells it out for me. Here's an example:

> System.String.CompareOrdinal("hi", "bye");;
val it : int = 6

> let x = ("hi", "bye");;
val x : string * string

> System.String.CompareOrdinal x;;
System.String.CompareOrdinal x;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
stdin(13,1): error FS0191: The member or object constructor 'CompareOrdinal' does not take 1 argument(s). An overload was found taking 2 arguments.

So, it appears you will need to _syntactically_ call the function. With your above code, this works fine:> D.f (1,2,3);;
val it : int = 6

I'd imagine that the new F# will clarify this a bit.

By on 3/18/2009 11:53 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