Is there any way to compile Standard ML to JavaScript taking advantage of MLTon?

782 views Asked by At

The only way I could imagine would be using Emscripten, but MLTon has no LLVM backend. Is it possible somehow?

1

There are 1 answers

4
Andreas Rossberg On

I don't think it is, and as I've commented on your other question, I don't see much point in doing so. Many of the optimisations MLton performs are not that relevant on top of an aggressive jit compiler. On the other hand, you would need to compile not just the program, but also port the MLton runtime to JavaScript. In particular, this involves the memory management system. With the Emscripten route, you probably would need to run MLton's garbage collector nested inside JavaScript. That's usually a terrible idea. Especially if you also want to interact with the JS environment in interesting ways, because then you would have to marshall and finalise back-and-forth across the language boundaries, which tends to imply horrible performance and a high potential for space leaks.

For this use case, the direct SMLtoJS compiler is what you want (although the site seems down right now).