haste-compiler
haste-compiler copied to clipboard
GHCJS-style imports for asynchronous functions
GHCJS supports
foreign import javascript safe "foo($1, $c);"
foo :: A -> IO B
where $c
stands for a continuation/callback function such that
do { b <- foo a; {-rest-} }
translates into an equivalent of
foo(a, function (b) { /*rest*/ });
instead of
var b = foo(a); /*rest*/
making asynchronous code more convenient to write. It would be nice if Haste had that.
Since Haste's IO monad is synchronous, this would be hard to support with the normal FFI. However, it would probably be quite possible to implement something like this for Haste.Foreign
. Will look into it.