Is anyone using MicroHs?

Some of you might have heard the MicroHs; a small Haskell compiler.
I’m not getting much feedback on MicroHs, so I’m simply curious to hear if any of you have been using it, and if so, for what?

– Lennart

31 Likes

Hi Lennart, I haven’t had the chance to try it out myself, but I know of the TFP25 submission KappaMutor: A Compact Structured Combinator Processor for Haskell which uses MicroHs as a frontend.

IIRC they measure their own SKI backend against MicroHs’ one, and compare their runtime performance on the custom functional hardware they built :slight_smile:

4 Likes

Hello @augustss ,

I’ve been enjoying MicroHs for simple demos (for example this silly little game), but the lack of libs makes it difficult to build something more substantial, in particular to read system process output and do concurrency.

If I had more time, I’d like to contribute to its ecosystem, and make sure my code can run with mhs.

Thank you for making MicroHs, reading its code is very refreshing!
-Tristan

6 Likes

The number of Hackage libraries that compile is slowly increasing as I add extensions.

9 Likes

That’s great to hear! I guess Template Haskell is still out of the question, so perhaps it would be nice to have a list of wanted “micro-package” alternatives to popular ghc packages that the community could help with.

Maybe we could organize a micro hackaton during the ZuriHac?

6 Likes

For what it’s worth, I haven’t actually used MicroHs, but I think that it’s awesome and I would like to use it — specifically for compiling to Web Assembly.

I’m a big fan of using fewer extensions, and I think the set chosen by MicroHs is more than enough, it even includes GADTs!

If I had free time, I would like into compiling (select parts of) threepenny-gui to WebAssembly / JavaScript. Sadly, I currently don’t have much free time. :see_no_evil:

If you’re looking for ideas to implement — I think that using MicroHs as a Haskell library is also a good idea. This would be very handy for using Haskell as an embedded scripting language, or for writing interpreters that are not GHCi, e.g. iHaskell or hyper-haskell.

5 Likes

I agree, MicroHs is awesome! I think it would be interesting to make real user interface with it.

If I had free time, I’d look into adapting optparse-applicative and http-client to make micro command line interface.

1 Like

Hi Lennart,
I have been using MicroHs’s parser for about a month now. I forked the project and separated its prelude and parser in order to use them in my own Haskell typechecker. I plan to create a pull request to upstream the changes in the near future.
Thank you for the amazing project!

6 Likes

Hello! Thanks a million for publishing MicroHS! I’m using it partially for teaching purposes and partially as a base for experimenting with a different backend (more STG-ish).

As a base for random hacking on a haskell compiler it’s absolutely indispensable. (Other ones are, well, too big for that.)

5 Likes

Please explain why this is awesome.

Sure, here is why I’m excited about MicroHs:

As explained in https://discourse.haskell.org/t/haskell-tools-could-loose-some-weight , MicroHs is awesome because it lets you use Haskell with a lightweight compiler that is easier to adopt than GHC (e.g. you basically only need gcc and a few MB of disk space to set it up).

Then the compilation/evaluation model using combinator graph is fascinating, checkout https://www.youtube.com/watch?v=IIE7umTroBY , toward the end Lennart demonstrates how it specializes expressions.

The runtime and your application is compiled down to machine code using a C compiler, which can be used to target embedded environment like micro-controllers.

Lastly, I hope MicroHs won’t adopt complicated extension like TemplateHaskell, which I think is necessary to achieve Simple Haskell.

6 Likes

I’ll probably try out the wasm support at some point!

Unrelatedly, @simonmic has suggested an alternative implementation of Hell could be done via MicroHs, which would make it more portable to environments that GHC doesn’t compile to.

As it’s C, I could see the embedded scripting angle. E.g. into PostgreSQL (the Elm author is doing this in secret) or Emacs — it depends on whether it uses a lot of globals or signals in funky ways or whether it’s more careful. Lua and e.g. DuktapeJS are good citizens in someone else’s process. I didn’t study the source in detail, just watched the talk.

By the way, I love the project.

4 Likes

Now that you mention Emacs. In the past I’ve contributed to Yi which advertises itself as “The Haskell-Scriptable Editor”, but I found using GHC to configure a text editor to have way too much overhead. Perhaps MicroHs could be included in Yi to provide a much more Emacs-like experience.

I wonder if it would be possible to have some parts of a program be pre-compiled with GHC for the best performance and have plugins compiled by MicroHs for scripting.

6 Likes

The MicroHs runtime has some global variables, but I’m thinking of getting rid of them if it can be done without any performance penalty. It does not (currently) set up any kind of signal handlers. I’d say it would be a very good citizen as a library, except that it will allocate a good chunk of memory.

2 Likes

Just tried it because I love the project.

Seems to not support unicode identifiers so my code may need some edits

mhs: error: "src/Math/SpecialFunction.hs": line 25, col 6:
  found:    Unrecognized input: '\120584'
  expected: @ LIdent ( UQIdent [ literal ~ ! QSymOper ` | = , :: ∷ empty
tcdf 𝜈 x = 0.5 + x * gamma (0.5*(𝜈+1)) / (sqrt(pi*𝜈) * gamma(𝜈/2)) * hypergeomet
ric [0.5, 0.5*(𝜈+1)] [1.5] (-(x^(2::Int))/𝜈)

Unicode in the source code is not supported. The reason is in the name, “MicroHs”. :slightly_smiling_face:
The tables needed to support all the Data.Char operations are many times bigger than the entire compiler binary! So I don’t find making those tables part of the compiler binary acceptable. But the tables could be stored in files and be (lazily) loaded at runtime. It’s just one more thing that is not done yet.

7 Likes

The cosmopolitan libc project solved a similar problem for Python by applying clever encoding tricks to the unicode tables: Size Optimization Tricks, which might be something eventually worth doing.

4 Likes

While I’m not really using MicroHs for anything, I’m having lots of fun contributing to it! It’s really easy to get into and you can test changes relatively quickly (at least in comparison to GHC). There’s still lots of stuff to do (fixing bugs, implementing missing library functions, optimizing things, …). If you’re interested, I wrote a small contributing guide.

11 Likes

Unicode is coming. I managed to compress the 1.1M category table to 2.8k (RLE followed by LZ).

11 Likes

Thanks for the inspiration!

1 Like