Compile

After following the excellent documentation by Stephen Blackheath, I was able to setup a new project with GHC support in no time.

The simplest iPhone program that compiles looks like this

main.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#import <UIKit/UIKit.h>

extern int Haskell_main(int argc, char* argv[]);

int main(int argc, char *argv[]) {
Haskell_main(argc, argv);
}

int kon(void) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(0, nil, nil, nil);
[pool release];
return retVal;
}

Main.hs

1
2
3
4
5
6
7
{-# LANGUAGE ForeignFunctionInterface #-}

import Foreign.C.Types

foreign import ccall safe "kon" kon :: IO CInt

main = kon

main.m calls into haskell's Main.hs, and haskell calls back via FFI a function that init the UiKit.

blog comments powered by Disqus