From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 9B1B9BC40 for ; Thu, 28 Oct 2004 23:34:55 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9SLYtT0006128 for ; Thu, 28 Oct 2004 23:34:55 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA09727 for ; Thu, 28 Oct 2004 23:34:54 +0200 (MET DST) Received: from orsfmr001.jf.intel.com (fmr12.intel.com [134.134.136.15]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9SLYrGq006122 for ; Thu, 28 Oct 2004 23:34:54 +0200 Received: from talaria.jf.intel.com (talaria.jf.intel.com [10.7.209.7]) by orsfmr001.jf.intel.com (8.12.9-20030918-01/8.12.9/d: major-outer.mc,v 1.15 2004/01/30 18:16:28 root Exp $) with ESMTP id i9SLZbi0014259 for ; Thu, 28 Oct 2004 21:35:37 GMT Received: from orsmsxvs041.jf.intel.com (orsmsxvs041.jf.intel.com [192.168.65.54]) by talaria.jf.intel.com (8.12.9-20030918-01/8.12.9/d: major-inner.mc,v 1.11 2004/07/29 22:51:53 root Exp $) with SMTP id i9SLRsa4002013 for ; Thu, 28 Oct 2004 21:28:06 GMT Received: from orsmsx331.amr.corp.intel.com ([192.168.65.56]) by orsmsxvs041.jf.intel.com (SAVSMTP 3.1.2.35) with SMTP id M2004102814344907390 for ; Thu, 28 Oct 2004 14:34:49 -0700 Received: from orsmsx407.amr.corp.intel.com ([192.168.65.50]) by orsmsx331.amr.corp.intel.com with Microsoft SMTPSVC(6.0.3790.0); Thu, 28 Oct 2004 14:34:49 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Pattern matching but no construction? Date: Thu, 28 Oct 2004 14:34:49 -0700 Message-ID: <012676D607FCF54E986746512C22CE7D01FF2E0B@orsmsx407> Thread-Topic: Pattern matching but no construction? Thread-Index: AcS9NfPQTXetigiqSwuW2gzRc+kFQQ== From: "Harrison, John R" To: "caml-list" X-OriginalArrivalTime: 28 Oct 2004 21:34:49.0907 (UTC) FILETIME=[F413C830:01C4BD35] X-Scanned-By: MIMEDefang 2.31 (www . roaringpenguin . com / mimedefang) X-Miltered: at nez-perce with ID 418165FF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 418165FD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; johnh:01 ocaml:01 recursive:01 constructors:01 constructors:01 sig:01 bool:01 val:01 val:01 struct:01 bool:01 sig:01 abstract:01 integer:01 integer: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: 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 =3D sig type thing =3D Integer of int | Boolean of bool val mk_thing : int -> thing val dest_thing: thing -> int end;; module Thing : Wibble =3D struct type thing =3D Integer of int | Boolean of bool let mk_thing i =3D Integer i let dest_thing t =3D 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 =3D 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.