draw_line :: CGFloat -> CGFloat -> CGFloat -> CGFloat -> IO () draw_line x y x' y' = do c <- _UIGraphicsGetCurrentContext _CGContextBeginPath c _CGContextMoveToPoint c x y _CGContextAddLineToPoint c x' y' _CGContextStrokePath c
, the Haskell one isn't terribly different from the original Objective-C code. By building FFI agains the iPhone SDK, Objective-C code can be kept both minimal and functional.
I really began to feel that Cocoa is indeed very nicely designed, and those design patterns for Objective-C are just about right for building GUI.
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
I've decided that the next project will be a music composition software targeting the iPhone platform.
If I fail eventually, I shall fail while doing what I still like.
Anyway, because the GHC-iphone port is so advance ( there are even hand written assembly code for the linker), there's no hope for me to take it over if it no longer works with future iPhone OS. But since GHC will have an LLVM backend, hopefully I can at least still call into haskell by using that.
I've been wanting to do this for a long time, and this will be my most complex project.