Previous week Up Next week

Hello

Here is the latest OCaml Weekly News, for the week of December 15 to 22, 2015.

  1. Invoking Java programs from an OCaml program
  2. Batteries 2.4.0
  3. ocaml-session
  4. LablGtk2-Ocaml-Tutorial (SooHyoung Oh) now on github
  5. Ocaml Github Pull Requests

Invoking Java programs from an OCaml program

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2015-12/msg00064.html

Soichi Sumi asked:
I want to invoke Java programs and use their result
from an OCaml program in my research.

I have tried OCaml-Java to realize the integration
and succeeded to execute some example.However,
it cannot invoke objects defined by me, as far as
I read OCaml-Java document. I think it only realize
seamless integration of Java standard library and OCaml.

Is there anyway to use Java Object which defined by me
or to invoke jar file and use the result?

If you know another way to use the result produced by
Java programs, I want to know the way too.

Any help appreciated.
      
Xavier Clerc suggested:
You should actually be able to use your own objects as
easily as any other Java object. It just happens that some
SDK classes can be accessed through the OCaml-Java
library.

The major point to consider is the classpath. By default,
the compiler has only access to the SDK classes, but
you can add any directory or jar file thanks to the "-cp"
command-line switch.
      
Chan Ngo also suggested and Paul Pelzl said:
> An alternative, if you want to do as follows:
> - Compile Java program to an executable (not jar file)
> - Call this executable and get the return values from it
> 
> 
> So you can think about Unix module in OCaml, you can use the standard I/O
> to realize a communication channel between your OCaml code and the
> executable Java.
> https://ocaml.github.io/ocamlunix/ocamlunix.html

If the data to be exchanged is structurally complex, then this technique
becomes difficult; a cross-platform serialization library can be very helpful
for generating appropriate serialization code in multiple languages. As one
example, Cap'n Proto has bindings for both Java and OCaml:
https://capnproto.org/otherlang.html
      
Seungcheol Jung said:
I am also looking for a way to use Java library in OCaml application. My OCaml
application is performance-critical static source code analyzer. I found two
options: X. Clerc's OCaml-Java and X. Leroy's camljava. Which one is more
suitable?

1. OCaml-Java
From my understanding, OCaml-Java[1] compiles OCaml code into byte code and
packs the byte code, interpreter, and Java code into one Java application. It
looks more like embedding OCaml code in Java, not getting some help from
Java. So it does not satisfy my pro-OCaml taste. I am also concerned about
slowdowns due to byte code and interpreter.

