Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an F# portable library with HTML5/Javascript on Windows 8 and Windows Phone 8

sorry if this has already been answered but the other posts on this are out of date.

I want to build a Windows 8 app in HTML5 and JavaScript that uses an F# portable library project to do the computational heavy lifting. Is this allowed? When I tried to add a reference to my F# project from the JS project VS2012 gave me an error but then let me add it anyway, will this blow up in my face later? I also want to make a Windows Phone 8 version

Thanks

like image 477
Ed Ayers Avatar asked Feb 27 '13 16:02

Ed Ayers


2 Answers

As far as I know, the current F# compiler cannot create a WINMD component (mentioned by Denis) so you won't be able to call F# code directly from JavaScript. It might be possible (but I'm not sure!) to create an F# library as a portable library and reference it from a C# project compiled as WINMD component and then reference that from JavaScript. This adds an additional step, so it might be a bit inconvenient.

Please submit this as a feedback on the Visual Studio UserVoice. It is more likely to be added if more people vote clearly say that this is an important scenario for them!

Alternatively, as mentioned by Ramon, there are tools that translate F# to JavaScript and would allow you to run your F# code as JavaScript (and call it directly from JS):

  • WebSharper is a commercial, supported product with an open-source release under the AGPL license.
  • FunScript is a recent open-source community effort that is available under Apache 2.0

I only have experience with FunScript (which works pretty well and has some nice features), but WebSharper has been around for longer, so I suppose it is more solid. It also adds more sophisticated GUI framework based on formlets (and similar patterns) while FunScript simply provides type-safe access to JQuery via a type provider that imports TypeScript definitions.

like image 51
Tomas Petricek Avatar answered Oct 05 '22 10:10

Tomas Petricek


JavaScript metro apps can not call .net libraries directly. To make it possible for javascript to call your F# library you should turn it into windows runtime component (winmd). Now, I am not 100% sure if it is possible to make winmd using F#, since officially microsoft only supports c# and VB. On WP8 side javascript can not call .net or winmd libraries directly, so you would have to bridge js and .net manually.

like image 27
Denis Avatar answered Oct 05 '22 09:10

Denis