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 TAA00621; Thu, 5 Apr 2001 19:39:40 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA00260 for caml-list@pauillac.inria.fr; Thu, 5 Apr 2001 19:39:40 +0200 (MET DST) 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 UAA17687 for ; Wed, 4 Apr 2001 20:47:39 +0200 (MET DST) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f34Ilcr28213 for ; Wed, 4 Apr 2001 20:47:38 +0200 (MET DST) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id f34Ilbq23562 ; Wed, 4 Apr 2001 20:47:37 +0200 (CEST) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.9.2/jb-1.1) id UAA05606 ; Wed, 4 Apr 2001 20:47:37 +0200 (MET DST) Date: Wed, 4 Apr 2001 20:47:37 +0200 (MET DST) From: Alain Frisch To: Chris Hecker cc: caml-list@inria.fr Subject: Re: [Caml-list] variant with tuple arg in pattern match? In-Reply-To: <4.3.2.7.2.20010404034802.0334fae0@shell16.ba.best.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, On Wed, 4 Apr 2001, Chris Hecker wrote: > I expected ii to be bound to the int * int tuple (1,2) in this pattern match: > > # type foo = Foo of int * int;; > type foo = Foo of int * int You define Foo to be a constructor with two arguments ... (the star here is not the same as the one for tuple types) > # match Foo (1,2) with Foo ii -> ii ;; and you use it as an unary constructor. Hence the error: > Characters 23-29: > The constructor Foo expects 2 argument(s), > but is here applied to 1 argument(s) The solution is to declare: type foo = Foo of (int * int) The drawback is that the internal representation of the value Foo (1,2) uses two heap allocated blocks (one for the constructor, one for the tuple). A flat representation, as is the case with your declaration, may be more efficient, but then you have to explicitely reconstruct the tuple: match Foo (1,2) with Foo (a,b) -> (a,b);; The issue probably deserves a few words in the FAQ or in the manual. Hope this helps. -- Alain Frisch ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr