Hi,
you could store F# function objects in a C# list (an F# function is represented using the FastFunc type from FSharp.Core.dll). However, it would be probably easier to use standard C# delegates and only wrap functions written in F# inside the delegate. An F# function that wraps function inside a delegate could look like this:

1
2
3
4
5
6
7
8
9
 
#r "System.Core.dll" // needs .NET 3.5, because I'll use generic Func<> delegate
open System

let asDelegate (f : int -> int -> int) =
  new Func<int, int, int>(f)

module Export = 
  let addition = asDelegate (fun a b -> a + b)

This is probably the most convenient way. It may be a little bit slower than when using F# function values directly, but I don't think that would be significant.

By on 6/2/2009 7:02 AM ()

Thanks for the advice!

We thought about using the delegate approach, but we're trying to leverage as much of the existing C# as possible while being able to launch the steps in parallel on the F# side. The problem we had with the delegate approach is that since they are still F# functions that are being called from C#, we would have to do the parallelism on the C# side, which we are trying to avoid.

This is basically a pricing system. Each set of steps has to be run for a specific product. Each time we run this we could be running it for up to seven products. Since the step info for the products can run independently they are perfect candidates for parallel processing. Unfortunately, the existing algorithm in C# makes it hard to use the delegate approach. Our plan is to pass a list of products, the steps for the products, and the customer data to F# and let it do the "heavy lifting."

It's going to be a multi-year/multi-phase process, but the goal is to more pretty much the whole pricing system to F#. This is just the first step. :)

Thanks,

James

By on 6/2/2009 7:55 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