haste-compiler icon indicating copy to clipboard operation
haste-compiler copied to clipboard

GHCJS-style imports for asynchronous functions

Open ion1 opened this issue 10 years ago • 1 comments

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.

ion1 avatar Jun 24 '14 08:06 ion1

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.

valderman avatar Jul 04 '14 09:07 valderman