On Jun 7, 2017, at 1:24 PM, Karl Nilsson <
kjni...@gmail.com> wrote:
>
> The last couple of months I've been experimenting with a backend to the fsharp compiler that compiles down to the "core erlang" language and from there to beam byte code.
Why not translate IL to BEAM instead?
It’s probably initially a lot more work, but I suspect it’s one of those cliff-climbing sorts of problems, where once you climb the cliff, things become a lot easier.
If you compile the F# app statically, this may allow you to use a lot of existing .NET framework and C# code.
> [1]
https://github.com/kjnilsson/fez/blob/master/test/basics.fs
With all due respect to the work you’ve already done, that looks like low-hanging fruit to me: the parts of F# where the mapping to Erlang is mainly a matter of syntax differences, rather than semantic or behavioral differences.
Let’s talk about the hard bits now:
> [2]
https://github.com/kjnilsson/fez/blob/master/thoughts.md
Quoting that now…
> Mutation (<-) could possibly be supported using the process dictionary.
As I understand it, the way Elixir handles this is by creating a different immutable variable under the hood each time you modify the value. The later versions of that value are said to “shadow” the earlier ones, with only the most recently seen version accessible at any given time.
> High-level object programming could possibly be supported using processes and or behaviours.
Or, do it the way so many other OO features have been strapped onto procedural languages after the fact: methods are just freestanding functions that happen to accept a hidden “this” or “self” parameter as their first parameter, and the function implicitly dereferences the “this” reference on each member access.
That could be a reference to an Erlang record in this case.
(Examples are Perl, Lua, R, Tcl, Lisp, and C++’s ancestor C-with-Classes.)
> First cut - no objects.
One of the reasons I prefer F# over Erlang is that it’s a truly multi-paradigm language. One-size-fits-all is a fairy tale.
If the only purpose of this project is to provide yet another syntax sugar coating atop Erlang, that already exists. I think it would be better if this actually brought new functionality to the table.
Other hard bits:
1. How do you implement Erlang atoms in F#? Without atoms, how do you do traditional Erlang-style message passing?
2. Do modules work yet? If so, does that imply that you have automatic function arity detection and declaration? Do you obey visibility keywords? (public, private, etc.)
3. It’s been quite a while since I wrote any Erlang, but my recollection is that currying could only be done with hackery in Erlang. Do you translate F#’s automatic currying into Erlang somehow?
4. Do you have any hope of implementing units-of-measure?
5. Does you current translation method preserve the distinction among numeric types? That is, does the translation allow unwanted mixture of integer sizes or integer and FP, or is that taken care of by the F# compiler front end, so that the translated AST is always semantically correct in the F# sense?
That’s enough grief for now. :)