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=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 19C3FBC6D for ; Thu, 31 Jan 2008 19:12:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAAOeoUeBrw8Eh2dsb2JhbACQIgEBAQgKKZlP X-IronPort-AV: E=Sophos;i="4.25,286,1199660400"; d="scan'208";a="7484031" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 31 Jan 2008 19:12:36 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m0VICZjb027409 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 31 Jan 2008 19:12:35 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAAOeoUeBrw8Eh2dsb2JhbACQIgEBAQgKKZlP X-IronPort-AV: E=Sophos;i="4.25,286,1199660400"; d="scan'208";a="7484030" Received: from ext.lri.fr ([129.175.15.4]) by mail1-smtp-roc.national.inria.fr with ESMTP; 31 Jan 2008 19:12:35 +0100 Received: from localhost (localhost [127.0.0.1]) by ext.lri.fr (Postfix) with ESMTP id 53D42A487C; Thu, 31 Jan 2008 19:12:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lri.fr Received: from ext.lri.fr ([127.0.0.1]) by localhost (ext.lri.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R6-iItrdK9vt; Thu, 31 Jan 2008 19:11:57 +0100 (CET) Received: from smtp.lri.fr (vhost3-23 [129.175.3.23]) by ext.lri.fr (Postfix) with ESMTP id DBE57A488D; Thu, 31 Jan 2008 19:11:57 +0100 (CET) Received: from [129.175.4.128] (lri4-128 [129.175.4.128]) by smtp.lri.fr (Postfix) with ESMTP id CDFE0E04A2; Thu, 31 Jan 2008 19:11:57 +0100 (CET) Message-ID: <47A20FC1.5040103@lri.fr> Date: Thu, 31 Jan 2008 19:13:21 +0100 From: Romain Bardou User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: David Teller Cc: caml-list Subject: Re: [Caml-list] Attach an invariant to a type References: <47a1cd167921b@wp.pl> <47A1D212.3010205@lri.fr> <1201802294.6154.56.camel@Blefuscu> In-Reply-To: <1201802294.6154.56.camel@Blefuscu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 47A20F93.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lri:01 sig:01 val:01 struct:01 ocaml:01 slighly:01 0100,:01 wrote:01 abstract:01 assert:01 caml-list:01 int:01 int:01 module:03 module:03 Wow, how could I forget about private types. However, you still need the of_int function. module Subindex: sig type t = private int val make: int -> t end = struct type t = int let make n = assert (n >= 10 && x <= 100); n end Romain Bardou David Teller a écrit : > Actually, OCaml contains something slighly simpler than this of_int / > to_int mechanism: private types. > > > On Thu, 2008-01-31 at 14:50 +0100, Romain Bardou wrote: > >> 2) (much better imo) use a module with an abstract type, such as: >