4

I was wondering if it is possible to use the WebSharper compiler to write Node.js applications in F#. Are there any resources available that could show me how to do this? Are there any good reasons not to try to do this?

mushroom
  • 6,201
  • 5
  • 36
  • 63
  • 2
    I have one good reason not to do it - I don't know F#!! – raidenace Sep 28 '12 at 22:15
  • Completely cool idea! If you have a few spare hours, I suggest just trying - it should be possible. You might have to bind the core libraries of Node.js (and some other libraries you might need) - there are online resources. Please do blog about your success, and difficulties! – Ramon Snir Sep 28 '12 at 22:48
  • 1
    Personally I think its important to just use different languages for different jobs. – 7sharp9 Sep 28 '12 at 23:59
  • 2
    https://github.com/martydill/node.fs – supernova Sep 29 '12 at 01:23

1 Answers1

10

[I would post this as a comment, but it got a bit too long...]

Here is another good reason not to do it - F# agents and asynchronous workflows provide a concurrent programming model that is in many aspects much better than what Node.js provides. For example:

  • it gives you both concurrency and also true parallelism so you can write code that does not block the system when it needs to do some work using the CPU
  • asynchronous workflows provide easy way to handle exceptions and handle resources
    (you can use try .. with in asynchronous (or event-based) code)
  • the agent-based programming model gives you a great way to store state

If you can use F# to write your server-side application, then you can as well us the powerful abstractions it providers. See Server-Side Functional Programming for a brief introduction. I also did a talk F# on the server-side which has been recorded and discusses the same topic.

This is not necessarily a reason why not to try this. Trying this might be fun and if you like F# language, but want to use in Node.js environment, then it would be very useful to have this.

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553