Functional javascript?

I’d like to use a “javascript derived language” in order to learn and use some of the usual web technologies today like node.js, jquery, etc.

After toying for a while with functional concepts and languages, mostly F#, I’m looking if there’s any similar thing in the Javascript world. So far what I’ve found and considered is:

  • derby.js vs capsule/thoonk?
  • Is it possible to mix TypeScript and CoffeeScript?
  • How to escape string interpolation in Coffeescript
  • Array .each() loop returning string instead of value in jQuery
  • How do I use CoffeeScript to mock out existing code?
  • How to convert a jQuery function with two function arguments into Coffeescript
    • Javascript the functional way: use javascript’s functional parts as extensively as I can, making use of Underscore or other functional libraries. The pros to this approach would be to learn the “mother language”. The cons for me are that I really don’t like its syntax and doesn’t feel very natural to program “functional first” in Javascript.
    • CoffeeScript + Underscore: I’ve seen some examples using CoffeScript + Underscore which seem appealing. For example: http://autotelicum.github.com/Smooth-CoffeeScript/SmoothCoffeeScript.html#toc-Chapter-7
      The pros to this would be that CoffeScript is spreading wildly and seems the defacto standard of languages designed for its use with a javascript VM. It syntax feels more natural to me and I could program some things the functional way in an easier manner.
      The cons would be getting far away from javascript itself (which really isn’t too much of a problem to me) and to be in middle ground of non truly functional.
    • Livescript: Derived from Coco (which itself was derived from CoffeScript), it has the more appealing syntax to me (it even has my beloved pipeline ‘|>’ operator from F#). The pros are that it is the most functional like approach. The cons would be that it isn’t very spread (I made a search in SO and there’s really NOTHING regarding it) and all that implies (not much community, support, tutorials, etc).

    After thinking for a while on all this, I have no real conclusión so it’d be great if people used to working with javascript, CoffeeScript, etc could guide me on the real importance of this concerns.

    Just in case… I haven’t really considered using Pit (and so continue using F#) because although it compiles to javascript, I think it doesn’t integrate with any javascript library like the above and doesn’t follow the same workflow or integrate with the javascript ecosystem as well as those options listed.

    Thanks a lot!

  • What are the best node packages to develop javascript browser apps?
  • indexedDB setVersion request being blocked?
  • Set up a coffee script unit test in JsTestDriver
  • Javascript “stuck” keys (unregistered keyup event)
  • How do I make node.js execute some code only if my file is the running file?
  • What's the easiest way to sync the state of backbone models across users? Node.js
  • 3 Solutions collect form web for “Functional javascript?”

    I’m probably a bit biased (I am the creator of LiveScript), but you should try LiveScript! I’m currently working on a standard library for it that will integrate better than underscore. As you say, there aren’t that many people using it yet, but a community has to start somewhere! As you’ve pointed out, it seems like the best option all other things being equal – so take a dive and try it!

    You basically have two options:

    • Use a JS-derived language like CoffeeScript
    • Use a functional language to JS compiler

    For option 1, well, it’s probably your best option for interoperability with other JS code. It’s also your best option if you actually want to work with other JS developers who may not be familiar with <insert functional language>.

    If you aren’t actually very familiar with JS, I would suggest option 1. It may be tricky to understand how things work especially if you run into bugs in the language/tool of your choice if you don’t understand the JS underpinnings.

    Option 2 can be more interesting to use as you would probably get the benefits of your favorite language into JS. In addition to the Pit project you mention, there are some attempts at making Haskell compile into JS which could also be an option.

    Option 2’s downsides are probably the fact the projects aren’t (afaik) very advanced to this day yet and that it may compile into not very efficient JS code.

    Lastly, there was some Haskell-style language which was based on JS, similar to CoffeeScript, but I seem to have forgotten its name. It might be worth a shot, if someone can figure out what it was called 😀

    And what about just a library of “”FUNCTIONAL”” functions , + coffeescript + underscore 😉 !

    http://osteele.com/sources/javascript/functional/