2
votes

I'm trying to wrap parts of the titanium api with PureScripts foreign function interface but I'm having trouble working out what the type definitions of the functions should be.

module Ti where

  foreign import data Window :: *

  foreign import window
    """ function (config) {
      return function () {
        return Ti.UI.createWindow(config);
      }
    } """ :: ??? -> Window

    foreign import open
    """ function (window) {
      return function () {
        window.open();
        return window;
      }
    } """ :: Window -> Window

    main = do
      w <- window ???
      open w
1
Not sure why you return a function of no arguments unless you expect to call import with config to create a function. Or is this supposed to be side-effecting?elclanrs
@elclanrs I wanted to return a function with a single argument, I just wasn't sure what the type of that argument should be. I will be experimenting with Phil Freemans' answer using pursescript-options.Jasper Lyons

1 Answers

2
votes

You might consider using the Foreign type from the purescript-foreign library as the argument type, together with the purescript-options library to construct the appropriate options object.

I've written a short guide to the purescript-options library here, and there is another example in the project repository.