Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: nadji <nadji@noos.fr>
To: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
Cc: rich@annexia.org, caml-list@inria.fr
Subject: Re: [Caml-list] Fwd: Polymorphic optional label argument, with default
Date: Sun, 11 Apr 2004 17:23:14 +0200	[thread overview]
Message-ID: <200404111723.14238.nadji@noos.fr> (raw)
In-Reply-To: <20040411221619G.garrigue@kurims.kyoto-u.ac.jp>

Le Sunday 11 April 2004 15:16, Jacques Garrigue a écrit :
> Basically, what you are asking for is a new type of constraint, which
> is only to be applied when the optional argument is omitted (and as
> result the default is selected).
> This is not possible in the current type system, and while there are
> some uses for that, it would be hard to justify making types more
> complex in the general case, just to handle this specific problem.
I would like to point out that a machinery to handle this problem
is guarded recursive datatypes proposed by Xi. It is a framework
that solves a bunch of other problems and is compatible with ml type
system (there is currently at Inria a student working on an Ocaml integration 
of this type system).
Combining it with your labeled parameters leads to a well typed code
analogous to your phantom-type based solution. Some even view
Xi's GRDT as a way to avoid your Obj.magic when matching against 
a phantom type. 
For those interested, the pseudo code would be something like :

guarded 'a opt = Omit with 'a = int | Arg of 'a->unit
let plot : ?(labels:'a opt) -> 'a graph -> unit =
  fun ?(labels=Omit) g ->
  let printing_labels : 'a -> unit = 
     match labels with 
       Omit -> print_int
    | Arg x -> x
  in
  ... printing_labels node_label ...

Nadji

-------------------
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 15:22 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
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 [this message]
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=200404111723.14238.nadji@noos.fr \
    --to=nadji@noos.fr \
    --cc=caml-list@inria.fr \
    --cc=garrigue@kurims.kyoto-u.ac.jp \
    --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