Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Duplicate functionality?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Matt Gushee <matt@g...>
Subject: Re: [Caml-list] Duplicate functionality?
Jon Harrop wrote:

>> On Saturday 22 October 2005 02:04, Stephen Brackin wrote:
>>>>My biggest initial question is why OCaml has both a modules system and
>>>>objects: Aren't they different ways of accomplishing the same things?
>> Both modules and objects allow you to encapsulate related
definitions, yes.
>> However, modules are much more static by nature and objects are much
>> dynamic, i.e. you get stronger static checking using modules than you do
>> using objects, giving more comprehensible error messages and more
robust and
>> faster code.

That's certainly true ... I've probably spent twice as much time
debugging type errors in mutually recursive objects as I have on all
other kinds of errors put together.

On the other hand (as Jon's statement implies), it's much easier to
write extensible code with objects. When you call a function on a module
(except within a functor) you are using a specific implementation,
whereas you can call an object method, say foo#display (), where foo can
be any object with a 'display' method that matches the expected type.

And even if modules and objects were functionally equivalent, I think
one of the great things about OCaml is the freedom it gives you to
structure your application in the best way for the problem.

Matt Gushee
Englewood, CO, USA