Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: patrick@watson.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Typing of default arguments
Date: Mon, 19 Feb 2001 09:01:46 +0900	[thread overview]
Message-ID: <20010219090146V.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <Pine.BSF.3.96.1010217150159.72507G-100000@fledge.watson.org>

From: Patrick M Doane <patrick@watson.org>

> Any thoughts about the restriction of polymorphism that can happen when
> using default arguments? It is still annoying that d' fails to type-check.
> 
> I would assume that the function could be type-checked as if the default
> argument did not exist, and then type-check the default value against the
> signature of the function for consistency.
> 
> This strategy would then give f and f' these types:
> 
>    val f  :  g:('a -> 'b) -> 'a -> 'b
>    val f' : ?g:('a -> 'b) -> 'a -> 'b

Since the default value for g is (fun x -> x), when g is omitted 'a =
'b should be enforced.
Otherwise, (fun x -> f' x) would be of the magic type ('a -> 'b),
which is certainly not what you are asking for.
Enforcing such a conditional equation is possible, but this would
means yet another extension to the type system:

    val f' : ?g:('a -> 'b ?= 'c -> 'c) -> 'a -> 'b

meaning that the default value for g has type 'c -> 'c.
Two problems: is it really worth it (you are not the first one to ask
for that, but would this improve a lot programming style?), and what
are the consequences. In particular it would probably mean more
polymorphic types at places where you do not really need them,
requiring more type annotations to make them readable.

    Jacques
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


      reply	other threads:[~2001-02-19  0:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-16  1:54 Patrick M Doane
2001-02-17  7:15 ` Pierre Weis
2001-02-17 20:07   ` Patrick M Doane
2001-02-19  0:01     ` Jacques Garrigue [this message]

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=20010219090146V.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=patrick@watson.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