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 KAA27067; Sat, 7 Jun 2003 10:22:22 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 KAA26922 for ; Sat, 7 Jun 2003 10:22:21 +0200 (MET DST) Received: from qrnik.knm.org.pl (paf87.warszawa.sdi.tpnet.pl [217.96.225.87]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h578MKH07545 for ; Sat, 7 Jun 2003 10:22:20 +0200 (MET DST) Received: from localhost ([127.0.0.1] ident=qrczak) by qrnik.knm.org.pl with esmtp (Exim 3.36 #1) id 19OYxv-0003bP-00 for caml-list@inria.fr; Sat, 07 Jun 2003 10:22:19 +0200 From: "Marcin 'Qrczak' Kowalczyk" To: caml-list@inria.fr Subject: Re: [Caml-list] polymorphic type constructor deconstructor Date: Sat, 7 Jun 2003 10:22:19 +0200 User-Agent: KMail/1.5.1 References: <20030606213021.GE27432@crhc.uiuc.edu> <20030606223739.GA28169@crhc.uiuc.edu> In-Reply-To: <20030606223739.GA28169@crhc.uiuc.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 8bit Content-Disposition: inline Message-Id: <200306071022.19345.qrczak@knm.org.pl> X-Spam: no; 0.00; marcin:01 'qrczak':01 kowalczyk:01 qrczak:01 caml-list:01 foo:01 passing:01 int':01 deconstruct:01 dummy:01 int:01 knm:01 polymorphic:01 constructors:01 match:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Dnia sob 7. czerwca 2003 00:37, Jeffrey J. Cook napisał: > I would like to simplify this into a function taking a type constructor > of type 'reply' and a type constructed value of type 'reply' and return > the contents of the type constructed value, such as (int * int) from > Foo of int * int. This function would internally have a match statement > and throw an exception if its not of the right type constructor. I see no other way than writing these functions manually. Just write them once and use them instead of passing constructors. BTW, the contents of 'REPLY_do_that of successlevel * int' is two things separately, not a pair. You can't match against 'Reply_do_that p'. Similarly for construction. > The only solution, using this approach, that I can think of, is by passing > a dummy constructed value, and pattern matching it against the real > constructed value, throwing an exception if it isn't of the right > constructor, otherwise decontructing the value and returning the data > within. There is no need for dummy values. Just write a matching function for each constructor manually. It's not that painful and there is no good other way anyway. > So, is there any way to polymorphically deconstruct a type constructed > value, which is type safe by providing either a dummy constructed value or > a dummy constructor? What type would such a deconstructor have? -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ ------------------- 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