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 CAA19767; Sat, 7 Jun 2003 02:09:56 +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 CAA19849 for ; Sat, 7 Jun 2003 02:09:55 +0200 (MET DST) Received: from mail3.tpgi.com.au (mail.tpgi.com.au [203.12.160.59]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h5709rH20165 for ; Sat, 7 Jun 2003 02:09:53 +0200 (MET DST) Received: from ozemail.com.au (203-219-225-40-syd-ts24-2600.tpgi.com.au [203.219.225.40]) (authenticated (0 bits)) by mail3.tpgi.com.au (8.11.6/8.11.6) with ESMTP id h5709jW03281; Sat, 7 Jun 2003 10:09:46 +1000 Message-ID: <3EE12D48.7040707@ozemail.com.au> Date: Sat, 07 Jun 2003 10:09:44 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: "Jeffrey J. Cook" CC: caml-list@inria.fr Subject: Re: [Caml-list] polymorphic type constructor deconstructor References: <20030606213021.GE27432@crhc.uiuc.edu> <20030606223739.GA28169@crhc.uiuc.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ozemail:01 caml-list:01 combinator:01 'check:99 ocamlp:01 ctor:01 deconstruct:01 camlp:01 toxteth:01 glebe:01 2037,:01 9660:01 0850:01 ocaml:01 handler:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jeffrey J. Cook wrote: > Hmmm, I didn't make much sense, I'll try again. It made sense to me, Felix has such a combinator for internal use called 'case_arg_n', it returns the argument of a the n'th kind of constructor of a union without any run time checking: there's a function 'check_case' that checks if a value is a particular case, so a match on a union type is done by: if (check_case (1, v)) handler1(case_arg_n(1,v)); else if ... I guess an implementation dependent C function could be written which checks Ocaml union tag values. Still, you'd have to manually magic the return type for each case .. OcamlP4 might be able to solve the latter problem so you could write type t = Ctor1 ctor1_arg_t | Ctor2 ... deconstruct(Ctor1, v) which would have type ctor_arg_t as desired. Deconstruct here would call a Camlp4 macro which looked up a table generated from the union declaration for t to find the right argument type, and to calculate the tag index to pass to the C function for the run time check. [I'm assuming in total ignorance the tags are sequential from the same origin for each union declared] -- John Max Skaller, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- 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