caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Make OCaml library available to Java
@ 2016-08-02  4:02 Arlen Cox
  2016-08-02 10:56 ` Malcolm Matalka
  0 siblings, 1 reply; 9+ messages in thread
From: Arlen Cox @ 2016-08-02  4:02 UTC (permalink / raw)
  To: caml-list

Hi all,

I'm trying to figure out what the best way is to make an OCaml library
available to a Java program.  I can think of several ways to do this
each with pros and cons:

1.  OCaml-Java:  This is the most obvious solution that translates the
OCaml code directly to Java.
  + Simple interface to OCaml code
  + Portable Java-compatible code
  + Can easily call back into Java
  - OCaml-Java is a bit buggy
  - Code runs slower

2.  js_of_ocaml:  Translate OCaml to JavaScript and then use the new
"fast" JavaScript engine in Java 8 to execute the JS.
  + Portable Java-compatible code
  + Can call back into Java (albeit, less easily than OCaml-Java)
  - Not type safe interface
  - Possible massive slowdowns or at least unpredictable performance

3.  JNI with C Library:  Wrap OCaml code in a C library and then call
into that with JNI
  + Native OCaml performance
  - Complex GC interaction
  - Not type safe
  - Not portable (need different .so for each platform)
  - No tools to help in doing this (CamlJava is both unsupported and
seemingly unidirectional)
  - No easy call back into Java

Does anyone have any experience with doing this or have any
suggestions on what to do in this situation?

Thanks,
Arlen

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Make OCaml library available to Java
  2016-08-02  4:02 [Caml-list] Make OCaml library available to Java Arlen Cox
@ 2016-08-02 10:56 ` Malcolm Matalka
  2016-08-02 11:51   ` Arlen Cox
  0 siblings, 1 reply; 9+ messages in thread
From: Malcolm Matalka @ 2016-08-02 10:56 UTC (permalink / raw)
  To: Arlen Cox; +Cc: caml-list

You could also make an executable written in Ocaml that communicates
over stdin/stdout.

Arlen Cox <arlencox@gmail.com> writes:

> Hi all,
>
> I'm trying to figure out what the best way is to make an OCaml library
> available to a Java program.  I can think of several ways to do this
> each with pros and cons:
>
> 1.  OCaml-Java:  This is the most obvious solution that translates the
> OCaml code directly to Java.
>   + Simple interface to OCaml code
>   + Portable Java-compatible code
>   + Can easily call back into Java
>   - OCaml-Java is a bit buggy
>   - Code runs slower
>
> 2.  js_of_ocaml:  Translate OCaml to JavaScript and then use the new
> "fast" JavaScript engine in Java 8 to execute the JS.
>   + Portable Java-compatible code
>   + Can call back into Java (albeit, less easily than OCaml-Java)
>   - Not type safe interface
>   - Possible massive slowdowns or at least unpredictable performance
>
> 3.  JNI with C Library:  Wrap OCaml code in a C library and then call
> into that with JNI
>   + Native OCaml performance
>   - Complex GC interaction
>   - Not type safe
>   - Not portable (need different .so for each platform)
>   - No tools to help in doing this (CamlJava is both unsupported and
> seemingly unidirectional)
>   - No easy call back into Java
>
> Does anyone have any experience with doing this or have any
> suggestions on what to do in this situation?
>
> Thanks,
> Arlen

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Make OCaml library available to Java
  2016-08-02 10:56 ` Malcolm Matalka
