FFI to SDK

Comparing

1
2
3
4
5
6
7
8
void drawLine(CGFloat x0, CGFloat y0, CGFloat x1, CGFloat y1)
{
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextBeginPath(c);
CGContextMoveToPoint(c, x0, y0);
CGContextAddLineToPoint(c, x1, y1);
CGContextStrokePath(c);
}

to

1
2
3
4
5
6
7
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.

blog comments powered by Disqus