Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a C# overloaded method with out parameters from F#

Tags:

f#

I have the following F# code to handle a Gtk.TreeView event:

  tree.CursorChanged.Add(fun (e : EventArgs) -> 
      let selection = tree.Selection
      let mutable iter = new TreeIter ()
      if selection.GetSelected(&iter) then
        Console.WriteLine("Path of selected row = {0}", model.GetPath(iter))
      )

selection.GetSelected has two overloads, with signatures

bool GetSelected(out TreeIter, out ITreeModel)

and

bool GetSelected(out TreeIter)

which is preventing me from using the tuple-returning version as described in this post:

let selection = tree.Selection
match selection.GetSelected() with
| true, iter -> // success
| _ -> // failure

Is there any way to specify which GetSelected overload I want with the latter syntax?

Edit: To clarify the question, I know what method signature I want; I just don't know how to specify it. For instance, I tried this, which didn't work:

let f : (byref<TreeIter> -> bool) = selection.GetSelected
match f() with
| true, iter -> // success
| _ -> // failure
like image 450
Martin DeMello Avatar asked Jun 02 '16 01:06

Martin DeMello


People also ask

What is calling function in C?

When a program calls a function, the program control is transferred to the called function. A called function performs a defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns the program control back to the main program.

How do you call C in C++?

Just declare the C function extern "C" (in your C++ code) and call it (from your C or C++ code). For example: // C++ code. extern "C" void f(int); // one way.

What is C function in Python?

The C function always has two arguments, conventionally named self and args. The self argument points to the module object for module-level functions; for a method it would point to the object instance. The args argument will be a pointer to a Python tuple object containing the arguments.


1 Answers

I think

match selection.GetSelected() : bool*_ with
...

should work.

like image 131
kvb Avatar answered Oct 04 '22 00:10

kvb