@ 2016-08-02 11:51   ` Arlen Cox
  2016-08-02 16:34     ` Gerd Stolpmann
  2016-08-02 17:21     ` Pippijn van Steenhoven
  0 siblings, 2 replies; 9+ messages in thread
From: Arlen Cox @ 2016-08-02 11:51 UTC (permalink / raw)
  To: caml-list

Thank you for your answers.  I should be more clear on a couple of
things.  My default method of communication is to use pipes or
sockets.  However, my code is an abstract domain library.  The
interface exposes large, recursively defined variants; exposes
first-class modules (though not functors); and is expected to be
relatively high performance.

For now I'll tinker with the js_of_ocaml option.  It might be a pain
to wrap it properly, but I think it should be possible to make the
performance acceptable by replacing a few of the hotter internal
components with native Java code accessed via the Javascript api.

I am still open to other ideas, though.

Has anyone considered writing a source-to-source translator from OCaml to Scala?

Thanks,
Arlen

On Tue, Aug 2, 2016 at 6:56 AM, Malcolm Matalka <mmatalka@gmail.com> wrote:
> You could also make an executable written in Ocaml that communicates
> over stdin/stdout.
>
> Arlen Cox <arlencox@gmail.com> writes:
>
>> Hi all,
>>
>> I'm trying to figure out what the best way is to make an OCaml library
>> available to a Java program.  I can think of several ways to do this
>> each with pros and cons:
>>
>> 1.  OCaml-Java:  This is the most obvious solution that translates the
>> OCaml code directly to Java.
>>   + Simple interface to OCaml code
>>   + Portable Java-compatible code
>>   + Can easily call back into Java
>>   - OCaml-Java is a bit buggy
>>   - Code runs slower
>>
>> 2.  js_of_ocaml:  Translate OCaml to JavaScript and then use the new
>> "fast" JavaScript engine in Java 8 to execute the JS.
>>   + Portable Java-compatible code
>>   + Can call back into Java (albeit, less easily than OCaml-Java)
>>   - Not type safe interface
>>   - Possible massive slowdowns or at least unpredictable performance
>>
>> 3.  JNI with C Library:  Wrap OCaml code in a C library and then call
>> into that with JNI
>>   + Native OCaml performance
>>   - Complex GC interaction
>>   - Not type safe
>>   - Not portable (need different .so for each platform)
>>   - No tools to help in doing this (CamlJava is both unsupported and
>> seemingly unidirectional)
>>   - No easy call back into Java
>>
>> Does anyone have any experience with doing this or have any
>> suggestions on what to do in this situation?
>>
>> Thanks,
>> Arlen

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Make OCaml library available to Java
  2016-08-02 11:51   ` Arlen Cox
@ 2016-08-02 16:34     ` Gerd Stolpmann
  2016-08-02 16:48       ` Arlen Cox
  2016-08-02 17:21     ` Pippijn van Steenhoven
  1 sibling, 1 reply; 9+ messages in thread
From: Gerd Stolpmann @ 2016-08-02 16:34 UTC (permalink / raw)
  To: Arlen Cox; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 3363 bytes --]

Am Dienstag, den 02.08.2016, 07:51 -0400 schrieb Arlen Cox:
> Thank you for your answers.  I should be more clear on a couple of
> things.  My default method of communication is to use pipes or
> sockets.  However, my code is an abstract domain library.  The
> interface exposes large, recursively defined variants; exposes
> first-class modules (though not functors); and is expected to be
> relatively high performance.
> 
> For now I'll tinker with the js_of_ocaml option.  It might be a pain
> to wrap it properly, but I think it should be possible to make the
> performance acceptable by replacing a few of the hotter internal
> components with native Java code accessed via the Javascript api.
> 
> I am still open to other ideas, though.
> 
> Has anyone considered writing a source-to-source translator from OCaml to Scala?

Scala is fairly slow for symbolical code. Actually, I'd be more
interested in a source-to-source translator from Scala to OCaml to get
better speed... For a translation of OCaml to Scala you need to start
with the typed source code (cmt files) because Scala requires way more
typing hints than OCaml, and to get the omnipresent subtyping under
control. Also, there is no direct counterpart of first-class modules, so
you'd have to work around that.

Gerd

> Thanks,
> Arlen
> 
> On Tue, Aug 2, 2016 at 6:56 AM, Malcolm Matalka <mmatalka@gmail.com> wrote:
> > You could also make an executable written in Ocaml that communicates
> > over stdin/stdout.
> >
> > Arlen Cox <arlencox@gmail.com> writes:
> >
> >> Hi all,
> >>
> >> I'm trying to figure out what the best way is to make an OCaml library
> >> available to a Java program.  I can think of several ways to do this
> >> each with pros and cons:
> >>
> >> 1.  OCaml-Java:  This is the most obvious solution that translates the
> >> OCaml code directly to Java.
> >>   + Simple interface to OCaml code
> >>   + Portable Java-compatible code
> >>   + Can easily call back into Java
> >>   - OCaml-Java is a bit buggy
> >>   - Code runs slower
> >>
> >> 2.  js_of_ocaml:  Translate OCaml to JavaScript and then use the new
> >> "fast" JavaScript engine in Java 8 to execute the JS.
> >>   + Portable Java-compatible code
> >>   + Can call back into Java (albeit, less easily than OCaml-Java)
> >>   - Not type safe interface
> >>   - Possible massive slowdowns or at least unpredictable performance
> >>
> >> 3.  JNI with C Library:  Wrap OCaml code in a C library and then call
> >> into that with JNI
> >>   + Native OCaml performance
> >>   - Complex GC interaction
> >>   - Not type safe
> >>   - Not portable (need different .so for each platform)
> >>   - No tools to help in doing this (CamlJava is both unsupported and
> >> seemingly unidirectional)
> >>   - No easy call back into Java
> >>
> >> Does anyone have any experience with doing this or have any
> >> suggestions on what to do in this situation?
> >>
> >> Thanks,
> >> Arlen
> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Make OCaml library available to Java
  2016-08-02 16:34     ` Gerd Stolpmann
