Am Samstag, den 27.08.2011, 18:59 +0200 schrieb David Baelde:
> On Sat, Aug 27, 2011 at 5:06 PM, Gerd Stolpmann <[email protected]> 
> wrote:
> > I think it is a non-issue in practice. Simply because inheritance is
> > quite seldom in Ocaml, even in programs using a lot of OO features.
> 
> Perhaps the issue is the reason why we don't use more OO in OCaml?
> That kind of problem did bit us once. It's particularly dangerous when
> combined with recursive methods -- when you override, it breaks
> recursion.

Right, but as noted, you can easily live without inheritance in OCaml.

I can only speculate why OO is not that much used in OCaml. I've got the
impression that the "disliked" feature is not object-orientation as
such, but the structural typing (which includes polymorphic variants,
which I also see rarely). I guess the biggest problem is that structural
typing does not offer much for getting information hiding - once a
method is public, it is fully public. This is, in some sense, against
the mindset of the typical OCaml programmer. Second, there are practical
difficulties - sometimes very long error messages (1000 lines and more),
and surprising weak spots in the type checker (e.g. when a method has
optional arguments). OO is definitely nothing for OCaml beginners.

Nevertheless, I think that there are very good examples of OO in OCaml.
For instance, any kind of I/O device or I/O processor - which usually
profit a lot from dynamic binding and subtyping, and for which
information hiding is not an issue (you communicate with the system).
For this reason there is a lot of OO in OCamlnet. Strange enough, I
count as "OO guy" in the OCaml scene, although I don't use it much
outside the context of I/O operations.

Let me reformulate your question: We should better ask which OO design
patterns are still adequate in OCaml. Obviously, many textbook design
patterns feel strange in OCaml - the language has simply better
alternatives. The remaining interesting cases seem to always use dynamic
binding and optionally subtyping.

Gerd
> 
> David
> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    [email protected]
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
*** Searching for new projects! Need consulting for system
*** programming in Ocaml? Gerd Stolpmann can help you.
------------------------------------------------------------


-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to