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 VAA15686; Wed, 4 Apr 2001 21:18:50 +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 VAA18027 for ; Wed, 4 Apr 2001 21:18:49 +0200 (MET DST) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f34JImH08971 for ; Wed, 4 Apr 2001 21:18:48 +0200 (MET DST) Received: from localhost (patrick@localhost) by fledge.watson.org (8.11.1/8.11.1) with SMTP id f34JIdx24515; Wed, 4 Apr 2001 15:18:39 -0400 (EDT) (envelope-from patrick@watson.org) Date: Wed, 4 Apr 2001 15:18:38 -0400 (EDT) From: Patrick M Doane 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 Hi Chris, You'll need to change your type declaration from type foo = Foo of int * int to type foo = Foo of (int * int) or type bar = int * int type foo = Foo of bar Caml performs some optimizations on the representation of tuples to place the arguments for the constructor as well as constructor name into one word of memory. This can be a big win, both in memory usage and in access time because one pointer access is removed. It makes this distinction syntactically in the type declarations. In the first case, the memory layout for values of type foo would be: [ tag word | int1 | int2 ] where the second case would be [ tag word | pointer ] -> [ tag word | int1 | int2 ] I would certainly like it if Caml could: 1) Treat this entirely as an optimization issue and not make a syntactic distinction. 2) Be able to make reasonable choices about which representation would be more appropriate. I doubt that it would do as well as the programmer could and it certainly would take a bit of effort without a real clear improvement. On the other hand, left with the syntactic distincation, a possible improvement would be to make a distinction between type foo = Foo of bar and type foo = Foo of (bar) so that "equational reasoning" could hold with regard to type declarations. On several occasions, I have been tempted not to create another type declaration because of this representation issue. Hope this helps Patrick On Wed, 4 Apr 2001, Chris Hecker wrote: > > I can't find anything about this in the docs, faq, or list archives. > > 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 > # match Foo (1,2) with Foo ii -> ii ;; > Characters 23-29: > The constructor Foo expects 2 argument(s), > but is here applied to 1 argument(s) > > > This works: > > # match Foo (1,2) with Foo _ -> () ;; > - : unit = () > > But I can't get an "as" clause to work, either: > > # match Foo (1,2) with Foo ((_,_) as ii) -> ii ;; > Characters 21-38: > The constructor Foo expects 2 argument(s), > but is here applied to 1 argument(s) > > But, even if the "as" worked, it's messy compared to the top method. > > Chris > > ------------------- > To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr > ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr