Re:OCamlScript – a JavaScript back end for OCaml
by cannam on Friday January 08, 2016 @04:28AM
(#10863825)
In the (nice) immutable map example on that page, a reference cell is used & updated each time something is added to the map. How would the JS output differ if you built the map using a fold or similar, without any refs?
Re:OCamlScript – a JavaScript back end for OCaml
by jordwalke on Friday January 08, 2016 @05:27AM
(#10864003)
Before that, I'd ask if the implementation of OCaml's map is at all similar to the implementation of Immutable.js's Map. Different internal data structures/algorithms are probably the most likely explanation for any difference. Still, it's nice to see a benchmark that shows how OCaml compiled to JS is competitive in performance, even when compared to a very popular library that is known for performing well.
Re:OCamlScript – a JavaScript back end for OCaml
by cannam on Friday January 08, 2016 @06:35AM
(#10864181)
Also a fair point, and I take your implication that the effect of a change to the outer loop syntax would probably be lost in the noise. It just struck me that using ref cells and loops feels like a concession to writing Javascript-style code in the first place (I grant in this particular case it makes the code more obvious) and I wondered how much difference it actually makes. Is the compiler able to flatten a fold into a similar loop? Or do you get a readable fold call in the JS code and, if so, is it much slower? Or neither?
Re:OCamlScript – a JavaScript back end for OCaml
by hongboz on Friday January 08, 2016 @01:48PM
(#10867187)
List.fold_left is compiled into a while loop in ocamlscript. The main reason that I used for loop is that the generated code is the same as hand written js, so the comparison is more reasonable
Edit: I am a practical programmer, I am in favor of both for loop and recursion as long as it is readable
Re:OCamlScript – a JavaScript back end for OCaml
by Drup on Thursday January 07, 2016 @07:08PM
(#10861879)
That is how you justify the project, and it makes sense, when you look at it with a microscope.
But my remark still stand: we now have two compilers to js, their API/FFI is not the same, so you can't factorize work, and the integration work could be made on js_of_ocaml too (see alain frisch's project).
Re:OCamlScript – a JavaScript back end for OCaml
by jordwalke on Thursday January 07, 2016 @07:26PM
(#10861975)
Hi Drup,
I'd be curious to hear about the work that Alain is doing. Do you have a link?
Re:OCamlScript – a JavaScript back end for OCaml
by Drup on Thursday January 07, 2016 @07:33PM
(#10862018)
There you go : https://github.com/LexiFi/gen_js_api
Re:OCamlScript – a JavaScript back end for OCaml
by hongboz on Thursday January 07, 2016 @08:21PM
(#10862249)
actually we have great relationship with Lexifi, and we did exchange some ideas about ocamlscript before, I think mostly we are on the same page, there is enough room for two compilers :-)
Re:OCamlScript – a JavaScript back end for OCaml
by truncate on Thursday January 07, 2016 @10:14PM
(#10862691)
Its good to see ocaml->js back to life. Have you considered supporting TCO or arbitrarily deep stack? I'm just curious how often could we reuse ocaml libraries with just tail call to loop conversion.
Design goals here: http://bloomberg.github.io/ocamlscript/