<div dir="ltr"><div><div>I have been thinking about f# as well, but from a different direction. I would want to use as much as possible of the existing f# compiler which is written in f# so I would write an interpreter in Erlang for AST generated by f# parser which you could then use that to run all the early parts of the compiler, like type-checking and such. Then hopefully you could replace the backend with a new bit which generates core erlang and use the erlang compiler for the rest.<br><br></div>I fully realise it would not be as simple as it sounds :-) but I think it would be a doable of reusing as much as possible of what is written in f#. For me time is the limiting factor.<br><br></div>Robert<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 22 April 2017 at 21:52, Karl Nilsson <span dir="ltr"><<a href="mailto:kjnilsson@gmail.com" target="_blank">kjnilsson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks for the advice. A few things to think about there. <div>I have been writing things in erlang, compiling and comparing but rather than writing a language from scratch I am working from the AST (or rather the TAST) from another language, fsharp. As fsharp is an ML and core erlang is ML-ish I was hoping to avoid having to do too much mangling but flattening out applies and mod calls with let expressions is easy enough so I'll definitely do that. </div><div><br></div><div>Cheers</div><span class="HOEnZb"><font color="#888888"><div>Karl</div></font></span></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Sat, 22 Apr 2017 at 20:19 Robert Virding <<a href="mailto:rvirding@gmail.com" target="_blank">rvirding@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>I would try doing 2 things:<br><br></div>- Write the equivalent Erlang code which does what you want the code to do, compile it with the to_core0 option and see what it generates. This then becomes your target code. This is how I did it with LFE.<br><br></div>- Or you can try flattening out your code to remove the nested calls. While Core erlang in principle should be able to manage nested code the Erlang compiler generally flattens things.<br><br></div>What I found when doing LFE was that while the language *in principle* allows a lot of things *in practice* later passes in the compiler, for example the optimisation passes, assume that the code looks like what the Erlang compiler compiler generates. One example of this is how literal structures are represented.<br><br></div>to_core0 returns the Core erlang which has been generated by the erlang->core conversion pass which is then what is passed on to optimisation and and code generation. This is what you should be targeting.<br><br></div><div>To check what the actual Core erlang data structures look like, not the pretty printed code, in the shell try doing:<br><br></div><div>> c("foo", [binary,to_core0,return]).<br><br></div><div>This call will *return* the actual data structure so you can put it in variable then pretty print it to a file so you can what you really need to get. Note that some of the attributes are important in later passes.<br></div><div><br></div>What language are you working on?<br><br></div>Robert<br><br></div><div class="gmail_extra"><br><div class="gmail_quote"></div></div><div class="gmail_extra"><div class="gmail_quote">On 21 April 2017 at 19:12, Karl Nilsson <span dir="ltr"><<a href="mailto:kjnilsson@gmail.com" target="_blank">kjnilsson@gmail.com</a>></span> wrote:<br></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>Whilst trying to compile some code to core erlang I came across a problem when the target expression (e0 in spec) to apply was another apply expression. According to the spec I thought that would be ok however when compiling the .core file with erlc I got an "no_file: Warning: invalid function call" error.<div><br></div><div>What I then tried, not thinking it would work, was to wrap the inner apply expression in a let expression. This to my surprise worked just fine. I've included the code below. 'addSix` is the working function and `addSix2` is the dodgy one. Am I doing something wrong in `addSix2` to in terms of how I print my AST or is it simply that `addSix2` cannot be made to work? I also tried putting some parens around it but that also didn't work.</div><div><br></div><div><div>'add'/2 =</div><div>    fun (_a0,_b0) -></div><div>        call 'erlang':'+'(_a0,_b0)</div><div><br></div><div>'addFive'/0 =</div><div>    fun () -></div><div>        let <_a0> = 5</div><div>        in fun (_b0) -></div><div>    apply 'add'/2 (_a0,_b0)</div><div><br></div><div>'addSix'/1 =</div><div>    fun (_x0) -></div><div>        call 'erlang':'+'(let <_fez0> = apply 'addFive'/0 ()</div><div>in apply _fez0 (_x0),1)</div><div><br></div><div>'addSix2'/1 =</div><div>    fun (_x0) -></div><div>        call 'erlang':'+'(apply     apply 'addFive'/0 () (_x0),1)</div></div><div><br></div><div><br></div><div>Cheers</div></div></div><span class="m_-487855369415715785m_9176844545573453120HOEnZb"><font color="#888888"><div><div><div>Karl</div></div></div>
</font></span><br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>
</blockquote></div>
</div></div></blockquote></div><br></div>