F# functional programming comes to JavaScript
In a beta stage of development, Fable leverages F# and uses Babel compilers to generate source maps. A 1.0 release is due soon.
"Fable's goal is really simple: compile F# to JavaScript," said Angelo Garcia-Caro, lead developer on the project. "It's compatible with most of F# core library and some of .Net classes like Regex, DateTime, but doesn't try to provide you with a set of tools specifically for Web development." Developers can choose the appropriate tool for their use case, he said.
Fable, Garcia-Caro said, is an "obvious choice" for current or aspiring F# developers who want to take advantage of F# language and editor features when developing for the JavaScript platform. "With this, I mean not only Web apps, but also Node, mobile, or desktop, with GitHub Electron." JavaScript developers, meanwhile, get a chance to work with functional programming.
Working with such JavaScript libraries and tools as Webpack, Fable is available via NPM and requires installation of Node.js. It works directly with F# source code and does not require compilation to .Net bytecode. Garcia-Caro said that users should compile to standard and idiomatic code to make interaction with any JavaScript framework, library, or tool easy. This interaction can be done dynamically, but it's also possible to parse TypeScript definition files to get the benefits of static checking and intellisense. The community is working on thin layers to give access to popular JavaScript libraries, such as React, in a more idiomatic manner in F#.
A developer planning to use Fable lauded the union between F# and JavaScript. "When talking about programming languages, people often forget how important the ecosystem around the language is. But JavaScript is not just the language -- it comes with a set of modern Web development tools," said developer Tomas Petricek, who has contributed to previous F#-to-JavaScript compilers and is a partner at F# developer fsharpWorks. "With Fable, you can use F# and benefit from nice features of the language, but still compile your project with WebPack. And because Fable generates nice JavaScript with clean public API, you can package your libraries using NPM and use them from other languages in the JavaScript ecosystem."