Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Haskell/ML-like compiler to C?

People have written games for the iPhone in Scheme. Because (some) Scheme-compilers compile down to C, it was easy to mix with Objective-C and integrate with XCode.

I am aware of patches for Haskell and OCaml compilers to enable ARM/iOS-backends. But those appear unofficial and experimental/unstable.

I prefer a static haskell/ML-type type-system over Scheme's dynamic typing. Is there a stable ML/SML/Haskell compiler which generates C-code so that it can be used in a similar way as Scheme/Gambit-C?

like image 239
LennyStackOverflow Avatar asked Jan 18 '11 09:01

LennyStackOverflow


People also ask

Does GHC compile to C?

Serveral years ago, GHC used to compile via C, but no longer does that in normal scenarios. Instead of generating C code and compiling that with gcc , nowadays GHC uses its own native code generator (or LLVM). Technically, it is possible to compile GHC itself as "unregisterised" to re-enable that option.

Why is OCaml a good compiler?

OCaml is a strongly-typed language (which means no core dumps and eliminates a large class of data corruption problems) which is statically typed (which means that OCaml detects type conflicts -- a large class of bugs -- at compile-time rather than at run-time, perhaps months after your application is in production) ...


1 Answers

I can't help with ML, but have you looked at JHC? JHC is a whole-program optimizing Haskell compiler that targets portable C, and iPhone support can be added by putting

[iphone]
cc=arm-apple-darwin-gcc
merge=le32

in ~/.jhc/targets.ini

More Haskell information is on the Haskell wiki and the JHC manual.

like image 193
John L Avatar answered Oct 21 '22 17:10

John L