Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Fwd: Polymorphic optional label argument, with default
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: [Caml-list] Fwd: Polymorphic optional label argument, with default

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.



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?

Richard Jones.
Merjis Ltd. - improving website return on investment
Perl4Caml lets you use any Perl library in your type-safe Objective
CAML programs.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: