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

module seems like class

Expand Messages
  • Z
    Hello, I have a very naive question here. Some ocaml users regard module of ocaml as package of Java. But I am wondering why cannot we think module of ocaml as
    Message 1 of 3 , Aug 5, 2010
    • 0 Attachment
      Hello,

      I have a very naive question here.

      Some ocaml users regard module of ocaml as package of Java. But I am
      wondering why cannot we think module of ocaml as class of Java ??

      Thank you for your ideas.

      Z


      [Non-text portions of this message have been removed]
    • Sylvain Le Gall
      Hello, ... Some ideas: Classes are data structures + related methods. Modules can be almost anything. You can have relationship between classes (inherit) and
      Message 2 of 3 , Aug 6, 2010
      • 0 Attachment
        Hello,

        On 06-08-2010, Z <zell08v@...> wrote:
        >
        > I have a very naive question here.
        >
        > Some ocaml users regard module of ocaml as package of Java. But I am
        > wondering why cannot we think module of ocaml as class of Java ??
        >
        > Thank you for your ideas.
        >

        Some ideas:

        Classes are data structures + related methods. Modules can be almost
        anything.

        You can have relationship between classes (inherit) and subtype them
        (i.e. an Orange is a Fruit). You cannot do this with module.

        Regards
        Sylvain Le Gall
      • Ashish Agarwal
        You cannot instantiate a module. In one way, Java classes are more like type declarations in OCaml. A class represents a new type of object, and you can create
        Message 3 of 3 , Aug 6, 2010
        • 0 Attachment
          You cannot instantiate a module. In one way, Java classes are more like type
          declarations in OCaml. A class represents a new type of object, and you can
          create specific objects that are instances of that class. Similarly you can
          define a new type in OCaml and have specific values of that type.

          However, classes are also used to organize code and keep related definitions
          together. In this regard, classes are like modules.

          The benefit of OCaml's design is it lets you separate these two design
          issues: which types you want, and how to modularize your code. Classes
          couple these issues.


          On Fri, Aug 6, 2010 at 12:17 AM, Z <zell08v@...> wrote:

          >
          >
          > Hello,
          >
          > I have a very naive question here.
          >
          > Some ocaml users regard module of ocaml as package of Java. But I am
          > wondering why cannot we think module of ocaml as class of Java ??
          >
          > Thank you for your ideas.
          >
          > Z
          >
          > [Non-text portions of this message have been removed]
          >
          >
          >


          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.