From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: Alain.Frisch@ens.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Type inference + optional parameters
Date: Sat, 06 Sep 2003 09:53:34 +0900 [thread overview]
Message-ID: <20030906095334H.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <Pine.SOL.4.44.0309031007140.14812-100000@clipper.ens.fr>
From: Alain.Frisch@ens.fr
> On Wed, 3 Sep 2003, Jacques Garrigue wrote:
> > From: Christoph Bauer <c_bauer@informatik.uni-kl.de>
> >
> > > ocamls type inference uses information of optionl arguments. This
> > > results in a strange behaviour.
> >
> > Brian Rogoff already answered this one. Do you seriously expect a
> > type-safe compiler to simply ignore the type of the default value :-)
>
> I guess the original question is not that naive. It would be possible to
> have a type system with an extension like your multimatch, to make the
> type of the result of a function depend on the presence/absence of
> optional argument.
>
> With a crazy syntax to express conditional unification constraints, you
> could write for instance:
>
> do_with_opt_conv: ?conv:('a -> 'b orelse 'b = 'a) -> 'a -> 'b
>
> meaning that in the absence of the optional argument, the result type
> must be unified with the argument type (there are more constraints
> when the optional argument is not provided).
>
> Does it make sense ?
It makes sense, and is just a direct consequence of the Default module
I was describing in my mail. I've already considered it 4 years ago,
after a comment for Wolfram Kahl.
However, if you let this behaviour be active with all default
parameters, you end up with overly general types; usually you expect
the concrete argument to be of the same type as the default.
Moreover, there may be hidden pitfalls: type incompatibilities you
only detect later, when several optional parameters are omitted
simultaneously.
All in all, I think that this feature is just on the borderline of
practical typing: possible, but the typing is too complex for casual
use, and may result in confusing type errors.
In some cases being explicit simplifies lots of things...
Jacques Garrigue
-------------------
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
next prev parent reply other threads:[~2003-09-06 0:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-02 16:20 Christoph Bauer
2003-09-02 17:06 ` brogoff
2003-09-03 2:08 ` Jacques Garrigue
2003-09-03 8:08 ` Alain.Frisch
2003-09-06 0:53 ` Jacques Garrigue [this message]
2003-09-03 9:56 ` Michal Moskal
[not found] <m3fzjf825m.fsf@diebuntekuh.de>
2003-09-02 19:01 ` brogoff
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=20030906095334H.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=Alain.Frisch@ens.fr \
--cc=caml-list@inria.fr \
/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