2. camljava
I think camljava[2] is more suitable for my purpose. Using camljava, I can
launch JVM and call Java methods via JNI from native OCaml applications.
However, it is a very low-level interface so that I need to implement many
boilerplates by hand (O'Jacaré[3] might reduce some burden?) and beware of
type-safety. Also, it is not maintained for a long time (the latest
version came out before ten years ago).

Do you have any suggestions? Moreover, could anyone share some real-world
stories about OCaml-Java binding?

Regards,
Seungcheol Jung

[1] http://www.ocamljava.org/
[2] https://forge.ocamlcore.org/projects/camljava/
[3] http://www.pps.univ-paris-diderot.fr/~henry/ojacare/index.en.html
      
Sébastien Ferré replied:
I have used camljava in one project. I found
that solution satisfying although it does involve
a lot of boilerplates, indeed. It makes it possible
to use a JAR a bit like a C library. At runtime, it
is sufficient to set the CLASSPATH.

If you are curious, visit http://www.irisa.fr/LIS/softwares/pew/
from where you can find the source code, and execution instructions.
(boilerplate code is in file owlapi.ml)

I am interested by solutions to ease the generation of
boilerplates.
      
Xavier Clerc also replied:
OCaml-Java actually compiles OCaml code to *Java* bytecode, meaning that no
OCaml interpreter is involved. Of course, the ocamljava-compiled programs are
slower than ocamlopt-compiled ones; however, the factor is heavily dependent
on the kind of computation.

Currently the rule of thumb is that ocamljava-compiled code is roughly 3 times
slower, with numerical code on par and "massively functional code" much slower
(sometimes 10x slower).
      

Batteries 2.4.0

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2015-12/msg00069.html

Francois Berenger announced:
Batteries (OCaml Batteries Included) is a community-developed overlay
over the "standard" library distributed with the compiler, that aims
to provide general-purpose data-structures and convenient functions.

The project follows a semantic versioning scheme; the new version is
backward-compatible with the previous releases (2.3.1 was in October
2014). The lowest OCaml version certainly supported is 3.12.1.

The new release is available in OPAM, or as a tarball
https://github.com/ocaml-batteries-team/batteries-included/releases/tag/v2.4.0
or from the sources
https://github.com/ocaml-batteries-team/batteries-included
The online API documentation is at:
http://ocaml-batteries-team.github.io/batteries-included/hdoc2/

This release contains a handful of new functions and bugfixes -- see
the detailed changelog below. Two highlights are the `pop_{min,max}`
in BatSet and `pop_{min,max}_bindings` in BatMap contributed by
François Berenger, and a nasty bug when hashing values close to
min_int spotted by Martin Neuhäußer -- this long-hidden bug was due to
a mistake in the backward-compatibility code for the hashing function
transition between OCaml 3.12 and OCaml 4.00.

With many thanks to the contributors to this new release, including
Guillaume Allais, Aleksey Z. Arens, Nils Becker, François Berenger,
Sang Kil Cha, Simon Cruanes, Bob Fang, Anders Fugmann, Rudi Grinberg,
Herry, Christoph Höger, Max Mouratov, Martin R. Neuhäußer, Gabriel
Scherer, Quentin Stievenart, Kevin Brubeck Unhammer, Ralf Vogler, and
Xavier Van de Woestyne.

New contributors are always welcome, you can have a look at the issue
list on github to find something you would be interested into working on and
discuss with the maintainers:
https://github.com/ocaml-batteries-team/batteries-included/issues

With our best regards,
The OCaml batteries-included team.

# Detailed changelog

- BatBitSet: use Bytes instead of String
  (Gabriel Scherer)
- BatHashtbl: fix hash computation bug introduced by 4.01 (issue #609)
  (Gabriel Scherer, report by Martin R. Neuhäußer)
- BatText: synchronize nsplit to match BatString.nsplit
  (Gabriel Scherer)
- BatLazyList: fix remove_all_such documentation
  (Xavier Van de Woestyne)
- BatMap: add pop_min_binding: 'a t -> (key * 'a) * 'a t
      and pop_max_binding: 'a t -> (key * 'a) * 'a t
  (Francois Berenger)
- BatMap: add at_rank_exn: int -> ('key, 'a) t -> ('key * 'a)
      and update: key -> key -> 'a -> 'a t -> 'a t
  (Francois Berenger)
- BatEnum: add interleave: 'a t array -> 'a t
  (Aleksey Z. Arens)
- BatFormat: expose asprintf for V>=4.01
  (Ralf Vogler)
- BatSet: add at_rank_exn: int -> t -> elt
      and update: elt -> elt -> t -> t
  (Francois Berenger)
- BatUTF8: add enum: t -> BatUChar.t BatEnum.t
  (Kevin Brubeck Unhammer)
- BatSet: add to_array: t -> elt array
      and of_array: elt array -> t
      and test for to_list
  (Francois Berenger)
- BatSet: add pop_max: 'a t -> 'a * 'a t
      and pop_min: 'a t -> 'a * 'a t
  (Francois Berenger)
- BatSplay: hardened against read-only-data compiler optimization
  (Gabriel Scherer)
- BatList: simplified interleave implementation
  (Francois Berenger)
- BatOption: add
  Infix.(>>=): 'a option -> ('a -> 'b option) -> 'b option
  (Herry Herry)
- BatHashtbl: modify now have same semantics than replace for the key
  (Anders Fugmann)
- BatHashtbl: more efficient modify_opt and modify_def
  (Anders Fugmann)
