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

Re: "ocaml_beginners"::[] How can i avoid the name conflicts of modules in different lib

Expand Messages
  • Richard Jones
    ... Unfortunately the answer is with difficulty . If you have source to the libraries, you could change the name of one or other of the modules. It may also
    Message 1 of 12 , Jan 12, 2005
    • 0 Attachment
      On Wed, Jan 12, 2005 at 04:55:19AM -0000, tuzi737 wrote:
      > How can i avoid the name conflicts of modules in different lib?
      > For example, in lib canlendar there is a module called Printer.
      > But i have another Printer module in another library.
      > How can i avoid the conflicts without rename one of them.

      Unfortunately the answer is "with difficulty". If you have source to
      the libraries, you could change the name of one or other of the
      modules. It may also be possible to link modules together with the
      -pack option, which would change the name of the module from Module to
      Lib.Module.

      Libraries shouldn't really be defining modules with such generic
      names, although I've been guilty of this too.

      Rich.

      --
    • Gilles Dubochet
      Hello everyone, I know that debugging code by adding print statements in the code is not the usual recommended way. But it is often so practical that I am
      Message 2 of 12 , Jan 12, 2005
      • 0 Attachment
        Hello everyone,

        I know that debugging code by adding print statements in the code is
        not the usual recommended way. But it is often so practical that I am
        using it all the time anyway.

        But there still is a problem with this method: for each type I want to
        "debug", I need a (sometimes long) function that transforms it into a
        string. The O'Caml debugger, on the other hand, prints out a nice
        representation of all types automatically. Is there any way to obtain
        a "nice string view" like the debugger's from within the code?

        Thanks for your answers (and please don't flame me for using this debug
        method, I won't change anyway).

        Cheers,
        Gilles Dubochet.
      • Alan Post
        ... A previous thread on the topic: http://thread.gmane.org/gmane.comp.lang.ocaml.beginners/1021
        Message 3 of 12 , Jan 12, 2005
        • 0 Attachment
          In article <BD29BDEE-64D1-11D9-A4A4-000A9575E5EA@...>, Gilles Dubochet wrote:
          >
          > But there still is a problem with this method: for each type I want to
          > "debug", I need a (sometimes long) function that transforms it into a
          > string. The O'Caml debugger, on the other hand, prints out a nice
          > representation of all types automatically. Is there any way to obtain
          > a "nice string view" like the debugger's from within the code?

          A previous thread on the topic:

          http://thread.gmane.org/gmane.comp.lang.ocaml.beginners/1021
        • tuzi737
          ... Oh, really !!! What s a pity. Why ocaml does not arrange namespace like python or java?
          Message 4 of 12 , Jan 12, 2005
          • 0 Attachment
            --- In ocaml_beginners@yahoogroups.com, Richard Jones <rich@a...> wrote:
            > On Wed, Jan 12, 2005 at 04:55:19AM -0000, tuzi737 wrote:
            > > How can i avoid the name conflicts of modules in different lib?
            > > For example, in lib canlendar there is a module called Printer.
            > > But i have another Printer module in another library.
            > > How can i avoid the conflicts without rename one of them.
            >
            > Unfortunately the answer is "with difficulty". If you have source to
            > the libraries, you could change the name of one or other of the
            > modules. It may also be possible to link modules together with the
            > -pack option, which would change the name of the module from Module to
            > Lib.Module.
            >
            > Libraries shouldn't really be defining modules with such generic
            > names, although I've been guilty of this too.
            >

            Oh, really !!!
            What's a pity.
            Why ocaml does not arrange namespace like python or java?
          • Richard Jones
            ... No. That s actually mostly a feature. One of the many things I hated about Java was having to type reams and reams of import uk.co.company.lib.module
            Message 5 of 12 , Jan 13, 2005
            • 0 Attachment
              On Thu, Jan 13, 2005 at 06:27:40AM -0000, tuzi737 wrote:
              >
              >
              > --- In ocaml_beginners@yahoogroups.com, Richard Jones <rich@a...> wrote:
              > > On Wed, Jan 12, 2005 at 04:55:19AM -0000, tuzi737 wrote:
              > > > How can i avoid the name conflicts of modules in different lib?
              > > > For example, in lib canlendar there is a module called Printer.
              > > > But i have another Printer module in another library.
              > > > How can i avoid the conflicts without rename one of them.
              > >
              > > Unfortunately the answer is "with difficulty". If you have source to
              > > the libraries, you could change the name of one or other of the
              > > modules. It may also be possible to link modules together with the
              > > -pack option, which would change the name of the module from Module to
              > > Lib.Module.
              > >
              > > Libraries shouldn't really be defining modules with such generic
              > > names, although I've been guilty of this too.
              > >
              >
              > Oh, really !!!
              > What's a pity.
              > Why ocaml does not arrange namespace like python or java?

              No. That's actually mostly a feature. One of the many things I hated
              about Java was having to type reams and reams of "import
              uk.co.company.lib.module" at the top of every file. Of course it does
              break down when two libraries happen to have the same module name, but
              that is reasonably rare.

              Rich.

              --
            • Jerry Charumilind
              ... And tuzi737, remember that nothing stops people from doing the exact same thing in Java. For instance, I can distribute a package named printer if I
              Message 6 of 12 , Jan 13, 2005
              • 0 Attachment
                On Jan 13, 2005, at 10:41 AM, Richard Jones wrote:

                >
                > On Thu, Jan 13, 2005 at 06:27:40AM -0000, tuzi737 wrote:
                >
                >> Oh, really !!!
                >> What's a pity.
                >> Why ocaml does not arrange namespace like python or java?
                >
                > No. That's actually mostly a feature. One of the many things I hated
                > about Java was having to type reams and reams of "import
                > uk.co.company.lib.module" at the top of every file. Of course it does
                > break down when two libraries happen to have the same module name, but
                > that is reasonably rare.

                And tuzi737, remember that nothing stops people from doing the exact
                same thing in Java. For instance, I can distribute a package named
                'printer' if I like, and you would run into the exact same thing.

                Conversely, O'Caml programmers are free to name their modules
                "ComMycompanyUtilPrinter" if they so desire.

                My point is, it's not so much a feature of the language you're talking
                about but just how people name their modules. Names are still scoped
                to their modules, analagously to how names are scoped to classes (or
                packages) in Java. Constrast this with a language like C, where
                scoping stops at the function level. In that case, it is much more of
                an issue with the language. (Hmmm... I wonder if I need a
                flame-retardant suit for that comment :-) ).
              • Nicolas Cannasse
                ... The problem about Java is not really the package feature, which is good, but the stupid and overcomplex naming scheme they re using. Nicolas
                Message 7 of 12 , Jan 13, 2005
                • 0 Attachment
                  > No. That's actually mostly a feature. One of the many things I hated
                  > about Java was having to type reams and reams of "import
                  > uk.co.company.lib.module" at the top of every file. Of course it does
                  > break down when two libraries happen to have the same module name, but
                  > that is reasonably rare.
                  >
                  > Rich.

                  The problem about Java is not really the package feature, which is good, but
                  the stupid and overcomplex naming scheme they're using.

                  Nicolas
                • Karl Zilles
                  ... Frankly, given the choice between typing a few extra characters on an import, and having the possibility a library naming conflict that would require me to
                  Message 8 of 12 , Jan 13, 2005
                  • 0 Attachment
                    Jerry Charumilind wrote:
                    >>>Oh, really !!!
                    >>>What's a pity.
                    >>>Why ocaml does not arrange namespace like python or java?
                    >>
                    >>No. That's actually mostly a feature. One of the many things I hated
                    >>about Java was having to type reams and reams of "import
                    >>uk.co.company.lib.module" at the top of every file. Of course it does
                    >>break down when two libraries happen to have the same module name, but
                    >>that is reasonably rare.

                    Frankly, given the choice between typing a few extra characters on an
                    import, and having the possibility a library naming conflict that would
                    require me to go in and modify library sources, I'll take a little bit
                    of extra typing.

                    >
                    > And tuzi737, remember that nothing stops people from doing the exact
                    > same thing in Java. For instance, I can distribute a package named
                    > 'printer' if I like, and you would run into the exact same thing.

                    But nobody does.

                    >
                    > Conversely, O'Caml programmers are free to name their modules
                    > "ComMycompanyUtilPrinter" if they so desire.

                    But nobody does.

                    > My point is, it's not so much a feature of the language you're talking
                    > about but just how people name their modules. Names are still scoped
                    > to their modules, analagously to how names are scoped to classes (or
                    > packages) in Java. Constrast this with a language like C, where
                    > scoping stops at the function level. In that case, it is much more of
                    > an issue with the language. (Hmmm... I wonder if I need a
                    > flame-retardant suit for that comment :-) ).

                    You're right of course, but since java established a naming convention,
                    and ocaml has not, ocaml ends up with name conflicts, and java does not.

                    It's a problem. Let's not go overboard on the glass half full pollyannaism.
                  • Richard Jones
                    ... Perl seems to get this about right. Most Perl modules exist in a two-level namespace, thus Net::FTPServer, WWW::Mechanize, HTTP::TreeBuilder, IO::stringy,
                    Message 9 of 12 , Jan 13, 2005
                    • 0 Attachment
                      On Thu, Jan 13, 2005 at 05:07:04PM +0100, Nicolas Cannasse wrote:
                      > The problem about Java is not really the package feature, which is good, but
                      > the stupid and overcomplex naming scheme they're using.

                      Perl seems to get this about right. Most Perl modules exist in a
                      two-level namespace, thus Net::FTPServer, WWW::Mechanize,
                      HTTP::TreeBuilder, IO::stringy, etc.

                      Rich.

                      --
                    • Benjamin Geer
                      ... The problem in OCaml is that is that I d like to be able to package and distribute several related modules separately, but put them in a common namespace
                      Message 10 of 12 , Jan 13, 2005
                      • 0 Attachment
                        Jerry Charumilind wrote:
                        > Names are still scoped
                        > to their modules, analagously to how names are scoped to classes (or
                        > packages) in Java.

                        The problem in OCaml is that is that I'd like to be able to package and
                        distribute several related modules separately, but put them in a common
                        namespace (e.g. the name of a project or organisation, as Java does, or
                        an area of functionality like "IO", as Perl does) to avoid conflicts in
                        case other people write modules with the same names. I can't do this,
                        because in order to put them in a namespace I have to put them in an
                        enclosing module, but then I have to package and distribute them all in
                        one lump as part of the enclosing module.

                        The workaround is either to give every module a sufficiently unusual
                        name, or to wrap each one individually in an otherwise useless enclosing
                        module with an unusual name. Not the end of the world, but an annoyance
                        nonetheless.

                        Ben
                      • Richard Jones
                        ... Why put them in the same namespace? In Perl, just because there exist two modules called Net::FTPServer and Net::Daemon doesn t mean that I can do use
                        Message 11 of 12 , Jan 14, 2005
                        • 0 Attachment
                          On Thu, Jan 13, 2005 at 11:35:23PM +0000, Benjamin Geer wrote:
                          >
                          > Jerry Charumilind wrote:
                          > > Names are still scoped
                          > > to their modules, analagously to how names are scoped to classes (or
                          > > packages) in Java.
                          >
                          > The problem in OCaml is that is that I'd like to be able to package and
                          > distribute several related modules separately, but put them in a common
                          > namespace (e.g. the name of a project or organisation, as Java does, or
                          > an area of functionality like "IO", as Perl does) to avoid conflicts in
                          > case other people write modules with the same names. I can't do this,
                          > because in order to put them in a namespace I have to put them in an
                          > enclosing module, but then I have to package and distribute them all in
                          > one lump as part of the enclosing module.

                          Why put them in the same namespace? In Perl, just because there exist
                          two modules called Net::FTPServer and Net::Daemon doesn't mean that I
                          can do "use Net" and get both of them. In fact there is no module
                          called Net, so "use Net" fails. So in Perl, namespaces are in fact
                          quite separate from each other, even if they appear related by name.

                          To imitate the same in OCaml, just use another separator char (not
                          '.') between your top-level and second-level names. For example,
                          it's quite possible to have Merjis_Calendar and Merjis_Private,
                          distributed separately or together as required.

                          Rich.

                          --
                        Your message has been successfully submitted and would be delivered to recipients shortly.