Loading ...
Sorry, an error occurred while loading the content.

14061Re: "ocaml_beginners"::[] Use "with type" with functorial signatures

Expand Messages
  • Chantal Keller
    Jun 2, 2014
    • 0 Attachment
      Many thanks!
      Chantal.



      Le 02/06/2014 17:05, Gabriel Scherer gabriel.scherer@...
      [ocaml_beginners] a écrit :
      > You can express this with a functor returning the signature. You'll
      > have to provide an implementation for the functor in the corresponding
      > .ml (if there is a .ml), but it is trivial.
      >
      > module type BAR = sig
      > type t
      > end
      >
      > module FooS : functor (Bar:BAR) -> sig
      > module type Sig = sig
      > type u
      > type t = Bar.t
      > end
      > end
      >
      > module type Foo = functor (Bar:BAR) -> FooS(Bar).Sig
      > module Make : functor (Bar:BAR) -> (FooS(Bar).Sig with type u = string)
      >
      > On Mon, Jun 2, 2014 at 4:57 PM, Philippe Veber
      > philippe.veber@... [ocaml_beginners]
      > <ocaml_beginners@yahoogroups.com> wrote:
      >>
      >>
      >> Hi Chantal,
      >>
      >> Not sure you can have what you want, in particular I expected the following
      >> to work
      >>
      >> module type BAR = sig
      >> type t
      >> end
      >>
      >> module type FOO = functor (Bar:BAR) -> sig
      >> type u
      >> type t = Bar.t
      >> end
      >> module Make(Foo:FOO)(Bar:BAR) : Foo(Bar) with type u = string
      >>
      >> but it does not:
      >>
      >> Error: Ill-typed functor application Foo(Bar)
      >>
      >> The closest I can see is this:
      >>
      >> module type BAR = sig
      >> type t
      >> end
      >>
      >>
      >> module type FOO = sig
      >> type u
      >> type t
      >> end
      >>
      >> module Make(Bar:BAR) : FOO with type u = string and type t = Bar.t
      >>
      >> This is already an advanced question, I suggest you ask on the caml-list.
      >>
      >> Philippe.
      >>
      >>
      >>
      >> 2014-06-02 16:09 GMT+02:00 Chantal Keller chantal.keller@...
      >> [ocaml_beginners] <ocaml_beginners@yahoogroups.com>:
      >>
      >>> Dear OCaml users,
      >>>
      >>> In a .mli file, I can write the following:
      >>>
      >>>
      >>> module type BAR = sig
      >>> type t
      >>> end
      >>>
      >>> module type FOO = functor (Bar:BAR) -> sig
      >>> type u
      >>> type t = Bar.t
      >>> end
      >>>
      >>> module Make : FOO
      >>>
      >>>
      >>> but I would like to specialize the last line to express the following
      >>> idea:
      >>>
      >>>
      >>> module Make : FOO with type u = string
      >>>
      >>>
      >>> Is it possible without expanding the signature FOO?
      >>>
      >>> Thanks in advance,
      >>> Chantal.
      >>>
      >>>
      >>> ------------------------------------
      >>> Posted by: Chantal Keller <chantal.keller@...>
      >>> ------------------------------------
      >>>
      >>> Archives up to December 31, 2011 are also downloadable at
      >>> http://www.connettivo.net/cntprojects/ocaml_beginners
      >>> The archives of the very official ocaml list (the seniors' one) can be
      >>> found at http://caml.inria.fr
      >>> Attachments are banned and you're asked to be polite, avoid flames
      >>> etc.Yahoo Groups Links
      >>>
      >>>
      >>>
      >>
      >>
      >>
      >>
      >
    • Show all 4 messages in this topic