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

Use "with type" with functorial signatures

Expand Messages
  • Chantal Keller
    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
    Message 1 of 4 , Jun 2, 2014
    • 0 Attachment
      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.
    • Philippe Veber
      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
      Message 2 of 4 , Jun 2, 2014
      • 0 Attachment
        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

        <*> To visit your group on the web, go to:
            http://groups.yahoo.com/group/ocaml_beginners/

        <*> Your email settings:
            Individual Email | Traditional

        <*> To change settings online go to:
            http://groups.yahoo.com/group/ocaml_beginners/join
            (Yahoo! ID required)

        <*> To change settings via email:
            ocaml_beginners-digest@yahoogroups.com
            ocaml_beginners-fullfeatured@yahoogroups.com

        <*> To unsubscribe from this group, send an email to:
            ocaml_beginners-unsubscribe@yahoogroups.com

        <*> Your use of Yahoo Groups is subject to:
            https://info.yahoo.com/legal/us/yahoo/utos/terms/


      • Gabriel Scherer
        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
        Message 3 of 4 , Jun 2, 2014
        • 0 Attachment
          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
          >>
          >>
          >>
          >
          >
          >
          >
        • Chantal Keller
          Many thanks! Chantal. Le 02/06/2014 17:05, Gabriel Scherer gabriel.scherer@gmail.com
          Message 4 of 4 , 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
            >>>
            >>>
            >>>
            >>
            >>
            >>
            >>
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.