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 HAA03677; Sun, 11 Apr 2004 07:20:22 +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 HAA03768 for ; Sun, 11 Apr 2004 07:20:20 +0200 (MET DST) Received: from herd.plethora.net (herd.plethora.net [205.166.146.1]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i3B5KIYM018105 for ; Sun, 11 Apr 2004 07:20:19 +0200 Received: from bhurt.plethora.net (bhurt.plethora.net [205.166.146.49]) by herd.plethora.net (8.11.6/8.10.1) with ESMTP id i3B5K9Q23499; Sun, 11 Apr 2004 00:20:12 -0500 (CDT) Date: Sun, 11 Apr 2004 01:26:24 -0500 (CDT) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: Richard Jones cc: caml-list@inria.fr Subject: Re: [Caml-list] Fwd: Polymorphic optional label argument, with default In-Reply-To: <20040410213616.GA28863@redhat.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 beginners:01 api:01 unsubscribed:99 beginners:01 floats:01 passing:01 ocaml:01 ocaml:01 int:01 int:01 labels:01 labels:01 polymorphic:01 polymorphic:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 238 On Sat, 10 Apr 2004, Richard Jones wrote: > Hi: > > I posted the message below originally on ocaml_beginners. There were > many helpful responses, and the general consensus was that this was > not possible, but no one could give a definitive answer. I just > wanted to confirm on the 'grown-ups' list (:-) if this is really true > before I finalise the API I am designing. Hmm. Somehow I've gotten unsubscribed from that list. I should subscribe again. > > Thanks, > > Rich. > > To: ocaml_beginners@yahoogroups.com > From: Richard Jones > Subject: Polymorphic optional label argument, with default > > 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. > > The problem is that because string_of_int is obviously int -> string, > my function is typed as: > > plot : ?labels : (int -> string) -> (* ... int ... *) -> unit > > but I want it to be typed as: > > plot : ?labels : ('a -> string) -> (* ... 'a ... *) -> unit > > [The 'a types are the same type. If I leave out the initializer, then > it works.] > > How to? > I don't think it's possible. Consider the following situation: I pass in a graph of floats for example, and then forget to specify a labels argument. Now you're passing a float to string_of_int. -- "Usenet is like a herd of performing elephants with diarrhea -- massive, difficult to redirect, awe-inspiring, entertaining, and a source of mind-boggling amounts of excrement when you least expect it." - Gene Spafford Brian ------------------- 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