@ 2016-08-02 16:48       ` Arlen Cox
  0 siblings, 0 replies; 9+ messages in thread
From: Arlen Cox @ 2016-08-02 16:48 UTC (permalink / raw)
  To: Gerd Stolpmann; +Cc: caml-list

Of course you're right.  Also, I think polymorphic variants would be
problemantic (and the object system...).

It just seems like there should be a genuinely good way to interact
with the JVM at a fine-grained level that doesn't involve writing a
boatload of really finicky C code to serve as an intermediary.  I
guess I sort of want a SWIG for OCaml instead of just SWIG for C/C++.

Arlen


On Tue, Aug 2, 2016 at 12:34 PM, Gerd Stolpmann <info@gerd-stolpmann.de> wrote:
> Am Dienstag, den 02.08.2016, 07:51 -0400 schrieb Arlen Cox:
>> Thank you for your answers.  I should be more clear on a couple of
>> things.  My default method of communication is to use pipes or
>> sockets.  However, my code is an abstract domain library.  The
>> interface exposes large, recursively defined variants; exposes
>> first-class modules (though not functors); and is expected to be
>> relatively high performance.
>>
>> For now I'll tinker with the js_of_ocaml option.  It might be a pain
>> to wrap it properly, but I think it should be possible to make the
>> performance acceptable by replacing a few of the hotter internal
>> components with native Java code accessed via the Javascript api.
>>
>> I am still open to other ideas, though.
>>
>> Has anyone considered writing a source-to-source translator from OCaml to Scala?
>
> Scala is fairly slow for symbolical code. Actually, I'd be more
> interested in a source-to-source translator from Scala to OCaml to get
> better speed... For a translation of OCaml to Scala you need to start
> with the typed source code (cmt files) because Scala requires way more
> typing hints than OCaml, and to get the omnipresent subtyping under
> control. Also, there is no direct counterpart of first-class modules, so
> you'd have to work around that.
>
> Gerd
>
>> Thanks,
>> Arlen
>>
>> On Tue, Aug 2, 2016 at 6:56 AM, Malcolm Matalka <mmatalka@gmail.com> wrote:
>> > You could also make an executable written in Ocaml that communicates
>> > over stdin/stdout.
>> >
>> > Arlen Cox <arlencox@gmail.com> writes:
>> >
>> >> Hi all,
>> >>
>> >> I'm trying to figure out what the best way is to make an OCaml library
>> >> available to a Java program.  I can think of several ways to do this
>> >> each with pros and cons:
>> >>
>> >> 1.  OCaml-Java:  This is the most obvious solution that translates the
>> >> OCaml code directly to Java.
>> >>   + Simple interface to OCaml code
>> >>   + Portable Java-compatible code
>> >>   + Can easily call back into Java
>> >>   - OCaml-Java is a bit buggy
>> >>   - Code runs slower
>> >>
>> >> 2.  js_of_ocaml:  Translate OCaml to JavaScript and then use the new
>> >> "fast" JavaScript engine in Java 8 to execute the JS.
>> >>   + Portable Java-compatible code
>> >>   + Can call back into Java (albeit, less easily than OCaml-Java)
>> >>   - Not type safe interface
>> >>   - Possible massive slowdowns or at least unpredictable performance
>> >>
>> >> 3.  JNI with C Library:  Wrap OCaml code in a C library and then call
>> >> into that with JNI
>> >>   + Native OCaml performance
>> >>   - Complex GC interaction
>> >>   - Not type safe
>> >>   - Not portable (need different .so for each platform)
>> >>   - No tools to help in doing this (CamlJava is both unsupported and
>> >> seemingly unidirectional)
>> >>   - No easy call back into Java
>> >>
>> >> Does anyone have any experience with doing this or have any
>> >> suggestions on what to do in this situation?
>> >>
>> >> Thanks,
>> >> Arlen
>>
>
> --
> ------------------------------------------------------------
> Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
> My OCaml site:          http://www.camlcity.org
> Contact details:        http://www.camlcity.org/contact.html
> Company homepage:       http://www.gerd-stolpmann.de
> ------------------------------------------------------------
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Make OCaml library available to Java
  2016-08-02 11:51   ` Arlen Cox
  2016-08-02 16:34     ` Gerd Stolpmann
@ 2016-08-02 17:21     ` Pippijn van Steenhoven
  2016-08-02 17:34       ` Arlen Cox
  2016-08-03 12:43       ` Hendrik Boom
  1 sibling, 2 replies; 9+ messages in thread
From: Pippijn van Steenhoven @ 2016-08-02 17:21 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 674 bytes --]

On Tue, Aug 02, 2016 at 07:51:11AM -0400, Arlen Cox wrote:
> Has anyone considered writing a source-to-source translator from OCaml to Scala?

