liveBook · Manning

Transpilation

As explained in F# in Action: A Revised Edition of Get Programming with F#

Transpilation is source-to-source translation from one programming language into another, typically preserving a comparable level of abstraction.

Transpilation translates source code from one programming language into another while keeping the result at a comparable level of abstraction. JavaScript often serves as the target runtime for languages designed to run in web browsers, including TypeScript and CoffeeScript. This approach separates the language developers prefer from the JavaScript platform that executes the result. section 11.4.1

Fable applies the pattern to F#: it converts F# scripts into readable JavaScript and rewrites F# and .NET library functions into JavaScript equivalents. The generated code can then run through browser tooling, the Fable REPL, or NodeJS. section 11.4.2

A practical Fable workflow is:

  • Create a local .NET tool manifest with dotnet new tool-manifest. section 11.4.2
  • Install Fable with dotnet tool install Fable --version 3.7.22. section 11.4.2
  • Compile a script such as sample.fsx with dotnet fable sample.fsx to produce sample.fs.js. section 11.4.2
  • Use the Fable REPL for quick experiments, or combine generated JavaScript with WebPack or Parcel for an application build. section 11.4.2

A small F# program becomes JavaScript

The F# source defines two values, adds them, and prints the answer. Fable emits JavaScript that preserves the variable names and replaces printf with a library-backed console operation, producing the result 3. section 11.4.2

Figure 11.6 The Fable REPL in action. F# entered on the upper-left pane is converted into JS and then run. The output in the bottom-right pane shows any console output.

Run F# in the Fable REPL, inspect the emitted JavaScript, and observe console output in the same interface. section 11.4.2

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Demonstrates installation, compilation, generated output, library rewriting, and REPL execution, while deferring detailed JavaScript build tooling.
Examples
Uses an arithmetic F# script, emitted JavaScript, the Fable REPL, and a larger order domain as concrete artifacts.
What it assumes
Assumes familiarity with basic F# scripts and JavaScript execution while demonstrating the installation and compilation commands.
What you can do after
Apply it via Fable to compile F# scripts into JavaScript and test the result interactively or locally.
How it connects
Connects JavaScript, TypeScript, F#, .NET libraries, NodeJS, WebPack, Parcel, and REPL-based execution.

Also explained in

Compare how 4 books explain transpilation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.