[Haskell-cafe] Tutorial on JS with Haskell: Fay or GHCJS?

Luite Stegeman stegeman at gmail.com
Wed Sep 4 20:18:27 CEST 2013


On Wed, Sep 4, 2013 at 6:32 PM, Daniil Frumin <difrumin at gmail.com> wrote:

>
>
> I think it's nice that you've raised that question, I will think about
> implementing a finer API for calling Haskell from JS.
>
>
It sounds like something like h$runSyncWithResult (name open for
bikeshedding) that takes an IO (JSRef a) and returns the result to the
caller, or null (exception?) when the synchronous thread terminated for
some reason, would fit the bill. I think this can be implemented in a few
lines of JS.

the current API is a bit bare-bones, based around calling main or a few
other top-level IO actions and doing the rest from Haskell code. The
Haskell code can make callbacks (JS functions that run Haskell when called,
see [1] ), but that can be a bit cumbersome to use when wrapping a library
with lots of external JavaScript.

If anyone has ideas of how they'd like a call-Haskell-functions-from-JS API
to look, I'd be happy to hear and see if we can make something nice.

One thing to keep in mind though is that type information has been erased
from the compiled code, making a generic applyHaskellFun(fun,x,y) that
would run 'fun x y' and return its result would be rather risky. That's why
the syncCallback/asyncCallback actions use JSRef, letting the Haskell side
do the conversion. Going through 'foreign export' could work though, or
perhaps there are other options that make this safer.

luite
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130904/db5ebd6f/attachment.htm>


More information about the Haskell-Cafe mailing list