I don't think this is reasonable. The OCaml and Scala type systems differ
massively. This would not be a source to source translation, but rather
just a compiler that targets Scala, which doesn't seem like a very useful
thing to do.

You might have more luck with Yeti[1], which is quite close to OCaml
already, and has a similar type system. It might even be possible to
semi-automatically (with lots of vim macros) translate all your code to
Yeti in a reasonable amount of time.

Cheers,
Pippijn

[1] https://mth.github.io/yeti/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Make OCaml library available to Java
  2016-08-02 17:21     ` Pippijn van Steenhoven
@ 2016-08-02 17:34       ` Arlen Cox
  2016-08-03 12:43       ` Hendrik Boom
  1 sibling, 0 replies; 9+ messages in thread
From: Arlen Cox @ 2016-08-02 17:34 UTC (permalink / raw)
  To: Pippijn van Steenhoven; +Cc: caml-list

If you stuck to a really simple subset of OCaml, it might be possible
to do a Scala translation (with appropriate type information), just
like if you stick to a really simple subset the code can work as F#
code.  I think Yeti falls into the same camp.  It doesn't look like it
supports a proper module system either.

Honestly this is really just a thought experiment.  What I really want
is for OCaml-Java to be revived...

-Arlen

On Tue, Aug 2, 2016 at 1:21 PM, Pippijn van Steenhoven
<pip88nl@gmail.com> wrote:
> On Tue, Aug 02, 2016 at 07:51:11AM -0400, Arlen Cox wrote:
>> Has anyone considered writing a source-to-source translator from OCaml to Scala?
>
> I don't think this is reasonable. The OCaml and Scala type systems differ
> massively. This would not be a source to source translation, but rather
> just a compiler that targets Scala, which doesn't seem like a very useful
> thing to do.
>
> You might have more luck with Yeti[1], which is quite close to OCaml
> already, and has a similar type system. It might even be possible to
> semi-automatically (with lots of vim macros) translate all your code to
> Yeti in a reasonable amount of time.
>
> Cheers,
> Pippijn
>
> [1] https://mth.github.io/yeti/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Make OCaml library available to Java
  2016-08-02 17:21     ` Pippijn van Steenhoven
  2016-08-02 17:34       ` Arlen Cox
@ 2016-08-03 12:43       ` Hendrik Boom
  2016-08-03 12:46         ` Jeremy Yallop
  1 sibling, 1 reply; 9+ messages in thread
From: Hendrik Boom @ 2016-08-03 12:43 UTC (permalink / raw)
  To: caml-list

On Tue, Aug 02, 2016 at 05:21:22PM +0000, Pippijn van Steenhoven wrote:
> On Tue, Aug 02, 2016 at 07:51:11AM -0400, Arlen Cox wrote:
> > Has anyone considered writing a source-to-source translator from OCaml to Scala?
> 
> I don't think this is reasonable. The OCaml and Scala type systems differ
> massively. This would not be a source to source translation, but rather
> just a compiler that targets Scala, which doesn't seem like a very useful
> thing to do.

There's soomething I've been wondering about.  OCaml keeps a minimum 
of type information at run-time -- one bit in each machine word tells 
whether it's a pointer or not.  Is OCaml's intermediate code stable 
enough that it could be used as intermediate code for another 
language, and compiled further using the usual OCaml toolchain?

-- hendrik

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Make OCaml library available to Java
  2016-08-03 12:43       ` Hendrik Boom
@ 2016-08-03 12:46         ` Jeremy Yallop
  0 siblings, 0 replies; 9+ messages in thread
From: Jeremy Yallop @ 2016-08-03 12:46 UTC (permalink / raw)
  To: Hendrik Boom; +Cc: Caml List

On 3 August 2016 at 13:43, Hendrik Boom <hendrik@topoi.pooq.com> wrote:
> There's soomething I've been wondering about.  OCaml keeps a minimum
> of type information at run-time -- one bit in each machine word tells
> whether it's a pointer or not.  Is OCaml's intermediate code stable
> enough that it could be used as intermediate code for another
> language, and compiled further using the usual OCaml toolchain?

That's the goal of the malfunction project:

   https://github.com/stedolan/malfunction

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-08-03 12:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-02  4:02 [Caml-list] Make OCaml library available to Java Arlen Cox
2016-08-02 10:56 ` Malcolm Matalka
2016-08-02 11:51   ` Arlen Cox
2016-08-02 16:34     ` Gerd Stolpmann
2016-08-02 16:48       ` Arlen Cox
2016-08-02 17:21     ` Pippijn van Steenhoven
2016-08-02 17:34       ` Arlen Cox
2016-08-03 12:43       ` Hendrik Boom
2016-08-03 12:46         ` Jeremy Yallop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).