Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Ocaml, Objective-c, and XCode
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Whitington  
View profile  
 More options Feb 11 2010, 6:16 am
Newsgroups: fa.caml
From: John Whitington <j...@coherentgraphics.co.uk>
Date: Thu, 11 Feb 2010 11:16:32 UTC
Local: Thurs, Feb 11 2010 6:16 am
Subject: Re: [Caml-list] Ocaml, Objective-c, and XCode
Hi Andrew,

On 11/02/2010 01:28, Andrew Webb wrote:

> Hi there,

> I have a few questions relating to using Ocaml with objective-c for anyone who programs on a Mac. I am aware that there aren't any real bindings between ocaml and objective-c/cocoa, so I am investigating rolling my own. So:

> 1) Does anyone have experience in interfacing ocaml and objc? Is it difficult?
> 2) Does anyone have a small example project that does mix these two languages? I have looked at unison, but it is too big for me to get my head around. I am thinking more on the scale of the ubiquitous Currency Converter...
> 3) Does anyone who is mixing these languages use Xcode to do so? If so, what steps do you need to go through to set that up?

> A big thanks to anyone who can answer (some of) these questions. I am trying to decide whether to use haskell or ocaml for my next cocoa application, as these are the two languages I am most comfortable. I have recently found an excellent description of how to do this using haskell (http://tscheff.blogspot.com/2010/02/currync-converter-using-haskell-w...) and was wondering if there were such resources for ocaml.

I've just released a product written in this way:

http://www.coherentpdf.com/proview.html

I just have a normal makefile which builds a .a library from the ocaml
code and its C wrapper as per the instructions in the ocaml manual.

The xcode project then uses the .a and the .h of the wrapper and a few
extra compilation and linking flags. Doubtless with a little bit more
effort, Xcode could be made to call the ocaml makefile.

Here's the OCaml makefile:

mklib:
         ocamlc cpdf.mli;
         ocamlopt -c -I . unix.cmxa str.cmxa bigarray.cmxa cgutil.cmxa
camlpdf.cmxa cpdf.ml;
         ocamlc cpdflib.mli;
         ocamlopt -c -I . unix.cmxa str.cmxa bigarray.cmxa cgutil.cmxa
camlpdf.cmxa cpdf.cmx cpdflib.ml;
         ocamlc cpdflibc.mli;
         ocamlopt -c -I . unix.cmxa str.cmxa bigarray.cmxa cgutil.cmxa
camlpdf.cmxa cpdf.cmx cpdflib.cmx cpdflibc.ml;
         ocamlc cpdflibwrapper.c;
         ocamlopt -output-obj -o cpdflibc.o unix.cmxa str.cmxa
bigarray.cmxa cgutil.cmxa camlpdf.cmxa cpdf.cmx cpdflib.cmx cpdflibc.cmx;
         cp /usr/local/lib/ocaml/libasmrun.a cpdflib.a;
         ar r cpdflib.a cpdflibc.o cpdflibwrapper.o

test:   zlibstubs.o cpdflib.a
         cc -m32 -c cpdflibc-test.c -o cpdflibc-test.o; \
         cc -m32 -L'/usr/local/lib/ocaml' -lunix -lbigarray -lstr -lz -o
test cpdflibc-test.o zlibstubs.o cpdflib.a

(The 'test' target shows you the kind of compiler and linker flags you'd
need to put into XCode).

Basically, once you've got the usual ocaml/c interface done, the Xcode
part is no problem.

Cheers,

--
John Whitington
Director, Coherent Graphics Ltd
http://www.coherentpdf.com/

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew  
View profile  
 More options Feb 11 2010, 7:18 pm
Newsgroups: fa.caml
From: Andrew <andrew.w...@gmail.com>
Date: Thu, 11 Feb 2010 16:18:16 -0800 (PST)
Local: Thurs, Feb 11 2010 7:18 pm
Subject: Re: Ocaml, Objective-c, and XCode
Hey,

Thanks for the information!

> I've just released a product written in this way:

> http://www.coherentpdf.com/proview.html

Indeed, and I posted a similar question on your blog at about the same
time as I posted this question. :-)

> I just have a normal makefile which builds a .a library from the ocaml
> code and its C wrapper as per the instructions in the ocaml manual.

> The xcode project then uses the .a and the .h of the wrapper and a few
> extra compilation and linking flags. Doubtless with a little bit more
> effort, Xcode could be made to call the ocaml makefile.

> Basically, once you've got the usual ocaml/c interface done, the Xcode
> part is no problem.

Thank you, that is all excellent information!

Ta,
Andrew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dynasti...@mac.com  
View profile  
 More options Feb 12 2010, 4:30 pm
Newsgroups: fa.caml
From: dynasti...@mac.com
Date: Fri, 12 Feb 2010 21:30:15 UTC
Local: Fri, Feb 12 2010 4:30 pm
Subject: [Caml-list] Re: Ocaml, Objective-c, and XCode

Andrew Webb <andrew.w...@gmail.com> writes:
> I have a few questions relating to using Ocaml with objective-c for
> anyone who programs on a Mac.

We've been working with OCaml/ObjC/Cocoa on the iPhone for a while.  We
also have a small subset working on the Mac and have built Mac apps with
it.

> I am aware that there aren't any real bindings between ocaml and
> objective-c/cocoa, so I am investigating rolling my own.

This is what we did.  There was some work on an OCaml/Cocoa bridge, but
it doesn't appear to be finished, and doesn't look like an active
project.  The home page is here:

    http://code.google.com/p/objective-c-caml-bridge

> 1) Does anyone have experience in interfacing ocaml and objc? Is it
> difficult?

The things that make it easier than it could be are:

(a) There is good documentation on interfacing OCaml and C, and ObjC is
    a clean superset of C.  So the language tools all work together
    quite well.

(b) The OO subsystem of OCaml is a pretty good match for the Cocoa
    design.  With some work, you can use OCaml objects to represent
    Cocoa objects, and vice versa.

The hard parts are:

(a) Cocoa is a very large system, too large for a small number of people
    to build an interface by hand.  A mechanical interface generator
    would be best, but is also a big project.

(b) There's a mismatch between the ObjC reference counting and OCaml GC.

For our work, we just add bits to our interface as we need them.  Memory
management issues are tricky but only need to be solved once in the
lowest layer.  We don't have any experience with the ObjC GC; this might
make things a little trickier.

One thing to note is that we like OCaml because it's very flexible and
expressive.  If you mechanically translate all Cocoa objects and structs
into their obvious OCaml corollaries, you lose a lot of the advantage of
using OCaml.  For example, we map Cocoa NSPoint values into OCaml
2-tuples, not into OCaml records.  And we often use OCaml lists (with
the correct base type) to represent NSArray objects.  Because of this,
we don't think a direct mechanical translation of Cocoa into OCaml is
going to work.  But a mechanical translation with sufficient overrides
probably would.

> 2) Does anyone have a small example project that does mix these two
> languages? I have looked at unison, but it is too big for me to get my
> head around. I am thinking more on the scale of the ubiquitous
> Currency Converter...

I don't know of anything.

> 3) Does anyone who is mixing these languages use Xcode to do so? If
> so, what steps do you need to go through to set that up?

To be honest, we don't currently use Xcode in any non-trivial way.  We
just use its built-in knowledge about packaging up applications.  There
was a project to integrate OCaml into Xcode, but again it doesn't look
like an active project.  The home page is here:

    http://maxao.free.fr/xcode-ocaml-plugin

Jeff Scofield
Seattle

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »