In fact, it is not so easy even if i do use add_Stopped. I get:

function has to many args or is used where a function is not expected.

I have to do it like this:

data_provider.add_Stopped(fun _ -> meta_strategy.End())

Seems like it might be nice to have a bit more terseness for wiring up C# events and handlers in F#. I'd guess this must be a common scenario for other people trying to port or build on top of C#.

By on 2/24/2009 7:54 PM ()

Hi Bradford,
when using the "add_EventName" function, you need to create the delegate explicitly, so the following should do the trick:

1
2
 
data_provider.add_OnStuff(new StoppedDelegate(meta_strategy.End))

Handling of events & delegates in F# is a bit difficult, because the idea of delegates is a bit weird for F# - a delegate is almost like a function, so why should it have a different name all the time :-)? E.g. your "StoppedDelegate" looks like a function of type "unit -> unit". Currently, the compiler recognizes standard .NET patterns used when writing delegates & events and translates them into F#-friednly style (in particular, XyzEventHandler taking object and XyzEventArgs), but for non standard delegates & events (which aren't used that often), the compiler just exposes the underlying "add_Xyz" function.

You can of course write some wrappers or extension members to make this a bit nicer for the classes you need to work with.

T.

By on 2/25/2009 4:23 AM ()

I found there is no need to explicitly create the delegate if I eliminated the "StoppedDelegate" and replaced it with the standard "Action." Neverthless, I sill had to explicitly created the "fun _ -> meta_strategy.End()"

By on 2/25/2009 10:34 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