- BatFormat: add pp_print_list: ?pp_sep:(formatter -> unit -> unit) ->
                            (formatter -> 'a -> unit) ->
                            (formatter -> 'a list -> unit)
         and pp_print_text: formatter -> string -> unit
  (Christoph Höger)
- BatEnum: add uniq_by: ('a -> 'a -> bool) -> 'a t -> 'a t
       and uniqq: 'a t -> 'a t
  (Max Mouratov)
- BatEnum: fix uniq to use structural comparison
  (Max Mouratov)
- BatUnix: add run_and_read: string -> process_status * string
  (Francois Berenger)
- BatCache: use hashmap to speed up lru_cache
  (Sang Kil Cha)
- BatQueue: add filter: ('a -> bool) -> 'a t -> 'a t
        and filter_inplace: ('a -> bool) -> 'a t -> unit
        and filter_map: ('a -> 'b option) -> 'a t -> 'b t
  (Gabriel Scherer)
      

ocaml-session

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2015-12/msg00075.html

Spiros Eliopoulos announced:
I'm happy to announce the initial release of ocaml-session:

https://github.com/inhabitedtype/ocaml-session

ocaml-session is an session manager that handles cookie headers and backend
storage for HTTP servers. The library supports CoHTTP and Webmachine; Async
and Lwt; and pluggable backing stores based on a functor interface.

The library ships with an in-memory backend (for development and testing) and
a postgresql-ocaml[0] based backend. One of the goals of the library is to
expand the number of persistent and ephemeral storage systems (filesystem,
memcache, redis, MySQL, etc.) that are available out of the box so that it's
easy to integrate into a user's existing infrastructure. There is already an
issue open to provide a PG'OCaml-based backend[1] if that's more of your cup
of tea in terms of postgresql libraries. Anybody who would like to contribute
that should claim the issue and have at it!

As always, issues and pull requests welcomed.

-Spiros E.

[0]: https://github.com/mmottl/postgresql-ocaml
[1]: https://github.com/inhabitedtype/ocaml-session/issues/1
      
Török Edwin then said:
How about signed cookies as a storage backend?
Python Flask and Django can use it to store session entirely in the cookies
with an hmac signature and expiration time, so your server can be entirely
stateless.
As long as the amount of data in your session is small, and all you need is
authenticated data (and not secret data) I think its quite an elegant
solution,
and more fitting with a functional style.

Now of course comes the question Cryptokit or nocrypto :)

[1] http://werkzeug.pocoo.org/docs/0.11/contrib/securecookie/
[2] https://docs.djangoproject.com/en/1.9/topics/http/sessions/
[3] http://pythonhosted.org/itsdangerous/
      
Spiros Eliopoulos replied:
This is interesting. As far as I can tell, it should be possible to implement
this as a backend without any modifications to module signatures. 

> Now of course comes the question Cryptokit or nocrypto :)

That decision, for better or worse, has already been made by ocaml-session: it
uses nocrypto to generate session keys.
      
Bruno Deferrari also replied:
Here is a basic implementation of something similar to itsdangerous I wrote a
few days ago for a project I'm working on, it uses nocrypto:

https://gist.github.com/tizoc/975bfac960d7e5c60232

With a bit of work it could become an opam package.
      

LablGtk2-Ocaml-Tutorial (SooHyoung Oh) now on github

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2015-12/msg00095.html

Oliver Bandel announced:
I made the LablGtk2-Ocaml-Tutorial,
initially written by SooHyoung Oh,
available on github.

I already corrected some of the links, which pointed to nirvana,
to point to the official laglgtk-docs.
Some more changes will follow, so that the other links to the lablgtk-API-docs
also will work.

The tutorial is available here:
  https://github.com/klartext/lablgtk2-ocaml-Tutorial
      

Ocaml Github Pull Requests

Gabriel Scherer compiled this list:
Here is a sneak peek at some potential future features of the Ocaml
compiler, discussed by their implementers in these Github Pull Requests.

Optim hashtbl
https://github.com/ocaml/ocaml/pull/328

Windows sockets in asynchronous mode
https://github.com/ocaml/ocaml/pull/331

Shortcut for extension and attributes
https://github.com/ocaml/ocaml/pull/342
      

Old cwn

If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.


Alan Schmitt