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 <yallop@gmail.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 = 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