hs-cordova
hs-cordova copied to clipboard
Use Haskell (GHCJS) to develop Cordova mobile apps (note: has not been updated to modern GHCJS)
This is the basic Cordova example project (what you get after running cordova create),
rewritten in Haskell using GHCJS.
Things to note:
-
A hook is provided so running
cordova buildorcordova runautomatically configures & builds the Haskell project. -
You can't perform
document.addEventListener('deviceready', ...)directly from the Haskell code, so thehs-cordovalibrary includes extra JS code which installs the listener. The reason for this is because the GHCJS runtime executes the Haskell main function "in the background", so you can't rely on anything being done before the DOM/Cordova is done loading.
Also in development is a library of bindings to the Cordova plugin APIs. Completed functionality:
- Waiting for "deviceready"
org.apache.cordova.cameraorg.apache.cordova.deviceorg.apache.cordova.vibrationorg.apache.cordova.dialogsorg.apache.cordova.network-informationorg.apache.cordova.geolocationorg.apache.cordova.statusbarorg.apache.cordova.battery-statusorg.apache.cordova.device-orientationorg.apache.cordova.device-motionorg.apache.cordova.file(needs testing)org.apache.cordova.globalization
Tips for using the bindings:
-
Asynchronous JS functions simply return their value synchronously in Haskell.
-
Double-callback JS functions, where you supply "success" and "error" callbacks, return "Either error success" in Haskell.
-
Functions that install event handlers take the following form in Haskell:
arguments -> IO (IO ())The
IO ()you get back is the "deregister" function, which removes the event handler. -
JS enumeration-like values become real Haskell
Enumtypes. -
Options arguments passed to JS functions become Haskell records, with a
Data.Default.Defaultinstance. Use thedefvalue as an empty options object, or usedef { someField = ... }to just pass specific fields.