[mercury-users] Exchanging 'rules' between OCaml and Mercury

Guillaume Yziquel guillaume.yziquel at gmx.ch
Tue Jun 7 08:06:00 AEST 2011


I finally got OCaml and Mercury to cooperate. I'm now wondering what's
the best way to exchange rather complex data structures between OCaml
and Mercury.

The main idea is that I have, in OCaml:

-1- items (let's call them that way), which are indexed by long ints.

-2- 'propositions' (i.e. OCaml discriminated union types) that expresses
properties of the various items, and relations between items.

-3- a handul of maps (tree-like purely functional data structures) that
map an item to the propositions that refer to this item.

Essentially, I have a parser written in OCaml (with Dypgen) that creates
all these items, propositions, and maps, and I wish to feed them to some
Mercury code.

Right now I'm wondering what's the most reasonable way to exchange data
between OCaml and Mercury. (By 'most reasonable', I mean nice, clean,
readable code, not concerned about efficiency and stuff like unboxing
yet). I'm mostly concerned about the maps.

On one hand, it seems possible to use Mercury to use the OCaml maps by
using foreign code and types the right from Mercury code, but this seems
a bit cumbersome. I also see that Mercury libraries have interesting
data structures readily available. So I'm also pondering the possibility
of creating Mercury datastructures from OCaml. This would probably the
cleanest solution, but I have little idea of the runtime issues
involved, such as garbage collection.

Another thing to consider is that items, propositions and maps are
created incrementally by the parser, and that Mercury would be called
quite frequently during this incremental parsing. (The datastructures
involved are purely functional and immutable, though).

So how would you do you live in harmony with the Mercury GC when
building Mercury data structures from foreign code and then invoking
Mercury code from foreign code on these data structures? Is there any
example of such code lying around on the net?

Best regards,

     Guillaume Yziquel
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list