Call for minimal HTML example #268
-
GHC now includes a Webassembly backend. GHCJS has also changed. Would anyone be able to put together an up-to-date example (ideally with a docker image so we can run it anywhere) that uses Yampa for a frontend web app? It can use HTML widgets or drawings, it doesn't matter. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 15 replies
-
Related issue #34 :) Would anyone like to volunteer to start working on this so we can tackle this for the next release? |
Beta Was this translation helpful? Give feedback.
-
Here is what I managed to get over the weekend: https://github.com/AntanasKal/yampa-wasm-example Here mouse position is collected on Javascript side, and there is Yampa signal function applied to it to get the position of rotating circle. Drawing is done on JS side using canvas (render function simply takes the position of the rotating circle). Drawing functions could also be called from Haskell, but for that some wrapper code would have to be written. In the example, the state management in Haskell and communications between Javascript and Haskell WASI reactor feels a bit hacky and I would like to think more carefully on how to structure that. But it seems that some hackiness and manual memory management might be unavoidable for more complex comms between JS and Wasm. A relevant Reddit thread . Also ghc-wasm-meta guide instructs to use manual memory management to send large data between JS and WASI reactor modules before GHC adds first-class JavaScript interop features. |
Beta Was this translation helpful? Give feedback.
-
Did not get much time to work on this the last few weeks, but I could return to this soon, hopefully will have some time this weekend. The current code has examples of:
If somebody would like to start working with Wasm and Haskell, they could already start with this example. There are some rough edges, but this might be the overall state of ecosystem around GHC Wasm backend. I could spend time cleaning up and documenting the code and also on:
Is there anything in particular that you would like to see before the next Yampa release? |
Beta Was this translation helpful? Give feedback.
-
I have added this Dockerfile to the repo as well. I will see if I get time to look into potentially porting one of the existing games to Wasm, it might be very tight to do it before a release. Most likely I will add at least a few wrapped JS functions for rendering (e. g. for rendering text), doing this today encountered some JS and Wasm issues, but there seems to exist workarounds (one issue I encountered is also discussed on stackoverflow: https://stackoverflow.com/a/76916494 ) . |
Beta Was this translation helpful? Give feedback.
-
Out of these proposals, I might be interested in porting Space Invaders game as it is the result of Yampa Arcade paper, which serves as one of the tutorials for Yampa. The code changes in rendering logic might be a bit invasive (as you might need to remove HGL dependency completely), but I think should be possible with conditional compilation to have code that compiles for both HGL and Wasm+JS+Canvas. I could start with a fork of Space Invaders repo. |
Beta Was this translation helpful? Give feedback.
Did not get much time to work on this the last few weeks, but I could return to this soon, hopefully will have some time this weekend. The current code has examples of:
If somebody would like to start working wi…