From: Jeremy Yallop <yallop@gmail.com>
To: Kenichi Asai <asai@is.ocha.ac.jp>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Labels at the module level?
Date: Tue, 23 Jun 2015 09:43:08 +0100 [thread overview]
Message-ID: <CAAxsn=Gf+Kp+K+OBF65N_6CN4Lf1v-4WC0harO8jUhj0eb46hA@mail.gmail.com> (raw)
In-Reply-To: <20150623082651.GA5301@pllab.is.ocha.ac.jp>
On 23 June 2015 at 09:26, Kenichi Asai <asai@is.ocha.ac.jp> wrote:
> Using labeled arguments, one can supply default values for unspecified
> arguments:
>
> let f ?(x = 3) y = x * y
> in f 5
>
> will return 15 without specifying the value of x at the second line.
> Is there a way to do a similar thing at the module level? Namely, I
> want to define a functor that accepts a module of sig:
>
> module type A_t = sig
> val x : int
> val y : int
> end
>
> but if the user did not specify some of the values in the signature,
> some default values will be used.
>
> Background: in the universe library for OCaml:
>
> http://pllab.is.ocha.ac.jp/~asai/Universe/
>
> one specifies various handlers for events (such as tick, mouse, and
> key events). Currently, these handlers are registered to the big_bang
> function that accepts them using labeled arguments (with default
> values). I wonder if I can specify the interface as a module
> signature and let the user write a module of that signature but only
> those handlers that the user is interested in.
Alain Frisch once had a patch to add exactly what you're asking for as
a language feature:
http://alain.frisch.fr/soft.html#patches (Scroll to 'optional
fields in modules')
http://alain.frisch.fr/info/patch-option-announce
In the absence of such a feature, one approach is to use 'include' to
provide the defaults:
module M
include M_defaults
let y = 3
end
Jeremy.
next prev parent reply other threads:[~2015-06-23 8:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-23 8:26 Kenichi Asai
2015-06-23 8:43 ` Jeremy Yallop [this message]
2015-06-23 8:46 ` Benjamin Greenman
2015-06-24 0:25 ` Kenichi Asai
2015-06-26 8:12 ` Ben Millwood
2015-06-23 8:50 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='CAAxsn=Gf+Kp+K+OBF65N_6CN4Lf1v-4WC0harO8jUhj0eb46hA@mail.gmail.com' \
--to=yallop@gmail.com \
--cc=asai@is.ocha.ac.jp \
--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