GHCJS previously implemented a
GHCJS supported functions up to 3 arity, and it supported various synchronicities of callbacks. Arguments are passed as an untyped
To construct callbacks, the following functions are used depending on synchronisation and the existence (or lack thereof) of a return value:
data OnBlocked = ContinueAsync | ThrowWouldBlock asyncCallback1 :: (JSVal -> IO ()) -> IO (Callback (JSVal -> IO ())) syncCallback1 :: OnBlocked -> (JSVal -> IO ()) -> IO (Callback (JSVal -> IO ())) syncCallback1' :: (JSVal -> IO JSVal) -> IO (Callback (JSVal -> IO JSVal))
Only the 1-arity signatures are demonstrated here, but sizes up to 3 - including 0 - are available.
Callbacks as FFI "exports"
Callbacks enable a form of FFI "exports", through setting global variables:
Then, if our generated Haskell-main is called in the HTML head,
globalF will be available as a callback for e.g. HTML buttons.
GHCJS.Foreign.Callback module from the