English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

Browse thread
The "Objective" part of Objective Caml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-11-08 (22:00)
From: Brian Hurt <bhurt@s...>
Subject: Re: Ant: [Caml-list] The "Objective" part of Objective Caml

On Tue, 8 Nov 2005, brogoff wrote:

>> I think I'm with Skaller here- Objects in Ocaml are much less powerfull
>> than they are in (for example) Java or Python.
> They're not "much less powerful" than they are in Java. They certainly lack
> some features of the Java object system, but they posses many others. If
> "powerful" means "supports multiple inheritance", Java is far less powerful.
> If it means "supports" downcasting, ...

Also, the structural typing in Ocaml allows for some neat tricks that are 
basically impossible in Java.

I suppose it depends upon what you mean by "powerful" more or less.  I 
meant it in terms of "widely usefull".  Objects are usefull in Ocaml, but 
you can write large and very complex programs without them.  It's 
impossible to even write "hello, world" in Java without objects.

> As far as static vs dynamic, dynamic type systems are inherently more
> capable. There is no "slack" in a dynamically typed language. But the
> possibility of a runtime exception is of course there.

Yes.  For example, Ocaml will reject this code:
 	let f n =
 		if (n > 0) && (is_prime (2*n)) then
 			"bad idea"

despite the fact that "bad idea" will never, ever be returned (given the 
obvious definition of is_prime, anyways).

But if we restrict ourselves to the domain of correct programs, now I'm 
not so sure.  Well, maybe, in the extreme fringes, there are correct 
programs which are being disallowed by the Ocaml type systems.  I've only 
been programming in Ocaml a couple of years now- I may just have not run 
across them yet.  But everything I've wanted to do in Ocaml I've been able 
to do, working with the type system and not against it.

> The flip side of this is that OCaml is like Perl, with lots of ways to do
> things, and many overlapping features. The fact that OCaml has classes and
> modules is good, and that's how I think OO languages should be, but I would
> expect that protection and hiding be done only by modules and not objects.

To my knowledge, they are.  How do you declare a private or protected 
method for a class variable *without* using modules to do so?