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 RAA13033; Fri, 19 Sep 2003 17:22: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 RAA11443 for ; Fri, 19 Sep 2003 17:22:55 +0200 (MET DST) Received: from cetus.henchmonkey.org (p67-70.acedsl.com [66.114.67.70]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8JFMsj29946 for ; Fri, 19 Sep 2003 17:22:55 +0200 (MET DST) Received: from katre by cetus.henchmonkey.org with local (Exim 3.36 #1 (Debian)) id 1A0N5w-00084W-00; Fri, 19 Sep 2003 11:22:52 -0400 Date: Fri, 19 Sep 2003 11:22:52 -0400 To: Richard Jones Cc: caml-list@inria.fr Subject: Re: [Caml-list] Subclasses and pattern matching Message-ID: <20030919152252.GA30989@henchmonkey.org> References: <20030919142156.GA30187@henchmonkey.org> <20030919145220.GD4205@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030919145220.GD4205@redhat.com> User-Agent: Mutt/1.5.4i From: katre X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 model:01 ints:01 int:01 int:01 match:02 match:02 float:02 float:02 subclasses:02 complex:03 wrote:03 constructor:03 inheritance:03 types:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Richard Jones wrote: > > Possibly I'm being dumb here, but wouldn't it be better to use > a union type, eg: > > type num = Int of int | Float of float > Yes, except for two facts: a) Each different type has different data available (some are ints, some strings, some more complex) b) Each different type has a lot of data. I don't really want to specify a 10-member tuple for each constructor :) c) Where the data is used, I want to match two or three different types, and then call a default method with anything left over. With a union, I have to deal with every possible type, or do nothing with the data. To clarify, using your type above, I can't do match n with Int(i) -> print_int i | _ -> print_int some_data_from_n Remember, all of my structures have many more than 1 piece of data. A class inheritance really is the best way to model the data structure, I just want to be able to pattern match on it. katre ------------------- 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