From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 7DB5F81792 for ; Fri, 13 Jul 2018 14:27:33 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-lj1-f171.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.208.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.208.171 as permitted sender) identity=mailfrom; client-ip=209.85.208.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-lj1-f171.google.com) identity=helo; client-ip=209.85.208.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-lj1-f171.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AuA1p3Rf/Ektd2IV2gI0saxiVlGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxcuzYx7h7PlgxGXEQZ/co6odzbaO7ea4ASQp2tWoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7?= =?us-ascii?q?Ovr6GpLIj8Swyuu+54Dfbx9HiTahYL5+Ngm6oRnMvcQKnIVuLbo8xAHUqXVSYe?= =?us-ascii?q?RWwm1oJVOXnxni48q74YBu/SdNtf8/7sBMSar1cbg2QrxeFzQmLns65Nb3uhnZ?= =?us-ascii?q?TAuA/WUTX2MLmRdVGQfF7RX6XpDssivms+d2xSeXMdHqQb0yRD+v9LlgRgP2hy?= =?us-ascii?q?gbNj456GDXhdJ2jKJHuxKquhhzz5fJbI2JKPZye6XQds4YS2VcRMZcTyNOAo2+?= =?us-ascii?q?YIUPAeQPPvtWoZfhqFUBtha+GRCsCfnzxjNUmnP736s32PkhHwHc2wwgGsoDvn?= =?us-ascii?q?XOo9ruLqcSUP66zK3Vxjvec/xW2Sny6JLWfRA7vPqBWr1wftDKxkk1FgPKkFGQ?= =?us-ascii?q?pZb+PzyJ1uQCrXKb4PR6Ve+0hG4nrht+ojmrxss2lobJgYcVx0nC+C5kw4g1Pc?= =?us-ascii?q?W1RFBnbdOgCpddtCGXO5FoTs8+QGxkojs2x78btZO9YSME0o4oxwTFZPyCa4WI?= =?us-ascii?q?4gzsVOKWITpggXJqYrO/hxKr/UikyO3wS9C40FhXoidHj9XArH8N1xvU6siITv?= =?us-ascii?q?ty4F2t1iqI1wDW8u1EIEY0mrTHK5M53LI8ip4evV7AEyL2gkn6krOae0Y+9uS1?= =?us-ascii?q?6enrf63qppqGOI91jgH+PL4umsu6AekgPQgBRXOU+f691LL9+U31Wq5KgeE2kq?= =?us-ascii?q?bHqpDVO94bq7W2Aw9QyIkj6hK/Ay2639QfmHkLNEhFdw6fj4j1J1HOJ+j1Auul?= =?us-ascii?q?jFSplDdn3vTGPrz6ApXRNXXDi7fgfbNl60FG0gYzzNZf54hVCr4bOv7zVFXx55?= =?us-ascii?q?TkCUoQNQO5x+GvI9JnzYoEXirbC6mWPafVmV6D4fg0KvOLIokYpGCuBeIi4qvB?= =?us-ascii?q?hHUjmFIZNZKi3ZYNZWrwSvtvKV+YbH6qmdwBHH0HpCIxSeXrjBuJVjsFNCX6ZL?= =?us-ascii?q?41+jxuUNHuNozEXI34xeXZhH7qTK0TXXhPDxW3KVmtcoyFX/kWbyfLe51ulzUF?= =?us-ascii?q?Uf6qTIpzjEjy5j+/8KJuK6/vwgNdrYjqjYEn6OjalBV0/jtxXZzEjjO9Clpsl2?= =?us-ascii?q?ZNfAcYmaBypUsnlAWG2Kl8xvhaTJldvqwQFAg9MpHYwqpxDNWgAg8=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CsAgCjmUhbhqvQVdFcHQEBBQELAYUrK?= =?us-ascii?q?IN7g22QT4IMiENnjCKBZguEbAKCTxkHAQQ0FAECAQECAQEBAQETAQEBCAsLCCk?= =?us-ascii?q?jDII1JAGCXQECAyMdARsdAQMMBgULDQICJgICIgERAQUBHAYTgyCBZwEDFZ4EP?= =?us-ascii?q?IsJgREFAReCcgWDSwoZJg1XgkYCBhJ5h3eBVz+EIoRDOIMBglUCjFeNBQcCgXC?= =?us-ascii?q?NN41lkgUPIYE3gXMzGiNQMYI4ghkag06KUz4wjDUBAQ?= X-IPAS-Result: =?us-ascii?q?A0CsAgCjmUhbhqvQVdFcHQEBBQELAYUrKIN7g22QT4IMiEN?= =?us-ascii?q?njCKBZguEbAKCTxkHAQQ0FAECAQECAQEBAQETAQEBCAsLCCkjDII1JAGCXQECA?= =?us-ascii?q?yMdARsdAQMMBgULDQICJgICIgERAQUBHAYTgyCBZwEDFZ4EPIsJgREFAReCcgW?= =?us-ascii?q?DSwoZJg1XgkYCBhJ5h3eBVz+EIoRDOIMBglUCjFeNBQcCgXCNN41lkgUPIYE3g?= =?us-ascii?q?XMzGiNQMYI4ghkag06KUz4wjDUBAQ?= X-IronPort-AV: E=Sophos;i="5.51,347,1526335200"; d="scan'208";a="338799003" Received: from mail-lj1-f171.google.com ([209.85.208.171]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 13 Jul 2018 14:27:32 +0200 Received: by mail-lj1-f171.google.com with SMTP id l15-v6so4278601lji.6 for ; Fri, 13 Jul 2018 05:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=iSRAqJttjWPEQjydbM70XQZixoxU5ZyizyYwabTNdaY=; b=O6tClu3aIASe1ptEFPBs2IJxlTbVcKJARqJbXUfRtmizMoJJ0PyNk38/zUoK2p9dmO qgQihl9IhVBvgKZKGjLz0eDJMVIZ3fmGd++cYc9MBtq5DY+3GFBkK1jkHeGm9lmUMCeI 6uQBAmzog5qgNH0U7JoMAidel1haIgts9OlNwsCeJUuDqVsIWiHIGaSRmLFel+XVq34q IrjwUZygMqpopR9cICXHGXn4GqZkHMEGGLKPGJJKwdqBHYgnFVU9DjX8gwFPPOxjxQWb k+uoe4P796mQ29VJiJKNYCw1y5jYPdbHaWjk1ZI/Av5jQRYEZQ4jVrxSKnV4NGN3hZ8A zC5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=iSRAqJttjWPEQjydbM70XQZixoxU5ZyizyYwabTNdaY=; b=tzrj8DbQFFzxJISXKQJa2HwMU30jCGIqW+y/5eRCLHzSmN5KQKOfoR/oqhPq8yjh9g v14BNnzGz4tNpRa06DL7aYQPOZtUuqfvoWJmfPP6HYySs88GIoSeHNEl+P9kISZBo0C0 mJBAQYD5ujtt+XPerRbHaZPsX5rxsHciSi+JJ8iG0Sak86UWdKkYe+zgD+1exPOjs/pm vIBltfBDe3LGy5UvDtEPh+FXQaZjv1bomO4sNojxIAH7K8s3Yw7Gp6Zm/E3x0flVtEKI 1qb2GTamL9hXTDEOKFgW5ZkJlGD2U+Twh/o3wIZrB6nqpq3bd4tDPT9pGhq2olVNRLq+ YeHg== X-Gm-Message-State: AOUpUlFyq5/Ta4fHlEhwJqsD9/94qO0aN+0lTlJP/NO5VZkEo+ZRQgif /IzF7j9BVHXt5XTVdKYQ4eULlu4414iJXGJbpyG9VQ== X-Google-Smtp-Source: AAOMgpdgxH36BMfZfLCEGDySnH07OCNn58ctnEX2wjOgui3vY09pFUiiKCYXnB0mLwBg2hTupWbkN4j7X4AyaHzS6NM= X-Received: by 2002:a2e:1dc8:: with SMTP id w69-v6mr3083319lje.110.1531484851545; Fri, 13 Jul 2018 05:27:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Gabriel Scherer Date: Fri, 13 Jul 2018 13:34:59 +0100 Message-ID: To: Angelo Corsaro Cc: caml users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Recursive Types and -rectypes -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 =E2=80=98msg actor_queue =3D Act of ( =E2=80=98msg actor_queue optio= n * =E2=80=98msg) some_queue_type let queue (Act q) =3D q On Fri, Jul 13, 2018 at 12:10 PM Angelo Corsaro wrote: > > Dear All, > > I am looking for some advices and suggestions on the use of recursive typ= es 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 =E2=80=94 with the dif= ference that at the present time we care only on using actors to control co= ncurrency on the same process. As you can probably imagine the recursive ty= pe definition comes out from the actor message queue. The most straight for= ward definition would look like (removing some details to keep the essence): > > type =E2=80=98msg actor_queue =3D ( =E2=80=98msg actor_queue option * =E2= =80=98msg) some_queue_type > > This is a simplified version, but let=E2=80=99s say that the intuition is= that we need to post on the receiving actor queue the message along to pos= sibly the queue of the agent we may reply to. This gives rise to a recursiv= e type definition which clearly would only be usable with the -rectypes opt= ion. > > The traditional way of breaking things kind of recursive types is to use = variant types recursion. Which is what I=E2=80=99ve 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 rep= resent this type, as they allow for recursive type definition? Or just stic= k with the variant type trick? > > Thanks very much in advance for sharing your thoughts! > > Ciao, > Angelo > > P.S. =E2=80=98msg is actually bound with some polymorphic variant to allo= w the actor to accept any user defined type as in Erlang. We also have a ve= rsion that leverages functors to define the messages that may be exchanged = between actors =E2=80=94 if a strict control is required on the set of mess= ages exchanged. > > =E2=80=94 > =E2=80=9CSimplicity is the ultimate sophistication." ~ Leonardo da Vinci >