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: 2004-04-11 (00:03)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Fwd: Polymorphic optional label argument, with default
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,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language

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