This post is going to be very boring.
BTW, all the info is contained inside the sample projects in GHC-iPhone release, I'm just documenting it to remember it better.
There's no wrapper to use for the iPhone SDK, so the programer will essentially be building a subset of Objective-C wrapper in C and manually creating tunnels to call these C functions in Haskell.
The task can be broken down into 3 Big steps:
1. Create
- wrap an Objective-C method in C
- import the C function into Haskell through FFI
- create a function that utilize this imported function in Haskell
2. Export
- create an empty function pointer in C
- create a setter function to initialize this function pointer in C
- import the setter function into Haskell
- Use the setter to initialize a Haskell function
3. Use
- somewhere in Objective-C, call into Haskell through this initialized function
Step 2 contains some boilerplates: the function pointer and initializer, so I wrote
OMG
my first C Macro! ><
1 | |
So my first experiment allows Haskell to draw a line in the view, here's the relavent code:
ScoreView.m
1 | |
Main.hs
1 | |