8

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.

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
eonil
  • 83,476
  • 81
  • 317
  • 516
  • 1
    If you are looking for a scripting language you might want to consider lua. – Femi Jun 12 '11 at 05:59
  • Try [Hugs](http://www.haskell.org/hugs/). – n. m. could be an AI Jun 12 '11 at 06:10
  • @Femi I'm currently using Lua :) But I'm wishing to switch to Haskell. – eonil Jun 12 '11 at 06:30
  • Ah. Alright. Good luck. I'll follow this: will be interesting to see what you come up with. – Femi Jun 12 '11 at 06:36
  • @n.m Hugs looks abandoned. And I cannot bear the risk of choosing discontinued implementation :( As I know it's features integrated into GHCi. – eonil Jun 12 '11 at 06:47
  • I'd look around before saying it's abandoned... I think a lot of the Haskell libraries are written so that they work with ghc, hugs, nhc, etc. Besides, sometimes great tools live longer than their latest revision ... you wouldn't exactly say that `bash`, `ls`, and `awk` are abandoned, right? – gatoatigrado Jun 12 '11 at 07:35
  • 2
    If you need Haskell 98, Hugs is already an excellent, portable, lightweight, stable implementation and it doesn't matter if it continues to be updated or not. If you need cutting edge, then Hugs is obviously not it. – n. m. could be an AI Jun 12 '11 at 07:47
  • @gatoatigrado, @n.m Hmm. Your comments are very persuasive. If it's stable enough, it should be fine to use. I'll look into it. – eonil Jun 12 '11 at 13:14
  • @Eonil Please post back if you have any successes, thanks :) – gatoatigrado Jun 12 '11 at 21:34
  • GHC's LLVM back-end has great potential. Too bad it isn't quite mature enough. – Robert Hensing Jun 16 '11 at 21:31

1 Answers1

8

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
Raeez
  • 2,423
  • 15
  • 12