开发者

Cross-Platform Functional Language for Objective-C

EDIT: After spending several hours researching this, I don't think I'm going to find anything that will actually end up saving me time compared to the amount of time and effort of finding suitable language, suitable bindings, and maintaining that environment in the face of change on all these platforms. I'm accepting the answer that seems most realistic because it would be the best idea for most people. The opinion I'm drawing from these conversations and others I'm having is that the only true way forward is to either use a Functional language that can operate without external bindings, or something that has bindings maintained by a commercial entity such as F#. It's too much work and too little demand and the state of what's available in the wild reflects that. I hope it changes one day.

I'd like to start using a functional language in my software, in addition to Objective-C which is my primary language (C may be workable as the binding?). Must be cross-platform, meaning Windows, Linux, OSX (x86), and iOS (ARM). What should I use and how can I achieve this?

I'm planning to switch to LLVM backend and Clang for my Objective-C soon, if this makes any difference.

I don't have any "knowledge investment" in any functional language, although I've screwed around with a few. I'm learning one from scratch so I want to learn something non-arcane if possible

  • The solution must be real, there's a lot of preliminary or prototype work done but..
  • I'm using objective C and I really do need Cocoa bindings; because a large amount of my data is using Cocoa types so things would be a mess otherwise. Also objective-c messaging would prevent me from needing to create glue code between static C functi开发者_如何转开发ons and my Objective-C object instances (which is already what objective-c method calls are doing built-in..)
  • The solution must be license-safe for statically linking (iOS requirement)

Here are examples of what I would like to do:

  • Process a language of bytes, for instance a network protocol
    • Input: bytes and length and 'calling' objective-c method instance
    • Output: return to calling objective-c method instance, send it cocoa-container arguments
  • Make decisions about the best "move" in a board game
    • Input: cocoa-contained state data, 'calling' objective-c method instance
    • Output: possibly alter state data, possibly call an arbitrary objective-c method, and then return to calling objective-c method instance, send it cocoa-container arguments


As Daniel Bünzli mentions, we have an OCaml iPhone app that's for sale right now in the iPhone app store. (It's a card game named Cassino, if you want to look for it.) Apple dropped their language restrictions in September 2010, and we encountered no resistance from them whatsoever (though of course we are a very small player).

I put together some tutorial examples for writing iOS apps in OCaml that you can find at our website:

http://psellos.com/ocaml/example-app-portland.html
http://psellos.com/ocaml/example-app-slide24.html

You don't mention whether you want GUI code to be cross platform. That's a much harder problem. Our code uses thin wrappers to access the native Cocoa Touch libraries, which aren't going to work on Linux or Windows. They do work (at least a subset) on OS X. You can see some custom (much simplified) Cocoa Touch wrappers in the tutorial examples.

OCaml certainly works well on all the systems you mention. It seems like a pretty good choice to me (a somewhat biased OCaml enthusiast).


OCaml is not GPL'd. The compiler itself is distributed under the Q Public License and the standard library is distributed under the LGPL with a static linking exception. See here for more details :

http://caml.inria.fr/ocaml/license.en.html

Some have already done apps in OCaml which are available on the app store, you don't need to pay 3000€. Follow these instructions :

http://web.yl.is.s.u-tokyo.ac.jp/~tosh/ocaml-on-iphone/index.html

http://psellos.com/ocaml/compile-to-iphone.html


I don't really know what a "Functional Language for Objective-C or C" means, but GHC (Haskell) is BSD licensed, and has a nice C FFI. There has also been a lot of work for GHC on iPhone.


Gambit or Chicken Scheme are probably your best bet — they compile to C.


Xamarin's support for F# is pretty good as of mid 2014.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