Dear All,

I am looking for some advices and suggestions on the use of recursive types that  OCaml makes available through the -rectypes option. 

To give you some context we have built a simple Agent framework for Ocaml that provides primitives similar to those of Erlang — with the difference that at the present time we care only on using actors to control concurrency on the same process. As you can probably imagine the recursive type definition comes out from the actor message queue. The most straight forward definition would look like (removing some details to keep the essence):

type ‘msg actor_queue = ( ‘msg actor_queue option * ‘msg) some_queue_type 

This is a simplified version, but let’s say that the intuition is that we need to post on the receiving actor queue the message along to possibly the queue of the agent we may reply to. This gives rise to a recursive type definition which clearly would only be usable with the -rectypes option.

The traditional way of breaking things kind of recursive types is to use variant types recursion. Which is what I’ve done. Yet that comes at some cost w.r.t. the readability of the code. Thus the question, would you suggest using -rectypes to enable recursive data types? Use classes to represent this type, as they allow for recursive type definition? Or just stick with the variant type trick?

Thanks very much in advance for sharing your thoughts!

Ciao,
    Angelo

P.S. ‘msg is actually bound with some polymorphic variant to allow the actor to accept any user defined type as in Erlang. We also have a version that leverages functors to define the messages that may be exchanged between actors — if a strict control is required on the set of messages exchanged. 

“Simplicity is the ultimate sophistication." ~ Leonardo da Vinci