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.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 7EB97BC6C for ; Thu, 31 Jan 2008 21:26:51 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAB6+oUdA6aq6mWdsb2JhbACQIgEBAQEBBgQECwgYmAmHcQ X-IronPort-AV: E=Sophos;i="4.25,287,1199660400"; d="scan'208";a="22031473" Received: from rn-out-0910.google.com ([64.233.170.186]) by mail4-smtp-sop.national.inria.fr with ESMTP; 31 Jan 2008 21:26:50 +0100 Received: by rn-out-0910.google.com with SMTP id s46so398554rnb.18 for ; Thu, 31 Jan 2008 12:26:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=jF+/AgWwpUfIKB+svYRfAECBLJ6Gu7w698xDfCVCsNg=; b=Cbu0U7VALW5K4dDru6pG8XX24HGcRPcskX00v0t2xPqZtqDGdSga9q624MqTqevu8Nfi4wFthSw777y+mvmljPYYYMZmRmntOJYqqc1AofyoED40ygQIwv9kscjnPHLzUwZ5OciKQwdoafayM9lzp4jRpltBg9lN5GcM4zFWr64= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=pQ8hzq4cca7+jv7INoxkOLVV3JH8ZjvcEU0Q1Ul4A5+7KyqBh8VpmrEwWSwNGpEF84125I9LvoMtc57nAhbjSVJh1PyEQpzNgf9HCgFuSu7N66xnfjbeeLbhCJf4axX3LzGoWVQJPMyFNlmb07ZCuw1SpPbY1rTY/3pld7HasQk= Received: by 10.142.131.18 with SMTP id e18mr1569826wfd.36.1201811206339; Thu, 31 Jan 2008 12:26:46 -0800 (PST) Received: from ?192.168.0.16? ( [71.149.131.4]) by mx.google.com with ESMTPS id 45sm3551909wri.25.2008.01.31.12.26.43 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 31 Jan 2008 12:26:44 -0800 (PST) Message-ID: <47A22F01.9070404@gmail.com> Date: Thu, 31 Jan 2008 14:26:41 -0600 From: Edgar Friendly User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: Dawid Toton Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Attach an invariant to a type References: <47a1cd167921b@wp.pl> <47A1D212.3010205@lri.fr> <1201802294.6154.56.camel@Blefuscu> <47A20FC1.5040103@lri.fr> <3a360f590801311113o4db1d660s206e7af4bcb3226@mail.gmail.com> <47A226D7.6030108@wp.pl> In-Reply-To: <47A226D7.6030108@wp.pl> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; compilation:01 variants:01 compiler:01 edgar:98 wrote:01 integer:01 integer:01 caml-list:01 constructor:01 int:01 int:01 declaration:02 checking:02 construct:02 construct:02 Dawid Toton wrote: >> I guess that making types like "int" private would require the system >> (among other things) to decide whether you're using a given integer as >> a Subindex.t or not. > > Suppose we have "type t = private int" in module Subindex. > > Is the following construct legal: let (a:Subindex.t) = 2 ? > It shouldn't be - to prevent me from constructing values of this type. > So I couldn't "use given integer as Subinddex.t". > type t = private int isn't legal. Most types get completely erased during compilation, but records and variants have code generated by the compiler based off their type declaration to construct a value of that type. A plain int doesn't have this compiler-generated constructor, so it can't be private in this way. That said, I'd appreciate a simple system to do the kind of checking you want at the site of an explicit typecast. E