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 XAA14875; Fri, 6 Jun 2003 23:30:24 +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 XAA14860 for ; Fri, 6 Jun 2003 23:30:23 +0200 (MET DST) Received: from innsmouth.crhc.uiuc.edu (innsmouth.crhc.uiuc.edu [130.126.141.158]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h56LUMT05874 for ; Fri, 6 Jun 2003 23:30:22 +0200 (MET DST) Received: (from jjcook@localhost) by innsmouth.crhc.uiuc.edu (8.11.6/8.11.6) id h56LULf28102 for caml-list@inria.fr; Fri, 6 Jun 2003 16:30:21 -0500 Date: Fri, 6 Jun 2003 16:30:21 -0500 From: "Jeffrey J. Cook" To: caml-list@inria.fr Subject: [Caml-list] polymorphic type constructor deconstructor Message-ID: <20030606213021.GE27432@crhc.uiuc.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-Spam: no; 0.00; deconstruct:01 failwith:01 val:01 foo:01 enumerating:01 rework:01 int:01 sockets:01 polymorphic:01 checking:01 match:02 modules:02 receive:97 manually:03 annoying:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Is there any way to polymorphically deconstruct a type constructor, thus not requiring a pattern match statement? I am using socket communication between processes and would like to utilize type checking to ensure I always have well-formed messages. Right now I'm doing something like (many more cases of course): type request = REQ_do_this of int | REQ_do_that of int * int type reply = RELPY_do_this of successlevel | REPLY_do_that of successlevel * int and am using input_value and output_value with sockets to send/receive messages. My approach right now requires me to do something similar to: let request = REQ_do_this 5 in let reply = Socket.client "mysocket" request in let success = match reply with | REPLY_do_this x -> x | _ -> failwith "this case shouldn't happen and is annoying" however, I would like to do something more like: let request = REQ_do_this(5) in let success = deconstruct (REPLY_do_this(socket_send request)) in where the polymorphic 'deconstruct' declaration is: val deconstruct : 'a -> 'b Where 'a is a type constructed type such as type foo = Bar of int * int and thus 'b is of type (int * int) My complication is that I have multiple sets of request and reply types in different modules which I would like to deconstruct without duplicating the function, not to meantion not manually enumerating all types and their straightforward deconstruction. Any ideas on how to do or rework to avoid this? Thanks. Jeff -- Jeffrey J. Cook Graduate Student, Electrical Engineering University of Illinois at Urbana-Champaign jjcook@uiuc.edu ------------------- 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