kejace / hs-cordova

Use Haskell (GHCJS) to develop Cordova mobile apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 build or cordova run automatically configures & builds the Haskell project.

  • You can't perform document.addEventListener('deviceready', ...) directly from the Haskell code, so the hs-cordova library 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:

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 Enum types.

  • Options arguments passed to JS functions become Haskell records, with a Data.Default.Default instance. Use the def value as an empty options object, or use def { someField = ... } to just pass specific fields.

About

Use Haskell (GHCJS) to develop Cordova mobile apps


Languages

Language:Haskell 59.9%Language:HTML 17.2%Language:JavaScript 16.9%Language:Ruby 3.4%Language:CSS 2.3%Language:Shell 0.2%Language:Makefile 0.1%