MicroHs is the browser is more fun now

I’ve updated MicroHs in the browser. New features:

  • You can import a local directory into the in-memory file system used by MicroHs. It will keep in sync with changes made to the local directory (with a small delay).
  • You can import an entire source tree from GitHub.
  • There’s a simple graphics package, CanvHs, inspired by Gloss and Shine.
    • There are some demos. You’ll be told on startup how to run them.
  • A few utlity functions: ls, cd, cat

Comments welcome!

A warning to those allergic to clanker code, a lot of the new code was written by Gemini.

30 Likes

I get no instance Num (IO ()) when I run the demo.

Which of the demos? I just ran the 3 first on my phone without problem.

Which browser?

1 Like

All 5 worked for me!

2 Likes

Never mind I’m stupid. I thought the example was literally demo1-demo5 instead of demos 1 through 5. Works!

2 Likes

Thanks @augustss, on my phone (Samsung) is the only place it’ll run for me.

  • On Wndows PC (Chrome) I get to Loading embedded package canvhs then it freezes.
  • On iPad (Chrome or Safari) I don’t even get as far as the Welcome ….

I can run ghc in the browser for all those environments.

Thanks for the bug report. I’ll try it more browsers&platforms. I was hoping those days were over, but I guess there are incompatibilities.

1 Like

Can you tell me more about the systems where it doesn’t work? I’ve tried on these, and they all work

  • Lenovo PC, Windows 11, Chrome 147.0.7727.102
  • Lenovo PC, Windows 11, Edge 147.0.3912.86
  • Mac Mini, MacOS 26.3.1, Chrome 147.0.7727.138
  • Mac Mini, MacOS 26.3.1, Safari 26.3.1
  • Mac Mini, MacOS 26.3.1, Opera 131.0.5877.24
  • Pixel 10 Pro, Android 16, Chrome 147.0.7727.138

What does the browser console say? Perhaps it’s running out of memory?

i took a look at devtools and uncompressed payload is less than 4mb, awesome work :+1:

one issue: the “select local workspace” button doesn’t work on firefox. the file system api doesn’t seem to be available in firefox/safari yet: Window: showDirectoryPicker() method - Web APIs | MDN

Out of curiosity, how does performance compare to native? Does the JIT have an effect?

Which JIT are talking about? The JIT from WASM to machine code? I’m sure that does a good job.

The general performance for MicroHs is similar to interpreted code in GHC (i.e., GHCi). But I’ve not done much comparison.

1 Like

The blob that the browser has to fetch is about 3M. This includes the entire base package and canvhs. And the compiler and RTS, of course. It’s bigger than I’d like, but it’s acceptable.

I’ll have to look into the directory picker.

1 Like

It all works wonderfully here, thanks a lot, it’s quite entertaining!

1 Like

demo5 looks like pong but I fail to understand how to play it. It keeps a score but I do not seem to be able to affect the outcome in any way.

You need to have the mouse pointer inside the animation area. Then you just move it up and down.

3 Likes

And now Pong has sound. :grinning_face:

2 Likes

Super!

Safari notes: the sound sometimes starts working after a half minute or so, and ctrl-C doesn’t work reliably.

Safari on what platform?

on latest macos, I think it’s 26.4.

And in safari on IOS: the page loads, the cursor
is flashing, but the panes and the select drop-down never populate with text (I waited a minute).

[And of course it worked on IOS when I tried one more time. At least, I could see the ball moving.(Small screen here.)]

(Sorry for the delay in replying.) Don’t worry about me and my cranky platforms. On the PC I have enough memory to run GHCi in the browser, or GHC .exe downloaded, or to build Hugs using Visual Studio. It’s Windows 8.1, so no hope of building MicroHS from source.

The browser is now getting the split screen edit pane. But still freezes loading canvhs. That’s with no other apps running than Chrome.

Merely, I’d hoped it might be more … micro. (How does GHCi manage to run in the browser?)