Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a fully functional paradigm language that transpiles to JavaScript?

Is there a language which transpiles to JavaScript (like TypeScript, CoffeScript etc.) and is almost purely functional (like Haskell, Erlang, F#)?

I know there are libraries which helps maintain immutability (Underscore), and there are a lot of cool array functions and lambdas in ES6. But what I'm looking for is a functional like syntax and transpiler for it, so I can write functional JavaScript with not much effort.

like image 689
godzsa Avatar asked Apr 25 '16 11:04

godzsa


3 Answers

Check out Scala.js, Elm or PureScript.

Other languages include ClojureScript (Clojure) and Funscript (F#)

Of those, I've only really used Scala.js and Elm, both of which work extremely well in my opinion.

Currying

In Elm and PureScript functions are curried by default. In Scala Currying can be done very easily by using multiple parameter lists:

def curried(param1: Int)(param2: Int): Int = ...
like image 185
Luka Jacobowitz Avatar answered Oct 13 '22 17:10

Luka Jacobowitz


If you like F# you might like OCaml via js_of_ocaml (better OCaml compatibility) or BuckleScript (better JS interop) or even Reason ML (more modern syntax, including JSX).

If you like Haskell better, you could use GHCJS (it's Haskell, targeting JS), Purescript (strict evaluation means simpler JS), or Elm (who needs type classes anyway).

I'm less sure about Erlang. There seem to have been some attempts (possibly somewhat successful) at targeting JS, but I'm not at all familiar with any of them.

like image 45
aij Avatar answered Oct 13 '22 15:10

aij


If you are looking to stay at the .NET platform, and would want to use F# as your language to transpile to JavaScript, then I recommend looking at the following:

1.) Fable - Fable brings together the power of the F# compiler and Babel to make JavaScript a true backend for F#. It works directly on F# source code, no compilation needed.

2.) WebSharper - A fundamentally different web framework for developing functional and reactive .NET applications

like image 45
123 456 789 0 Avatar answered Oct 13 '22 15:10

123 456 789 0