Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommendation to embed Haskell as script engine in iOS apps on ARM?

I tried to compiling Haskell into an iOS app a few months ago. Unfortunately the only stable/maintained implementation that I could find was GHC, so I tried some kind of cross-compilation, but failed because of absence of RTS for ARM/iOS.

I realized it's not easy enough for me. So I'm requesting some recommendations for this. I know there's a patch for iOS, but it's not continued anymore. I considered NHC/YHC, but I couldn't use dropped implementation. If I'm thinking wrong, please correct me.

like image 627
eonil Avatar asked Jun 12 '11 04:06

eonil


1 Answers

This is fairly easy using GHC-iPhone and the Foreign Function Interface

For reference, David Pollak has an example implementing a Lisp interpreter written in Haskell, running inside an iPad app:

https://github.com/dpp/LispHaskellIPad

An example declaring the Haskell main in main.m:

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

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

and in his Main.hs, a series of foreign function declarations granting him access to the Cocoa libs:

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

data ViewController_struct
type ViewController = Ptr ViewController_struct


type RunStr = ViewController -> CString -> IO ()
foreign import ccall safe "wrapper" wrapFuncInvoke :: RunStr -> IO (FunPtr RunStr)
foreign import ccall safe "setLispEval" setLispEval :: ViewController -> FunPtr RunStr -> IO ()

foreign import ccall safe "addToResult" addToResult :: ViewController -> CString -> IO ()

data ObjCId_struct
type ObjCId = Ptr ObjCId_struct

data ObjCSEL_struct
type ObjCSEL = Ptr ObjCSEL_struct

foreign import ccall safe "objc_msgSend" objc_msgSend :: ObjCId -> ObjCSEL -> IO ObjCId
foreign import ccall safe "objc_msgSend" objc_msgSendInt :: ObjCId -> ObjCSEL -> Int -> IO ObjCId
foreign import ccall safe "sel_registerName" sel_registerName :: CString -> IO ObjCSEL
foreign import ccall safe "objc_lookUpClass" objc_lookUpClass :: CString -> IO ObjCId
like image 180
Raeez Avatar answered Nov 20 '22 19:11

Raeez