Is it possible to compile a Haskell module to JS using ghcjs
? I played with it, but it seems it requires main
function to be defined before it would generate JS. 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
. It will compile only .hi and .o files if main function is not defined. 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.
Fay
seems to be capable of doing it. I will like to investigate it for ghcjs
first.