From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 1262C7EEEF for ; Tue, 23 Jun 2015 10:46:43 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of blg59@cornell.edu) identity=pra; client-ip=209.85.217.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="blg59@cornell.edu"; x-sender="blg59@cornell.edu"; x-conformance=sidf_compatible Received-SPF: Neutral (mail3-smtp-sop.national.inria.fr: domain of blg59@cornell.edu does not assert whether or not 209.85.217.174 is permitted sender) identity=mailfrom; client-ip=209.85.217.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="blg59@cornell.edu"; x-sender="blg59@cornell.edu"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-lb0-f174.google.com) identity=helo; client-ip=209.85.217.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="blg59@cornell.edu"; x-sender="postmaster@mail-lb0-f174.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AQBAD2G4lVlK7ZVdFbFoJfb18GgxioFQEGXQSCPI5aghmFeAIogRMHTAEBAQEBARIBAQEBBwsLCR8whBoIAQEBAwESEUsLBQsLCw0NEA0CAiEBEgEFAQoSGRIQhVGCJwMKCA2pAT4xiz+QVQMKRwGFJQEBAQcBAQEBAQEcCoYShS6CTYI1BAeCaA+BNAWFWgqGLIUUglkChFiFGIFhgXyMN4JqhU4SI4EVEQaCGxyBbiIxAYJHAQEF X-IPAS-Result: A0AQBAD2G4lVlK7ZVdFbFoJfb18GgxioFQEGXQSCPI5aghmFeAIogRMHTAEBAQEBARIBAQEBBwsLCR8whBoIAQEBAwESEUsLBQsLCw0NEA0CAiEBEgEFAQoSGRIQhVGCJwMKCA2pAT4xiz+QVQMKRwGFJQEBAQcBAQEBAQEcCoYShS6CTYI1BAeCaA+BNAWFWgqGLIUUglkChFiFGIFhgXyMN4JqhU4SI4EVEQaCGxyBbiIxAYJHAQEF X-IronPort-AV: E=Sophos;i="5.13,664,1427752800"; d="scan'208";a="137456272" Received: from mail-lb0-f174.google.com ([209.85.217.174]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Jun 2015 10:46:41 +0200 Received: by lbnk3 with SMTP id k3so2164820lbn.1 for ; Tue, 23 Jun 2015 01:46:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc:content-type; bh=0EqWSRMmlVSmqnCo5MtYKBEzI+uODyw4Ayc6zFJ6URI=; b=MYqS41fTINzE1sLkF4LAihRhOMGKOzZYyyfHu6d3XbTcokYyrrW9fJptLQrRgfDRgq BXGKdoiHN28QY0PrhPLDqRT2Up8FysSPgu7tziv0kHcey2M6cldlen+vM+CPMMwPMJ7n JWtFPKQi4XH3y5UF2jEUdiBrH7ZG4ks9wwF7Awku6IUHfaYvB0npYVbB0f0IhmY/CIKk 6p+76Qi86V3l8UMqXkdqIeBnqanS2FLPVaRejzYa9fpgWZUzKkVpotaCL4Us6H6DrZlq YycztTlRA4kCbDpM4i19LQAB29F52km+A77fk2TIR9rvRCyB94Rh9jtegIwYjaWj3JGr JJtQ== X-Gm-Message-State: ALoCoQmbgXIvvQinxvximePI3maaohBkSZd92WJJbC72BylUDVmxcF9SKZslSGGmERV6lNvWyHO+ X-Received: by 10.152.2.2 with SMTP id 2mt18767948laq.58.1435049200528; Tue, 23 Jun 2015 01:46:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.14.40 with HTTP; Tue, 23 Jun 2015 01:46:21 -0700 (PDT) In-Reply-To: References: <20150623082651.GA5301@pllab.is.ocha.ac.jp> From: Benjamin Greenman Date: Tue, 23 Jun 2015 04:46:21 -0400 Message-ID: Cc: Kenichi Asai , Caml List Content-Type: multipart/alternative; boundary=089e013c6470d54ced05192b6d4d Subject: Re: [Caml-list] Labels at the module level? --089e013c6470d54ced05192b6d4d Content-Type: text/plain; charset=UTF-8 Instead of making a functor, you could try a first-class module: module type Person = sig val name : string val age : int end let make_person ?(name="anon") (age : int) : (module Person) = (module struct let name = name let age = age end) On Tue, Jun 23, 2015 at 4:43 AM, Jeremy Yallop wrote: > On 23 June 2015 at 09:26, Kenichi Asai 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. > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --089e013c6470d54ced05192b6d4d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Instead of making a functor, you could try a first-class m= odule:

module t= ype Person =3D sig
=C2= =A0 val name : string
= =C2=A0 val age : int
e= nd

let = make_person ?(name=3D"anon") (age : int) : (module Person) =3D
=C2=A0 (module struct
=C2=A0 =C2=A0 let name = =3D name
=C2=A0 =C2=A0= let age =3D age
=C2= =A0 end)

On Tue, Jun 23, 2015 at 4:43 AM, Jeremy Yallop <yallop@g= mail.com> wrote:
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 =3D 3) y =3D 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?=C2=A0 Namely= , I
> want to define a functor that accepts a module of sig:
>
> module type A_t =3D sig
>=C2=A0 =C2=A0val x : int
>=C2=A0 =C2=A0val 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).=C2=A0 Currently, these handlers are registered to the big= _bang
> function that accepts them using labeled arguments (with default
> values).=C2=A0 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:

=C2=A0 =C2=A0 =C2=A0http://alain.frisch.fr/soft.html#patches= =C2=A0 =C2=A0(Scroll to 'optional
fields in modules')
=C2=A0 =C2=A0 =C2=A0http://alain.frisch.fr/info/pat= ch-option-announce

In the absence of such a feature, one approach is to use 'include' = to
provide the defaults:

=C2=A0 =C2=A0 module M
=C2=A0 =C2=A0 =C2=A0 include M_defaults
=C2=A0 =C2=A0 =C2=A0 let y =3D 3
=C2=A0 =C2=A0end

Jeremy.

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocam= l_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--089e013c6470d54ced05192b6d4d--