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 KAA11249; Sun, 11 Apr 2004 10:34:00 +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 KAA10829 for ; Sun, 11 Apr 2004 10:33:59 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3B8Yujq030889 for ; Sun, 11 Apr 2004 10:34:56 +0200 Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 1BCaPe-0001Qo-00 for ; Sun, 11 Apr 2004 09:33:58 +0100 Date: Sun, 11 Apr 2004 09:33:58 +0100 Cc: caml-list@inria.fr Subject: Re: [Caml-list] Fwd: Polymorphic optional label argument, with default Message-ID: <20040411083357.GA19305@redhat.com> References: <20040410213616.GA28863@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.5.1+cvs20040105i From: Richard Jones 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 2004:99 floats:01 passing:01 compile-time:01 endline:01 val:01 foo:01 val:01 endline:01 api:01 team's:01 ltd:98 ints:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 242 On Sun, Apr 11, 2004 at 01:26:24AM -0500, Brian Hurt wrote: > > 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. I'd want this to generate a compile-time error, because the 'a 's aren't the same. It's perfectly possible to define this function if one leaves out the default argument, or sets the default argument to a function typed as 'a -> string. # let plot ~labels graph = print_endline (labels graph);; val plot : labels:('a -> string) -> 'a -> unit = or: # let string_of_any x = "foo";; val string_of_any : 'a -> string = # let plot ?(labels = string_of_any) graph = print_endline (labels graph);; val plot : ?labels:('a -> string) -> 'a -> unit = But not if I want the default to be the most common case (which is that my graph will be a graph of ints). I want the common case in there so that most of the time end users of the API won't need to worry about ~labels and optional arguments. Rich. -- Richard Jones. http://www.annexia.org/ http://www.j-london.com/ Merjis Ltd. http://www.merjis.com/ - improving website return on investment 'There is a joke about American engineers and French engineers. The American team brings a prototype to the French team. The French team's response is: "Well, it works fine in practice; but how will it hold up in theory?"' ------------------- 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