Ghc now runs in your browser – Show and Tell

✨ Check out this insightful post from Hacker News 📖

📂 Category:

✅ Here’s what you’ll learn:

ghc itself can now run purely client-side in the browser, here’s a haskell playground demo. terms and conditions apply, and i’ll write up more detailed explanation some time later, but i thought this is a cool thing to show off how far the ghc wasm backend has advanced :slight_smile:



73 Likes

This is very cool! I wonder how easy it would be to load some packages; cabal in the browser when? I’m also wondering how usable Agda in the browser would be.



3 Likes

I think I found a bug: ghc options persist even after I change them. Edit: this has been fixed!

Also -with-rtsopts=-s does not work, sadly. Edit: Ah, that’s because it is interpreted.



3 Likes

This is awesome!
Perfect for building a fully interactive Haskell online course! :star_struck:

Excellent work – the efforts to bring Haskell to WASM are a huge boon to our ecosystem and userbase!

Can’t run it on my tablet (wasm), curious: is this running the type checker or also code gen to wasm?



1 Like

It runs the code, but it seems like it uses the bytecode interpreter.



1 Like

What modifications were to GHC for it to be compiled to WASM?



1 Like

cabal won’t work in the browser due to lack of process support; but it’s possible to use wasm32-wasi-cabal to precompile some third party packages to wasm and make this playground support them as well.

you might be interested to check GitHub – agda-web/agda-wasm-dist: Distributions of Agda executable compiled into WebAssembly.; afaik they even compiled GitHub – agda/agda-language-server: Language Server for Agda to wasm, not sure how usable it is currently

thanks for the report! i pushed an update which should have fixed it.

that’s right; ghc in browser can’t invoke the c compiler and it can only interpret haskell modules via bytecode.



1 Like

thanks for the reports! a few seconds of freeze during start-time is expected, since it needs to download ~50M of a rootfs tarball and extract it, then link the ghc library and all its dependencies. as for safari, it’s strange since i i just landed a workaround for a webkit bug that breaks the wasm dynamic linker a few days ago, i’ll take a closer look later.

the ghc library already mostly works when compiled to wasm, and it can parse/typecheck/desugar stuff. the bottleneck is the linker/loader part, for it to be useful it needs to be able to dynamically load and execute haskell code. i landed a couple of ghc patches recently to push towards that direction, and the last one that gets us towards the haskell playground (not landed yet) is Draft: Support running GHC fully client-side in the browser (!15000) · Merge requests · Glasgow Haskell Compiler / GHC · GitLab



8 Likes

Which packages are installed by default?



2 Likes

now chrome will consume even more memory :stuck_out_tongue:

Awesome work!



2 Likes

the ghc library and its transitive dependencies.

⚡ Share your opinion below!

#️⃣ #Ghc #runs #browser #Show

🕒 Posted on 1762017322

By

Leave a Reply

Your email address will not be published. Required fields are marked *