[英]Compiling Haskell module to Javascript using ghcjs
Is it possible to compile a Haskell module to JS using ghcjs
? 是否可以使用
ghcjs
将Haskell模块编译为JS? I played with it, but it seems it requires main
function to be defined before it would generate JS. 我玩它,但它似乎需要在生成JS之前定义
main
函数。 A toy code below: 下面的玩具代码:
module Test where
add :: Int -> Int -> Int
add x y = x + y
I can't figure out how to compile it to JS using ghcjs
. 我无法弄清楚如何使用
ghcjs
将其编译为JS。 It will compile only .hi and .o files if main function is not defined. 如果未定义main函数,它将仅编译.hi和.o文件。 If I can figure out a way to compile it to JS (with appropriate
Z-encoded
function name, and a corresponding JS object, like what we have in FFI
for C), then I could use more powerful Haskell libraries like unordered-containers
and vector
to implement some algorithm, compile to JS, and use in Elm
through JS FFI. 如果我能想出一种方法将它编译成JS(具有适当的
Z-encoded
函数名称,以及相应的JS对象,就像我们在FFI
for C中所拥有的那样),那么我可以使用更强大的Haskell库,如unordered-containers
和vector
实现一些算法,编译成JS,并通过JS FFI在Elm
使用。
Fay
seems to be capable of doing it. Fay
似乎有能力做到这一点。 I will like to investigate it for ghcjs
first. 我想首先对
ghcjs
进行调查。
I just asked the ghcjs author (luite) in IRC, and he said, "there is no good way yet to directly export a library." 我刚刚在IRC询问了ghcjs作者(luite),他说,“还没有好办法直接导出一个库。”
He does seem very interested in supporting that capability, though, so I'm hoping, and optimistic that this will change in the near future. 不过,他似乎对支持这种能力非常感兴趣,所以我希望并乐观地认为这将在不久的将来发生变化。 The place to watch this issue is the ticket requesting this feature on github .
观看此问题的地方是在github上请求此功能的票证 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.