Does

type S = delegate of (int*int)->int

work for what you're doing?

By on 2/17/2009 8:49 PM ()

Thank you but this not work because i have to use this delegate to invoke a function of the type

let f x y = x+y

By on 2/18/2009 5:11 AM ()

Hmm. Using System.EventHandler (which seems like what you want, a delegate that takes 2 arguments) as an example, you can write the following code in C#.

1
2
3
4
5
6
void f(object arg1, System.EventArgs arg2) {}

void g()
{
    System.EventHandler handler = new System.EventHandler(f);
}

So if I understand correctly, you want something that behaves exactly like System.EventHandler but with different types for the arguments. Typing System.EventHandler into the F# window and looking at the type shows

1
    type EventHandler = delegate of obj*System.EventArgs -> unit

Indeed, the following works fine in F#

1
    let x = new System.EventHandler(fun x y -> ())

So it seems like making it a tuple should work? Although admittedly I haven't tried it with anything other than System.EventHandler

Edit: I Just tried it :P

1
2
type del3 = delegate of int*int*int -> int
let x = new del3(fun x y z -> x + y + z)

works fine. It seems to be picky about the parentheses though. If I do

1
type del3 = delegate of (int*int*int) -> int

Then I can only create the delegate by using a 3-element tuple as the argument. But without the parentheses, I can invoke it with a curried function just like you specified in the OP.

By on 2/18/2009 1: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