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 CAA23851; Sun, 11 Apr 2004 02:03:35 +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 CAA23862 for ; Sun, 11 Apr 2004 02:03:34 +0200 (MET DST) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3B04Sjq022871 for ; Sun, 11 Apr 2004 02:04:30 +0200 Received: from [192.168.1.200] (ppp116-94.lns1.syd2.internode.on.net [150.101.116.94]) by smtp3.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i3B03JvM013517; Sun, 11 Apr 2004 09:33:20 +0930 (CST) Subject: Re: [Caml-list] Fwd: Polymorphic optional label argument, with default From: skaller Reply-To: skaller@users.sourceforge.net To: Gerd Stolpmann Cc: Richard Jones , caml-list In-Reply-To: <1081636807.24595.88.camel@ice.gerd-stolpmann.de> References: <20040410213616.GA28863@redhat.com> <1081636807.24595.88.camel@ice.gerd-stolpmann.de> Content-Type: text/plain Message-Id: <1081641798.20677.294.camel@pelican> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 11 Apr 2004 10:03:18 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 gerd:01 stolpmann:01 2004:99 'int:01 unsound:01 9660:01 glebe:01 int:01 int:01 nsw:01 labels:01 labels:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 236 On Sun, 2004-04-11 at 08:40, Gerd Stolpmann wrote: > On Sam, 2004-04-10 at 23:36, Richard Jones wrote: > > I have a function defined: > > > > let plot ?(labels = string_of_int) graph = > > (* ... *) > > > > The idea of the optional 'labels' argument is to specify a polymorphic > > function 'a -> string which is used to print labels stored in the > > 'graph' argument. > > > This does not work. If "plot" were not specialised to int labels, you > could call > > plot string_graph Now hang on! Let's suppose we have a type 'a graph and we want: plot g to work if g is type 'int graph'. On the other hand if g is type float graph, it fails and we can write plot ~labels:string_of_float g We could also write plot ~labels:polyprint g for any graph type, where polyprint:'a -> string would likely print the label's physical address -- since that's about all a polymorphic print could do .. unless it's an int. That can be determined at run time. It seems to me there's nothing unsound here, but that doesn't mean we can do it .. I'd actually make the default polyprint. That way you can print any graph, and if you desire you can add a print routine specialised to the label type. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- 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