Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 functions 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
like image 338
Nektarios Avatar asked Dec 06 '22 23:12

Nektarios


1 Answers

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).

like image 123
Jeffrey Scofield Avatar answered Dec 15 '22 00:12

Jeffrey Scofield