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
Re: Looking for a nail
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-01-29 (08:50)
From: Markus Mottl <mottl@m...>
Subject: Re: Looking for a nail
> Yes, I'd be interested to see a really convincing use of the utility of the
> OO features, e.g. a program or library which is manifestly shorter, cleaner
> and/or simpler when expressed with OO rather than the core features.  I
> guess people can take this as a challenge if they like :-)  I'm open to be
> convinced - but I'm not convinced yet.

Imagine that all basic types were classes and all of them would support
a method e.g. "print". Than you could do the following:

  let print x = x # print
  List.iter print [3; "hello"; 3.14; ["yeah, another list!"]]

or you want to map various objects to strings:

  let to_string x = x # to_string to_string [some_object; another_object; 7; 2.7172]

Some (general) complex stuff you can do with OO (send some messages to
all objects in a container - they do not necessarily have to be members
of the same class, they only share parts of interfaces):

  ASet.iter (fun x -> x#simplify; x#factorize; x#calculate_question 42) s

If you want, I show you a zillion similar constructs, which IMHO make
life *significantly* more comfortable...

I already use this where I can, but if basic types were classes, the first
two examples would also work. There is probably hardly any program, where
you wouldn't need such constructs. Although modules are a great means of
abstraction, show me how you can do such (very readable) things with them.

When I began using the OO features, I rewrote some program to use classes
instead of (algebraic) types. The code not only became much more readable,
but it is much easier to maintain - adding new features takes (in my
experience) far less time.

Best regards,

Markus Mottl,,