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

Re: Implementing a nested signature

Expand Messages
  • Remi Vanicat
    ... when you do SDM writes: module Bob : O = struct [....] you are creating a module (Bob) with signature (O). That is nothing that is
    Message 1 of 17 , Feb 12, 2008
    • 0 Attachment
      > Hmm, what's the reason for that? I would like to be able to call the
      > functions of Bob.Inner.

      when you do
      "SDM" <s_david_m@...> writes:

      module Bob : O =
      struct
      [....]

      you are creating a module (Bob) with signature (O). That is
      nothing that is not in the signature O won't be visible outside of
      Bob. Including any submodule Bob might have.

      Submodule are part of the module, as are type and value. So if you
      want them accessible outside, you need to declare them in the
      signature.



      --
      Rémi Vanicat
    • SDM
      ... So in a sense, a signature seals a module, so even if you try to use the module directly, only those definitions present in the signature are publicly
      Message 2 of 17 , Feb 13, 2008
      • 0 Attachment
        --- In ocaml_beginners@yahoogroups.com, Remi Vanicat
        > module Bob : O =
        > struct
        > [....]
        >
        > you are creating a module (Bob) with signature (O). That is
        > nothing that is not in the signature O won't be visible outside of
        > Bob. Including any submodule Bob might have.

        So in a sense, a signature "seals" a module, so even if you try to use
        the module directly, only those definitions present in the signature
        are publicly visible?

        SDM
      • Remi Vanicat
        ... yes. At least outside the module, inside it (even inside submodule of it) every thing is visible. By the way I see no other way to use a module than
        Message 3 of 17 , Feb 13, 2008
        • 0 Attachment
          "SDM" <s_david_m@...> writes:

          > --- In ocaml_beginners@yahoogroups.com, Remi Vanicat
          >> module Bob : O =
          >> struct
          >> [....]
          >>
          >> you are creating a module (Bob) with signature (O). That is
          >> nothing that is not in the signature O won't be visible outside of
          >> Bob. Including any submodule Bob might have.
          >
          > So in a sense, a signature "seals" a module, so even if you try to use
          > the module directly, only those definitions present in the signature
          > are publicly visible?

          yes. At least outside the module, inside it (even inside submodule of
          it) every thing is visible.

          By the way I see no other way to use a module than "directly", so may
          be one of us is overlooking something here.

          --
          Rémi Vanicat
        • SDM
          ... Thanks for the help everyone. I knew it could be expressed, but I was having trouble fitting my OCaml hat back on. ;-) Here s the final version: module
          Message 4 of 17 , Feb 13, 2008
          • 0 Attachment
            --- In ocaml_beginners@yahoogroups.com, Remi Vanicat
            <remi.vanicat@...> wrote:
            >
            > yes. At least outside the module, inside it (even inside submodule of
            > it) every thing is visible.
            >
            > By the way I see no other way to use a module than "directly", so may
            > be one of us is overlooking something here.

            Thanks for the help everyone. I knew it could be expressed, but I was
            having trouble fitting my OCaml hat back on. ;-)

            Here's the final version:

            module type Pair =
            sig
            module O :
            sig
            type t
            val read : t -> string
            val make : unit -> t
            end

            module B :
            sig
            type t
            val make : O.t -> t
            val compile : t -> string -> O.t -> unit
            end
            end;;

            (* provides both O and B *)
            module Bob : Pair =
            struct
            module O =
            struct
            type t = out_channel
            let make u = stdout
            let read x = "dummy string"
            let write x s = output_string x s
            end

            module B =
            struct
            type t = O.t
            let make x = x
            let compile log source output =
            O.write log "compiling log"; (* can access Bob's write function *)
            O.write output "writing cc output"
            end
            end;;

            # let bobo = Bob.O.make () in
            let b = Bob.B.make bobo in
            Bob.B.compile b "foo" bobo;;
            compiling logwriting cc output- : unit = ()


            So Bob.B has full access to the Bob.O definition, ie. Bob.O's write
            function. I was trying to demonstrate that a "confused deputy" is
            expressible using ML modules just as it can be expressed using Java's
            package scoping [1]. Thanks again!

            SDM

            [1] http://www.eros-os.org/pipermail/cap-talk/2008-February/009867.html
          • Oliver Bandel
            ... [...] But ONLY, when providing a narrowed signature via the module type you talked about. You have mentioned this, but IMHO noe clear enough emphasized
            Message 5 of 17 , Feb 13, 2008
            • 0 Attachment
              Zitat von Remi Vanicat <remi.vanicat@...>:

              > "SDM" <s_david_m@...> writes:
              >
              > > --- In ocaml_beginners@yahoogroups.com, Remi Vanicat
              > >> module Bob : O =
              > >> struct
              > >> [....]
              > >>
              > >> you are creating a module (Bob) with signature (O). That is
              > >> nothing that is not in the signature O won't be visible outside of
              > >> Bob. Including any submodule Bob might have.
              > >
              > > So in a sense, a signature "seals" a module, so even if you try to
              > use
              > > the module directly, only those definitions present in the
              > signature
              > > are publicly visible?
              >
              > yes. At least outside the module, inside it (even inside submodule of
              > it) every thing is visible.
              [...]

              But ONLY, when providing a narrowed signature
              via the module type you talked about.

              You have mentioned this, but IMHO noe clear enough emphasized this.

              The default signature would show all inside residing modules too.
              Onkly the signature, provided to narrow the default signature
              makes things invisible outside.

              You both talked about throwing out the signature type out of the
              module itself. But do not throw away the outside module type ;-)

              So, this is nothing new in the discussion,
              but a hint to explain it more clear.

              Ciao,
              Oliver
            Your message has been successfully submitted and would be delivered to recipients shortly.