From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA25792; Fri, 27 Jun 2003 23:29:12 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 XAA25565 for ; Fri, 27 Jun 2003 23:29:11 +0200 (MET DST) Received: from mail.speakeasy.net (mail13.speakeasy.net [216.254.0.213]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h5RLTAf09504 for ; Fri, 27 Jun 2003 23:29:10 +0200 (MET DST) Received: (qmail 21997 invoked from network); 27 Jun 2003 21:15:08 -0000 Received: from unknown (HELO grace.speakeasy.org) ([216.254.0.2]) (envelope-sender ) by mail13.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 27 Jun 2003 21:15:08 -0000 Date: Fri, 27 Jun 2003 14:15:08 -0700 (PDT) From: brogoff@speakeasy.net To: Shaddin Doghmi cc: "caml-list@inria.fr" Subject: Re: [Caml-list] syntax of private constructors in CVS version In-Reply-To: <3EFCAE16.8060609@mitre.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam: no; 0.00; brogoff:01 caml-list:01 matchings:01 ledit:01 3.06:01 val:01 struct:01 snap:99 printf:01 bin:01 ocaml:01 caml:01 speakeasy:01 sig:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 27 Jun 2003, Shaddin Doghmi wrote: > From the CVS version changes file, under language features: > > - Support for "private types", or more exactly concrete data types > with private constructors or labels. These data types can be > de-structured normally in pattern matchings, but values of these > types cannot be constructed directly outside of their defining module. > > What is the syntax for those? is there some kind of documentation on the > CVS server, like a development version of the manual or something? No documents are available yet. Check out the following: bpr@granite[bpr]$ ledit ~/bin/ocaml Objective Caml version 3.06+36 (2003-06-19) # type t = private { x : int; y : int } ;; type t = private { x : int; y : int; } # type ('a, 'b) choice = private L of 'a | R of 'b;; type ('a, 'b) choice = private L of 'a | R of 'b # let p0 = { x = 0; y = 0 } ;; One cannot create values of the private type t # module Point2D : sig type t = private { x : int; y : int } val grid : int val mkPoint : int -> int -> t end = struct type t = { x : int; y : int } let grid = 10 let snap i = let rem = i mod grid in if rem <= 0 then i - rem else i - rem + grid let mkPoint x y = { x = snap x; y = snap y } end;; module Point2D : sig type t = private { x : int; y : int; } val grid : int val mkPoint : int -> int -> t end # open Point2D;; # match mkPoint 5 5 with { x = x; y = y } -> Printf.printf "(%d, %d)\n" x y;; (10, 10) - : unit = () -- Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners