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 QAA25040; Fri, 29 Aug 2003 16:30:36 +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 QAA29042 for ; Fri, 29 Aug 2003 16:30:34 +0200 (MET DST) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7TEUWT10755 for ; Fri, 29 Aug 2003 16:30:32 +0200 (MET DST) Received: (qmail 10837 invoked by uid 566); 29 Aug 2003 13:30:03 -0000 Date: Fri, 29 Aug 2003 15:27:15 +0200 From: Michal Moskal To: Richard Jones Cc: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphic graph widget problem Message-ID: <20030829132715.GA13304@roke.freak> Mail-Followup-To: Richard Jones , caml-list@inria.fr References: <20030829115446.GA879@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030829115446.GA879@redhat.com> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 widget:01 widget:01 lablgtk:01 plots:01 gobj:01 generalise:01 gobj:01 int':01 generics:01 michal:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, Aug 29, 2003 at 12:54:46PM +0100, 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? Put this 'a array inside an object with string_of_int and (+) functions. Then parametrize chart with 'a, where 'a :> that object. Finally provide functions to embed int array (or float array) in this kind of object. You can also try to wait for generics to fix this problem. -- : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h ------------------- 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