From: Alain Frisch <alain@frisch.fr>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>,
David Allsopp <dra-news@metastack.com>
Cc: OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] GADT in an optional parameter
Date: Fri, 19 Jul 2013 12:37:59 +0200 [thread overview]
Message-ID: <51E91707.60002@frisch.fr> (raw)
In-Reply-To: <37C2C45C-A317-408E-8545-4FD426E3C817@math.nagoya-u.ac.jp>
On 07/19/2013 08:59 AM, Jacques Garrigue wrote:
> val find : ?mode:(('s,'t) wrap = Exn) -> string -> 's Map.Make(String).t -> 't
>
> It would be good to see whether this has many applications.
The idea would be to have a different kind of optional argument, which
specifies as part of the function type an expression to be expanded
syntactically on the call site when the argument is not provided
explicitly. (In your example, the Exn constructor would need to be
available from the call site. -- Or do you interpret "Exn" as a typed
reference to the Exn constructor on the value declaration site?)
If we assume that the "default" can be an arbitrary "parse tree"
(untyped) expression, I guess that type equality would require these
expressions to be strictly equal (modulo locations).
This could have several interesting usages:
- Passing the "identity" function as a continuation, or a GADT to
customize the return type.
- Implicit arguments, capturing an identifier from the scope of the
call site:
let rec eval ??(env = env) x =
...
| ... -> eval y (* pass "env" implicitly *)
| ... -> eval env' z
- Implement the implicit passing of "runtime type representations":
let variant ??(t : 'a ty = (type of _)) (x : 'a) = ....
or of values synthesized by -ppx rewriters on the call site:
let debug ??(loc = [%self_loc]) x =
Format.eprintf "%a %s@." pp_loc loc x
(this uses the syntax of extension nodes in the extension_points
branch, and assumes that the call site will be processed with a -ppx
rewriter which substitutes a value representing the current location in
the source code for the [%self_loc] extension node.)
Alain
next prev parent reply other threads:[~2013-07-19 10:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-18 14:03 David Allsopp
2013-07-19 6:59 ` Jacques Garrigue
2013-07-19 10:37 ` Alain Frisch [this message]
2013-07-19 16:33 ` Gabriel Scherer
2013-07-25 9:31 ` David Allsopp
2013-07-25 12:11 ` Alain Frisch
2013-07-19 9:05 ` oleg
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=51E91707.60002@frisch.fr \
--to=alain@frisch.fr \
--cc=caml-list@inria.fr \
--cc=dra-news@metastack.com \
--cc=garrigue@math.nagoya-u.ac.jp \
/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