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

Re: "ocaml_beginners"::[] Re: Objects

Expand Messages
  • Brian Hurt
    ... OK, I m going to engage in a little language advocacy here, but as it s pro-Ocaml advocacy it s probably OK for this group. Also, it highlights some
    Message 1 of 15 , Jun 5, 2005
      On Sun, 5 Jun 2005, Steven Johnson wrote:

      >>
      >>
      >> In Java, having "everything" as an object leads to huge numbers of
      >> runtime checks and very few static checks.
      >>
      >
      > Well, I see this as a failing of Java-the-language rather than object
      > models in general. In particular, a good generics system would do
      > wonders towards this. (I understand that Java 1.5 has added this in some
      > form, but haven't yet had an opportunity to try it out.)

      OK, I'm going to engage in a little language advocacy here, but as it's
      pro-Ocaml advocacy it's probably OK for this group. Also, it highlights
      some features of Ocaml, so I'm sneaking in that way.

      Ocaml's style of objects is radically different from Java's. To pick an
      example not at random, say you have two different classes (types) of
      objects. I have class foo, defined (in Ocaml) with the signature:
      class foo : object
      method f : int -> int
      end

      And then I have class bar:
      class bar : object
      method f : int -> int
      method g : float -> float
      end

      In Java, an object of type bar can be typecast to an object of type foo
      only if class bar explicitly inherits from foo (or implements foo, if foo
      is an interface). The fact that bar provides every function, everything
      it needs to be a foo, it's not a foo unless explicitly stated to be a foo.

      This is quite often a problem when bar is comming in from some library you
      don't have control over, but which you want to define a new subclass for.
      This is supposedly one of the advantages of dynamically typed languages,
      is it allows you to pull tricks like this.

      Ocaml, on the other hand, uses a structural definition of objects. An
      object is of type X if it implements the entire interface X requires.
      This means that in the above case, bars can always be used as foos, even
      if bar isn't explicitly defined as being a foo. Thus Ocaml has the
      advantage of being able to "add" superclasses to an object after the fact.

      But this advantage does come at a cost- all member functions of objects
      are always virtual, there is no such thing as a static or final member
      function. So a lot of uses objects get put to in a language like Java
      they don't work for in Ocaml. For example, Singletons are hard to
      implement with objects in Ocaml. That's OK, though, because Ocaml gives
      you other means of doing the same thing. For singletons, for example,
      Ocaml's modules work really well. Use the right tool for the job.

      As such, I don't think you could take Ocaml's theory of objects and make
      it into a language that has OO as it's central paradigm (and keep the
      strong static type checking).

      Brian
    • Richard Jones
      ... We need someone to fill in the details on this page: http://wiki.cocan.org/getting_started_with_ocaml_on_windows ... I think you ll find most people on
      Message 2 of 15 , Jun 6, 2005
        On Sun, Jun 05, 2005 at 05:39:35PM -0700, Steven Johnson wrote:
        > Can anyone point me at (or contribute) a more-detailed Windows-oriented
        > setup instruction for OCaml? Some do exist but in very sketchy detail.

        We need someone to fill in the details on this page:

        http://wiki.cocan.org/getting_started_with_ocaml_on_windows

        > (I realize that this list is heavily Unix/Linux-oriented, but please
        > don't suggest that I switch to that instead... I barely have time to
        > learn a new language, much less a new OS :-)

        I think you'll find most people on this list seem to use Linux. Try
        and grab a Knoppix live CD. It boots and runs off the CD so you don't
        even need to install Linux to try it out:
        http://www.knopper.net/knoppix/index-en.html

        Does anyone know of a Knoppix variant which includes OCaml tools?

        Rich.

        --
        Richard Jones, CTO Merjis Ltd.
        Merjis - web marketing and technology - http://merjis.com
        Team Notepad - intranets and extranets for business - http://team-notepad.com
      • Radu Grigore
        ... The livecd for icfp2005 :) But, if I remember correctly (I don t have the cd right now), only the compiler and _perhaps_ an emacs mode are installed.
        Message 3 of 15 , Jun 6, 2005
          --- Richard Jones <rich@...> wrote:

          > Does anyone know of a Knoppix variant which includes OCaml tools?

          The livecd for icfp2005 :)
          But, if I remember correctly (I don't have the cd right now), only
          the compiler and _perhaps_ an emacs mode are installed.

          regards,
          radu




          __________________________________
          Discover Yahoo!
          Use Yahoo! to plan a weekend, have fun online and more. Check it out!
          http://discover.yahoo.com/
        Your message has been successfully submitted and would be delivered to recipients shortly.