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 TAA24715; Fri, 29 Aug 2003 19:04:02 +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 TAA19773 for ; Fri, 29 Aug 2003 19:04:01 +0200 (MET DST) Received: from manzanita (63-217-154-71.greystoneapts.com [63.217.154.71]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7TH40T24442 for ; Fri, 29 Aug 2003 19:04:00 +0200 (MET DST) Received: from manzanita ([127.0.0.1] helo=ucdavis.edu) by manzanita with esmtp (Exim 3.36 #1 (Debian)) id 19smdC-0000LL-00 for ; Fri, 29 Aug 2003 10:01:50 -0700 Message-ID: <3F4F86FE.2080202@ucdavis.edu> Date: Fri, 29 Aug 2003 10:01:50 -0700 From: Issac Trotts Reply-To: ijtrotts@ucdavis.edu User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030319 Debian/1.3-3 X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphic graph widget problem References: <20030829115446.GA879@redhat.com> In-Reply-To: <20030829115446.GA879@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; issac:01 trotts:01 ijtrotts:01 caml-list:01 widget:01 graphing:01 floats:01 floats:01 widget:01 lablgtk:01 plots:01 gobj:01 generalise:01 gobj:01 int':01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk If you'll only be graphing ints and floats, why not just use floats and cast to them? To support both, you could try this: type number = Int of int | Float of float class chart : ... number array -> (* the data being plotted *) object method repaint : Gdk.Rectangle.t option -> unit end It might also help to think of the array as a map from ints to floats. Then you could write this instead: class chart : ... (int * int * (int -> float)) -> (* x0, x1, the data being plotted *) object method repaint : Gdk.Rectangle.t option -> unit end - ijt Richard Jones wrote: >As part of a project I'm doing at the moment, I've written a Gtk graph >widget using lablgtk. The graph currently plots ints, so the type >looks something like this: > >class chart : > ?width:int -> > ?height:int -> > ?packing:(GObj.widget -> unit) -> > ?show:bool -> > int array -> (* the data being plotted *) > object > method repaint : Gdk.Rectangle.t option -> unit > end > >All fine, but now I'd like to generalise this so it can plot floating >point values as well as int, thus: > >class ['a] chart : > ?width:int -> > ?height:int -> > ?packing:(GObj.widget -> unit) -> > ?show:bool -> > 'a array -> (* the data being plotted *) > object > method repaint : Gdk.Rectangle.t option -> unit > end > >The problem with this is that at various places in the implementation >we need to break the polymorphism. eg. To plot Y labels we call >'string_of_int', and to work out the height of the Y axis we do some >sums on the values using the (+) operator. > >What I need is some way to isolate the parts which break the >polymorphism. How do I do that? > >Rich. > > > ------------------- 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