caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Gerd Stolpmann <info@gerd-stolpmann.de>
Cc: Richard Jones <rich@annexia.org>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Fwd: Polymorphic optional label argument, with default
Date: 11 Apr 2004 10:03:18 +1000	[thread overview]
Message-ID: <1081641798.20677.294.camel@pelican> (raw)
In-Reply-To: <1081636807.24595.88.camel@ice.gerd-stolpmann.de>

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


  reply	other threads:[~2004-04-11  0:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-10 21:36 Richard Jones
2004-04-10 22:40 ` Gerd Stolpmann
2004-04-11  0:03   ` skaller [this message]
2004-04-10 23:52 ` Matt Gushee
2004-04-11  6:26 ` Brian Hurt
2004-04-11  8:33   ` Richard Jones
2004-04-11  9:01     ` skaller
2004-04-11 13:16     ` Jacques Garrigue
2004-04-11 15:23       ` nadji
2004-04-12  2:25         ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1081641798.20677.294.camel@pelican \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=info@gerd-stolpmann.de \
    --cc=rich@annexia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).