From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=AWL,DNS_FROM_SECURITYSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 9A8E1BB84 for ; Thu, 30 Oct 2008 22:54:49 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsUAANfJCUlRZ90vkWdsb2JhbACKGIlzAQEBAQkLCgcRA7gGg1E X-IronPort-AV: E=Sophos;i="4.33,518,1220220000"; d="scan'208";a="16691993" Received: from mtaout01-winn.ispmail.ntl.com ([81.103.221.47]) by mail2-smtp-roc.national.inria.fr with ESMTP; 30 Oct 2008 22:54:49 +0100 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20081030215445.ZWTO21227.mtaout01-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com>; Thu, 30 Oct 2008 21:54:45 +0000 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout02-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20081030215445.EXEX21638.aamtaout02-winn.ispmail.ntl.com@romulus.metastack.com>; Thu, 30 Oct 2008 21:54:45 +0000 Received: from countertenor (dynamic86.vpdn.csx.cam.ac.uk [131.111.7.86]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id m9ULsaHb020145 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Thu, 30 Oct 2008 21:54:38 GMT From: "David Allsopp" To: "=?iso-8859-1?Q?'Daniel_B=FCnzli'?=" , "'OCaml List'" References: <340C8DB35D244173AE527238DB359A19@countertenor> <04092D60-3BB6-49A6-8A04-0BFE3A2081BD@erratique.ch> Subject: RE: [Caml-list] Private types Date: Thu, 30 Oct 2008 22:54:34 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <5687D906367C49F981398A97A5966E09@countertenor> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <04092D60-3BB6-49A6-8A04-0BFE3A2081BD@erratique.ch> Thread-Index: Ack6zuI7QMFk/5UgQXuYpq/88j+A1gABsQgg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Scanned-By: MIMEDefang 2.64 on 81.102.132.74 X-Cloudmark-Analysis: v=1.0 c=1 a=ZOzjf2MOAAAA:8 a=XfKI61SxSpU1a97sVXQA:9 a=aFKq6IcXYFwopgPM2IAA:7 a=zPMzU_CVUH6uPIUBKtCrkBg-Q98A:4 a=oltf0pfCdT4A:10 X-Spam: no; 0.00; bunzli:01 substituted:01 ocaml:01 ocaml:01 integers:01 abbreviation:01 gotchas:01 compiler:01 optimise:01 mutable:01 wrote:01 abstract:01 ints:01 ints:01 caml-list:01 Daniel B=FCnzli wrote: > Le 30 oct. 08 =E0 21:18, David Allsopp a =E9crit : > > > Shouldn't I now be able to say: > > > > string_of_int x;; > > I don't think so. According to the manual [1] the only thing you can =20 > do on private types is pattern match or project their fields. I =20 > doesn't mean your type can be substituted by int. Strictly speaking the manual says that you can't construct values = directly (you can construct other values which contain private types, though, so = it's not limited to pattern matching or projection). > > [1] http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#htoc99 Thanks for this - although it's a link to an OCaml 3.10 manual so not applicable here it did point me to the correct chapter in the OCaml 3.11 manual (I'd been looking in Part I of the manual and given up). What I should have written is string_of_int (x :> int) Though that does make me wonder why the coercion is mandatory. What = happens if I *want* to allow the use of M.t values as though they were ints and = only want to guarantee that they come from a specific sub-set of the integers (I'm thinking of database row IDs which is what I want to use them for)? Assuming that the type abbreviation doesn't contain type-variables, = would there be anything theoretically preventing the inclusion of two = keywords: type t =3D private int (* can be used as though it were an int *) type t =3D very_private int (* requires a coercion to be used an int *) Or are there some very obvious programming gotchas that I'm missing if = the need to write the coercion were relaxed? The important point to me would seem to be that if I say: x + 1 then I get the *int* 1 and not the *M.t* value 1. As it stands, I can't = see a huge amount of difference, given that you have to write the coercion everywhere, between a fully abstract type and a function M.getValue : t = -> int and a private int type. (I'm assuming that if M.getValue is defined as %identity then the = compiler would optimise out the calls to it... of course if that isn't the case = than private ints are already one stage better!) And one final thought - given that you can't assign to mutable members = of private record types, isn't a bit strange that you can change the = contents of private string values? Wouldn't having type t =3D private string = where character access is not possible give some people the immutable strings they've been asking for in the past? David