views:

89

answers:

1

I'm interested in using F# for numerical work, but my platforms are not windows based. Mono still has a significant performance penalty for programs that generate a significant amount of short-lived objects (as would be typical for functional languages).

Silverlight is available on OSX. I had seen some reference indicating that assemblies compiled in the usual way could not be referenced, but not clear on the details. I'm not interested in UIs, but wondering whether could use the VM bundled with silverlight effectively for execution?

I would want to be able to reference a large library of numerical models I already have in java (cross-compiled via IKVM to .NET assemblies) and a new codebase written in F#. My hope would be that the silverlight VM on OSX has good performance and can reference external assemblies and native libraries.

Is this doable?

+5  A: 

Technically speaking, Silverlight assemblies are similar as normal CLR assemblies, with the exception that they reference different version of runtime (and different version of system libraries such as mscorlib). Silverlight can run only Silverlight assemblies, so if you're compiling F# code you need to instruct the F# compiler to reference Silverlight (here are Visual Studio templates from Luke Hoban and here is a recent sample Silverlight app in F# by Brian McNamara).

Now, regarding the non-F# assemblies, I'm afraid this may be a problem. In principle you don't need to recompile them - there are tools to change the version (to turn CLR assembly into Silverlight assembly). See for example this article. In practice, Silverlight has many limitations (lots of methods missing, you are not allowed to do some Reflection tricks for security reasons etc.). So, I'm afraid that if you simply convert the assembly to Silverlight, it won't really work, but you may still try that... (but be careful - if a referenced method is missing, you won't find this out until Silverlight tries to call it at runtime).

Finally, there is also a problem with communicating with the application running in Silverlight as Silverlight apps have pretty limited capabilities. However, Silverlight 4 RC should allow you to read/write local files when running in the Out-of-browser mode (which may be good enough).

In summary I think that there are a lot of issues that may make it impossible to use Silverlight for this. I would maybe consider doing some more testing on Mono and sending feedback to them (if you find some case where the performance is clearly poor) - From my experience, they can be quite effective in responding to the feedback from users and I have the feeling that F# may be quite interesting thing for Mono team.

Tomas Petricek
Thanks for the insight.Regarding the mono option, there has been some work on performance with a LLVM mapping and now a new GC in testing. That said, I suspect the main problem is that the mono team is spread too thin and may have different priorities. I would prefer depth to breadth (depth being more focus on the VM and less around the API catch-up).
Jonathan Shore