Skip to content

GHCJS: Bringing Haskell to the Browser

Photo of Gershom B
Hosted By
Gershom B.
GHCJS: Bringing Haskell to the Browser

Details

GHCJS: Bringing Haskell to the Browser
Luite Stegeman

GHCJS is a Haskell to JavaScript compiler based on GHC. Its concurrent runtime system supports lightweight threads, (asynchronous) exceptions, lazy and asynchronous IO, synchronisation primitives like MVar, and software transactional memory. A non-concurrent runtime is also available for situations where code size is of particular importance. In addition to the existing foreign function interface, GHCJS has a convenient "foreign import javascript'' calling convention, allowing users to write inline JavaScript in their Haskell program.

The compiler integrates well in the Haskell ecosystem: GHCJS implements all modern GHC extensions, including Template Haskell. Cabal supports GHCJS as a compiler flavour, and most packages on hackage can be compiled and used directly without changes. Packages with foreign dependencies can be used when a JavaScript implementation is available for the imported foreign functions.

In this talk we will see the stages and transformations in the GHCJS compilation pipeline, and discuss the design choices for translating various Haskell features to JavaScript. The second half will be more practical, with examples of interacting with (asynchronous) JavaScript code through the foreign function interface, handling browser events and doing smooth animation. If time permits, we will also briefly look at debugging the compiled code.

Luite Stegeman has studied computer science at Utrecht University where he learned Haskell, and is the principal author of GHCJS. He currently works as a freelance programmer in the Netherlands, and is interested in combinatorics, numerical optimisation and simulation, and in bringing better tools for education and data visualisation to the web with Haskell.

Photo of New York Haskell Users Group group
New York Haskell Users Group
See more events
AOL Patch Labs
675 Avenue of the Americas, Floor 3 · New York, NY