From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 4CAA8BC40 for ; Fri, 29 Oct 2004 00:37:00 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i9SMaxUI007416 for ; Fri, 29 Oct 2004 00:36:59 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA11943 for ; Fri, 29 Oct 2004 00:36:59 +0200 (MET DST) Received: from mail1.speakeasy.net (mail1.speakeasy.net [216.254.0.201]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i9SMavxK007400 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 29 Oct 2004 00:36:58 +0200 Received: (qmail 12181 invoked from network); 28 Oct 2004 22:36:56 -0000 Received: from shell1.speakeasy.net ([69.17.110.70]) (envelope-sender ) by mail1.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 28 Oct 2004 22:36:56 -0000 Date: Thu, 28 Oct 2004 15:36:55 -0700 (PDT) From: brogoff To: "Harrison, John R" Cc: caml-list Subject: Re: [Caml-list] Pattern matching but no construction? In-Reply-To: <012676D607FCF54E986746512C22CE7D01FF2E0B@orsmsx407> Message-ID: References: <012676D607FCF54E986746512C22CE7D01FF2E0B@orsmsx407> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 4181748B.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41817489.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 ocaml:01 recursive:01 constructors:01 constructors:01 sig:01 bool:01 val:01 val:01 struct:01 bool:01 sig:01 caml-list:01 beginner's:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: private types do exactly what you want. How lucky. See where I inserted private below, that should do it. On Thu, 28 Oct 2004, Harrison, John R wrote: > Is there a way to use the OCaml module system to declare an > abstract type with an implementation as a recursive type in > such a way that: > > * You can use the constructors to pattern-match against > > * You cannot use the constructors to construct values > > For example, suppose I do the following: > > module type Wibble = > sig type thing = Integer of int | Boolean of bool ^ --- private > val mk_thing : int -> thing > val dest_thing: thing -> int > end;; > > module Thing : Wibble = struct > type thing = Integer of int | Boolean of bool > let mk_thing i = Integer i > let dest_thing t = match t with > Integer i -> i > | Boolean b -> if b then 1 else 0 > end;; > > include Thing;; > > I can now define functions by pattern-matching, which I want: > > fun (Boolean b) -> b;; > > but I can also use the constructors to construct, which I don't: > > Integer(3);; > > On the other hand, if I change the signature to just > > module type Wibble = > sig type thing > val mk_thing : int -> thing > val dest_thing: thing -> int > end;; > > then I can do neither. Is there any way to get one and not the > other? > > John. > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >