Elixir_of_ocaml

Super that you are tackling this. Sad to see, that they kick out the fundament of your work out of the language.

I guess you have good reasons; why do you use something plugin based that Ocaml provides, instead of simply forking Fez, as an example?

You could save tons of time since this is pretty mature now and you could just adjust it so it works with the slightly changed syntax in Ocaml. :slight_smile:

1 Like

Of course it’s not a backend like ocamlopt, it’s a backend for the current js_of_ocaml.

js_of_ocaml itself currently is a backend of ocaml’s bytecode representation so it receives all the optimization from the mainstream ocaml compiler.

This is why the whole bucklescript/js_of_ocaml project started. The question usually comes to readable code vs low maintaince

Because working on the OCaml AST is super simple, and Fez is based on F#, which is lacking First Class Modules, which is the big big thing of OCaml.

And entirely lacking things like First Class Modules and Functors among a few other things. ^.^;

Yes, same thing. js_of_ocaml build from the bytecode layer, which is fantastic for writing out bytearrays of memory code, but pretty horrible for making anything even remotely readable (and sending to the BEAM would not work well for that low level code).

Eh it’s low maintenance this way while being readable, OCaml’s AST is super easy to work with, there is just soooo much of it. ^.^;

2 Likes

Which means you add support for these two features and you are done.
The alternative is starting from zero.

Anyway what happens, this implementation will always work, since OCaml wont change its syntax, while it apparently removes used APIs out of the dark.

It might be that working on the OCaml AST is super easy, adoption something that is nearly done and also not horrible to work with, might be more reasonable.

That is not a trivial feature, and certainly not one you can just add to F#. :wink:

Why? An OCaml compiler driver can still work.

1 Like

That’s why a modified lambda representation would be useful. The catch is that lambda doesn’t uncurry your functions, and because you don’t have access to the types anymore ir becomes harder to do it yourself…

2 Likes

I am not talking about adding it to F#.

You can use Fez to compile OCaml code, once you adjust it accordingly.

Sidenote: Functors are implemented in FSharpPlus for about a decade.

Functors != First Class Modules; First Class Modules make Functors significantly more powerful (this is the main difference between OCaml and SML, and is not a feature F# had at least as of a year ago) and First Class Modules work wonderfully well on the BEAM (unlike .NET).

1 Like

I think it’s pretty much decided that we should fork the OCaml compiler, Bucklescript-style. So I think you should do it, release something that works even if partially and then people like me an collaborate.

1 Like

I’m wondering if you can reuse Bucklescript’s codebase?

Bucklescript uses an old version of the OCaml compiler. @OvermindDL1 claims he can do it better with a newer version

Yeah that’s basically what a compiler driver is, just importing the compiler as a library and using its parts. ^.^;

BS actually fully forks though, it edits compiler-lib.

Eh, not really, javascript’isms are very different from BEAM’isms.

Oh definitely so!

1 Like

Didn’t you say this wasn’t possible anymore because the compiler has deprecated parts you’d like to use?

Oh no, that part is fine, what I was using was becoming a compiler plugin. A plugin loads me ‘into’ the stock compiler so I can output both elixir, and even generate native code too (like making a standalone beam ‘node’ for example later on would have been a long-term plan). A compiler driver loads the compiler library and does what it needs to manually, but it doesn’t work as a drop-in compiler replacement either, it’s a “new program”.

And can you do it as a compiler driver without forking?

1 Like

Yep, a compiler driver is just a standalone program that uses compiler-lib to call the compiler interfaces directly. Not too hard, just more API’s to learn that I’ve not touched yet.

Could you publish something then? Even if it’s your horrible single file so that I can take a look. I wouldn’t know how to start from scratch, but I can help you refactor your file, implement parts you haven’t implemented yet, etc.

2 Likes

It will basically need to be rewritten from scratch, a plugin is more concerned with transforming the AST, a compiler driver will instead consume the AST entirely, which will make some things easier for sure. ^.^

Yes. And as I said: This is completely unrelated.

Can you parse and transpile higher order modules without higher order modules?

If yes, then you have no reason to avoid Fez for that purpose.

Yes, but re-implementing that with all necessary type checking is not a small task, and something compiler-lib already has in OCaml, which saves a substantial amount of work be re-using code that is already very well tested, featureful, stable, and well written.

1 Like