Skip to content

FinleyMcIlwaine/zurihac-2024-ghc-wasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GHC WebAssembly Backend Demonstration - ZuriHac 2024

At ZuriHac 2024, Jane Street was giving out shirts with the following prompt on the back:

shirt prompt

I was interested in doing something with GHC's WebAssembly (wasm) backend, so I decided to solve the problem above using a wasm-driven simulation in the browser.

Here it is in action:

demo gif

All of the logic for this simulation is written in Haskell and compiled to wasm, including:

  • Concurrent execution of each simulation
  • Mutex protecting the HTML canvas rendering context
  • Randomness using the random package

No libraries were used for interacting with the DOM, just raw JavaScript FFI through the wasm backend.

Build it and try it yourself

The ghc-wasm-meta README is a good resource for setting up a wasm cross compilation toolchain. The GHC team does supply official distributions of wasm cross compilers for Linux, but not other platforms (yet). On other platforms (e.g. macOS), you will need to build a cross compiler from source.

Once you have a toolchain set up, you can simply run the ./build.sh file in this repository and serve the dist directory on a local file server.

Credits: