Hello Gabriel,


On 13 Jul 2018, at 14:34, Gabriel Scherer <gabriel.scherer@gmail.com> wrote:

-rectypes is not the default because it leads to the type-checker
accepting code that is a programmer mistake but makes sense using
recursive types. This leads to hard-to-understand errors down the line
when you try to use the name at the type you think it has.

I would just go for the variant. I am not sure what kind of
readability overhead you have in mind, do you have a concrete example?
In my experience, the ability to use pattern-matching in function
arguments and let declarations makes this very smooth


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

 let queue (Act q) = q

Yes, this is similar to what I did. I shared your concerns on the use of -rectypes this is why I was looking for advises. We are a bit new to OCaml and from time to time it is good to get some advise from the community. Thanks again for the valuable feedback!

Enjoy the weekend.

Ciao,
Angelo
 


On Fri, Jul 13, 2018 at 12:10 PM Angelo Corsaro <angelo@icorsaro.net> wrote:

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


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