From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr 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 CAE9E822AC for ; Thu, 16 Nov 2017 22:46:12 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=cedilla@gmail.com; spf=Pass smtp.mailfrom=cedilla@gmail.com; spf=None smtp.helo=postmaster@mail-wm0-f50.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of cedilla@gmail.com) identity=pra; client-ip=74.125.82.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of cedilla@gmail.com designates 74.125.82.50 as permitted sender) identity=mailfrom; client-ip=74.125.82.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@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-wm0-f50.google.com) identity=helo; client-ip=74.125.82.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="postmaster@mail-wm0-f50.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AJwpzdhwkCDf2TpTXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?0u8VIJqq85mqBkHD//Il1AaPBtqLra8cw8Pt8IneGkU4qa6bt34DdJEeHzQksu?= =?us-ascii?q?4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2NBXupSi55DsWXxH+LhZd?= =?us-ascii?q?J+LvG4eUgd7k+fq1/sjpbghEzAW8Zah1Kl3ipgjdt80SiKNtL68wzl3CpX4eKL?= =?us-ascii?q?ce/n9hOV/Gx0W03cy35pM2qyk=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CBAQDlBQ5ahjJSfUpdhAw0eScHg3iBN?= =?us-ascii?q?pgPPQcBAQaBLIlUh0eFSYIRCgWKEAc/GAEBAQEBAQEBAQESAQEBCAsLCCgvgjg?= =?us-ascii?q?igm4EGQEbHgMSCQc3AiQBEQEFAYpAAQMIDZkqg0VAjA2BbRgFARyDCgWDYwoZJ?= =?us-ascii?q?w1YgxwCBhKDIoIHgQ6LP4JJgmMFkwePNJUKghWKEIcjlhwUBR+BFR+CLTQhCB0?= =?us-ascii?q?VfoIvgmyCFCA2jAYBAQE?= X-IPAS-Result: =?us-ascii?q?A0CBAQDlBQ5ahjJSfUpdhAw0eScHg3iBNpgPPQcBAQaBLIl?= =?us-ascii?q?Uh0eFSYIRCgWKEAc/GAEBAQEBAQEBAQESAQEBCAsLCCgvgjgigm4EGQEbHgMSC?= =?us-ascii?q?Qc3AiQBEQEFAYpAAQMIDZkqg0VAjA2BbRgFARyDCgWDYwoZJw1YgxwCBhKDIoI?= =?us-ascii?q?HgQ6LP4JJgmMFkwePNJUKghWKEIcjlhwUBR+BFR+CLTQhCB0VfoIvgmyCFCA2j?= =?us-ascii?q?AYBAQE?= X-IronPort-AV: E=Sophos;i="5.44,405,1505772000"; d="scan'208,217";a="301148732" Received: from mail-wm0-f50.google.com ([74.125.82.50]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 16 Nov 2017 22:46:12 +0100 Received: by mail-wm0-f50.google.com with SMTP id b189so2980862wmd.0 for ; Thu, 16 Nov 2017 13:46:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=kahG+HVgUXgfyaNhSl+NxMAc1YlN6lY2HClAWi7ELOY=; b=aXt+ZiAFWkHDi1MeyCPG4YuDczeJEnBPAxw7cn9178FqSKiulPxvMOm6hujpDM9TGx Y8tgLlCqoFSieuNcrl0/cnPqVzkXK/Ng+u0LW6er+LRK5Vka4wOC0VLudTcwJGHbZieU 2Aqn0dDJz2DbpJZntfZUe7nNTgEZY6CFlaQWGaiz6UOaTJmxmue9fs9rynUsQX9zbSCI 8bTZN9420G7YOHT+XT3Dn90hVhXA9QWdhp73H3gwx4M9g/TGL7kT8/FZxFfmLx9+14G0 9NH6t+WbcnRrnPuwsmFgbkt5mwHvI11xMi7/vnARzg+A7jjU/gCMpYbIBA26P5zrJObi FU4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=kahG+HVgUXgfyaNhSl+NxMAc1YlN6lY2HClAWi7ELOY=; b=VmsKGUAJT65cJcrjjw4hqyzZoFy4deCktZb3BA2cMhr1hgbsUJC8rqVqlgFXmfMHr0 TyYWu8/mtjkS63LMawH8EV5O3HDvI6Z+ythZHYgUyvinrJ5TcuvLoRLZhVHUukBRop3k h4G21ILxdbCSWriP+iXsV3xzt6DJmUA6H0345aGCnO8XEzhBnB7hEWTpjmGU+x0xuepZ zvFPtaR8FumPstnJXmAhYEz/aC5EPms8B5FB1sPBPDo3+JYYkhq/QJwliUjZCSkWOXb3 LU43lW2lUlByezA+eEIs8/6u3zDhXa2CZvYlRVLA4N5uY7f4M7Cx7rmWmDnj3uYIW/EZ 4Jjg== X-Gm-Message-State: AJaThX5BYGZCdVeHaMqsMIaSiLsxzTYjEznbgIVtBv9pLU0CgUYgq/ub Pb/yOuhu4hJTiLEhnY9YOv7/BXYaxSHtLEG5tFzsq2ZW X-Google-Smtp-Source: AGs4zMbtWs5e3LHff/1aComvgG3NDDrJpN5q6KHVRj+LNL6fPuKn1CRDKielVttGzPz+AB36j0F/w5rAv5q+5AGpmvc= X-Received: by 10.80.139.65 with SMTP id l59mr4619236edl.187.1510868771811; Thu, 16 Nov 2017 13:46:11 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.245.226 with HTTP; Thu, 16 Nov 2017 13:46:11 -0800 (PST) From: Reed Wilson Date: Thu, 16 Nov 2017 13:46:11 -0800 Message-ID: To: caml-list@inria.fr Content-Type: multipart/alternative; boundary="94eb2c194a0672350c055e208cbc" X-Validation-by: cedilla@gmail.com Subject: [Caml-list] Subtyping (or something like it) --94eb2c194a0672350c055e208cbc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable A while ago, I made a module which basically extended bigarrays with a few more functions. However, I wanted to have a distinction between read-only and read-write values. The equivalence with bigarrays was irrelevant, so my interface just looked like this: type ro type rw type 'a t val read_only : 'a t -> ro t val get : 'a t -> int -> int val put : rw t -> int -> int -> unit ... Basically, any function that wrote to the type would have to take a "rw t", but anything else would take " 'a t". From what I know about C, "ro" behaves like the "const" qualifier - not water-proof but it catches some of my common mistakes. Now, however, I want to re-export the equivalence between 'a t and bigarrays (mostly for the .{} operator), but also have the read-only/read-write distinction. The problem is that if I write: type 'a t =3D (int, int8_unsigned_elt, c_layout) Array1.t then OCaml will see that "ro t" and "rw t" are the same and freely let me use "ro t" values in, for example, the "put" function above. To summarize, is there a way to make two types internally represented by bigarrays, the first of which: * can use the bigarray functions (specifically .{} ) * can use all of my new functions and the second type * can't use bigarray functions * can only use a subset of my new functions I don't want to have two different versions of each function that I have to keep track of. Thanks, Reed Wilson --=20 =C3=A7 --94eb2c194a0672350c055e208cbc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
A while ago, I= made a module which basically extended bigarrays with a few more functions= . However, I wanted to have a distinction between read-only and read-write = values. The equivalence with bigarrays was irrelevant, so my interface just= looked like this:

type ro
type rw
t= ype 'a t
val read_only : 'a t -> ro t
val ge= t : 'a t -> int -> int
val put : rw t -> int -&g= t; int -> unit
...

Basically, any fun= ction that wrote to the type would have to take a "rw t", but any= thing else would take " 'a t". From what I know about C, &quo= t;ro" behaves like the "const" qualifier - not water-proof b= ut it catches some of my common mistakes.

Now, how= ever, I want to re-export the equivalence between 'a t and bigarrays (m= ostly for the .{} operator), but also have the read-only/read-write distinc= tion. The problem is that if I write:
type 'a t =3D (int, int= 8_unsigned_elt, c_layout) Array1.t

then OCaml will= see that "ro t" and "rw t" are the same and freely let= me use "ro t" values in, for example, the "put" functi= on above.

To summarize, is there a way to make two= types internally represented by bigarrays, the first of which:
*= can use the bigarray functions (specifically .{} )
* can use all= of my new functions
and the second type
* can't us= e bigarray functions
* can only use a subset of my new functions<= /div>

I don't want to have two different versions of= each function that I have to keep track of.

Thank= s,
Reed Wilson

--
=C3=A7
--94eb2c194a0672350c055e208cbc--