valderman / haste-compiler

A GHC-based Haskell to JavaScript compiler
http://haste-lang.org
BSD 3-Clause "New" or "Revised" License
1.45k stars 109 forks source link

GHCJS-style imports for asynchronous functions #199

Open ion1 opened 10 years ago

ion1 commented 10 years ago

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.

valderman commented 10 years ago

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.