caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <bhurt@spnz.org>
To: Richard Jones <rich@annexia.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Fwd: Polymorphic optional label argument, with default
Date: Sun, 11 Apr 2004 01:26:24 -0500 (CDT)	[thread overview]
Message-ID: <Pine.LNX.4.44.0404110124260.25700-100000@localhost.localdomain> (raw)
In-Reply-To: <20040410213616.GA28863@redhat.com>

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 <rich@annexia.org>
> 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


  parent reply	other threads:[~2004-04-11  5:20 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
2004-04-10 23:52 ` Matt Gushee
2004-04-11  6:26 ` Brian Hurt [this message]
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=Pine.LNX.4.44.0404110124260.25700-100000@localhost.localdomain \
    --to=bhurt@spnz.org \
    --cc=caml-list@inria.fr \
    --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).