You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That generates a .js file that outputs [1, 1, 1, 1]. On the last lines of that file, there is:
$_0_runMain();
Which executes Main.main. That is pretty useless, though. Much more desirable would be to export a CommonJS library with the exported values. If we merely replace that line with:
module.exports={ones: Main__ones};
It works as expected and we can use lib.js from other Node.js modules:
Such feature could be useful for many reasons. For one, I could port eth-lib to Idris, compile it to JS and make thin wrappers to publish on npm, where people could use it from their JS codes. Of course, that would require settling a stable format for compiled ADTs. It currently uses: {"type": tag_of_the_constructor, "$1": first_field, "$1": second_field, ...}, which seems fine to me.
Note: it would also be desirable that, when generating a module, the BN.js dependency (which is inlined on Idris's output) would be just require("BN.js"), avoiding importing the same lib twice on JS bundles.
The text was updated successfully, but these errors were encountered:
@MaiaVictor I'm not an Idris contributor, but I have been playing around with the JS codegen since JS is my day job.
I think it would be good to pull request support for this feature. It could be the default behavior for the target node. My rationale is that:
Exposing the functions as named entrypoints to the JS module with CommonJS would make it automatically supported in most environments (certainly in Node)
It could work so that only the code in the "main" function gets built without a wrapper around it so that it gets immediately executed.
There is an --interface option in idris "--interface Generate interface files from ExportLists" I don't know what it is, but sounds what you need. It does not work on the js backend. I will try to figure it out and implement it.
The
--codegen node
option generates an executable Node.js program. Suppose, for example, that we try to compile the following Idris file:It doesn't work because of the following error:
Suppose, though, we modify the file to:
That generates a
.js
file that outputs[1, 1, 1, 1]
. On the last lines of that file, there is:Which executes
Main.main
. That is pretty useless, though. Much more desirable would be to export a CommonJS library with the exported values. If we merely replace that line with:It works as expected and we can use
lib.js
from otherNode.js
modules:Such feature could be useful for many reasons. For one, I could port eth-lib to Idris, compile it to JS and make thin wrappers to publish on
npm
, where people could use it from their JS codes. Of course, that would require settling a stable format for compiled ADTs. It currently uses:{"type": tag_of_the_constructor, "$1": first_field, "$1": second_field, ...}
, which seems fine to me.Note: it would also be desirable that, when generating a module, the
BN.js
dependency (which is inlined on Idris's output) would be justrequire("BN.js")
, avoiding importing the same lib twice on JS bundles.The text was updated successfully, but these errors were encountered: