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 B2E9C7EEEF for ; Tue, 23 Jun 2015 10:43:09 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of yallop@gmail.com) identity=pra; client-ip=209.85.215.45; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of yallop@gmail.com designates 209.85.215.45 as permitted sender) identity=mailfrom; client-ip=209.85.215.45; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; 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-la0-f45.google.com) identity=helo; client-ip=209.85.215.45; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="postmaster@mail-la0-f45.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BFAQC/GolVlC3XVdFbDgiDGTVfBoMYr3qMMYV4AoE7B0wBAQEBAQESAQEBAQcLCwkfMIQjAQEEEhEdARsdAQMMBgULDQICJgICIgERAQUBHAYTIod3AQMSDakBPjGLP4FrgnmLJwoZJw1XhRYBAQEHAQEBARgBBQ6BE4ophQYHgmiBQwWTf4RYhnmBfIw3iDgSI4EMCReCGxyBFD89MQGCRwEBAQ X-IPAS-Result: A0BFAQC/GolVlC3XVdFbDgiDGTVfBoMYr3qMMYV4AoE7B0wBAQEBAQESAQEBAQcLCwkfMIQjAQEEEhEdARsdAQMMBgULDQICJgICIgERAQUBHAYTIod3AQMSDakBPjGLP4FrgnmLJwoZJw1XhRYBAQEHAQEBARgBBQ6BE4ophQYHgmiBQwWTf4RYhnmBfIw3iDgSI4EMCReCGxyBFD89MQGCRwEBAQ X-IronPort-AV: E=Sophos;i="5.13,664,1427752800"; d="scan'208";a="137455614" Received: from mail-la0-f45.google.com ([209.85.215.45]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Jun 2015 10:43:09 +0200 Received: by lagi2 with SMTP id i2so2025508lag.2 for ; Tue, 23 Jun 2015 01:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=K/PaSgb1dIvYmqjsTVh8v9Jy1DbWjrqaKXvegKfm1gY=; b=npNSiN35bUJJy6D3n5ZpIW6zXbJgV9t/yyk8j0LAXrWHYzjafzsHxDF5hrImx9kVuS FaLKa7NLtnoXPMC5SVv2HBcu2ba8n1kcHOd1jTOXsmMj71f04QsloZ1l6XHiF6dD6Jpj e0e/pe+it8urzG3zi3JGJ1f2EJwUPrZDTgt458acyXGI7+OWGm9IMtYJoYWxX7jZ3ONA R5slUL7wKyudEMQZS7S5DSInf2/ZOrRE9dMoULBJVHW9NvthLFzCA1NpKlvHeNue/xkF FQ3WsaxnEoPcJfvPYhDZnTcWB6JBPVLoQiI45I8sGalyzHP4VlJFMJBwoLelQKUPVylI 0A2g== MIME-Version: 1.0 X-Received: by 10.152.5.194 with SMTP id u2mr5461313lau.94.1435048988601; Tue, 23 Jun 2015 01:43:08 -0700 (PDT) Received: by 10.25.169.72 with HTTP; Tue, 23 Jun 2015 01:43:08 -0700 (PDT) In-Reply-To: <20150623082651.GA5301@pllab.is.ocha.ac.jp> References: <20150623082651.GA5301@pllab.is.ocha.ac.jp> Date: Tue, 23 Jun 2015 09:43:08 +0100 Message-ID: From: Jeremy Yallop To: Kenichi Asai Cc: Caml List Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Labels at the module level? 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.