-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A neat little function request #10
Comments
Thanks for the issue! Replied in tweag/ghc-wasm-miso-examples#17 (comment) regarding getting In general, the relatively heavyweight |
However, let's consider a case when you depend on a package which needs to run e.g. random number generation. I suspect there is no true randomness source on WASM, so I would like to use the one from javascript - There is JSDOM.Generated.Crypto module, however those functions run in JSM. Obviously I am not going to rewrite the whole package to entirely run in JSM monad. In order to easily modify the package, I would need something like:
I only see very impractical ways how to solve this, unless there is such function. Do you think it's feasible/possible to have such function? |
On WASI (https://wasi.dev/), which the GHC WASM backend uses, there actually is a true randomness source. That is e.g. what is powering this PR: haskellari/splitmix#73
What "whole package" are you referring to here? Generally, it is expected that your entire application should run in You can always resort to using the WASM JS FFI directly instead of JSaddle; these functions run directly in A related project would be to add native WASM support to ghcjs-dom. Currently, ghcjs-dom basically conditionally reexports one of:
It should be possible to write a ghcjs-dom-wasm package that uses the WASM JS FFI similarly (but not identically) to ghcjs-dom-jsffi/ghcjs-dom-javascript, where all functions are in I also mention this here:
|
The package I am referring to is 'entropy'. It is a dependency of another dependency. If I was to change a function in entropy to run in JSM (for the random number generation), I would have to turn all those which depend on it to JSM as well... that's what I mean by impractical. Looks like going either the "cbits" or "WASM JS FFI" way would be the cleanest/easiest to pull of. Thanks! |
Actually, entropy shouldn't need any changes apart from the E.g. building a simple executable depending on main = print =<< getEntropy 123 and running it via |
Yes I get exceptions - |
Ah right, that makes sense, as Using It should be possible to adapt this though by tweaking the |
Simple implementation based on source-repository-package
type: git
location: https://github.com/amesgen/entropy
tag: f771c8010f001b87c5ccf9b61703b6912f7062d5 This works fine both in the browser and via wasmtime for me. |
Hi,
same as there is
run :: JSM () -> IO ()
would you mind adding a function like
runWithResult :: JSM a -> IO a
I would like to use it to make entropy package compile for WASM by using javascript to generate random numbers.
The text was updated successfully, but these errors were encountered: