caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Real excellent object oriented source code examples of Ocaml
@ 2000-11-17 12:14 STARYNKEVITCH Basile
  2000-11-20 13:46 ` Xavier Leroy
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: STARYNKEVITCH Basile @ 2000-11-17 12:14 UTC (permalink / raw)
  To: caml-list

Hello All,

I am trying to interest a young collegue Franck VEDRINE
<franck.vedrine@cea.fr> to Ocaml-3.00. He is an excellent C++ coder
and a respected young specialist of abstract interpretation (on which
he got a PhD recently -regarding abstract interpretation of C++
code). We are both working in the domain of static analysis of
embedded C code (eg critical C code in nuclear plants or aircrafts)
using abstract interpretation techniques and are supposed to deliver
some working prototype (sadly proprietary) tools on that subject.

Franck wants to see real good Ocaml-3 code using all -or most of- the
fancy advanced object-oriented features (with multiple inheritance,
class types, functors, etc...). And I did not found much of such code
(e.g. OO features are almost unused in the Ocaml compiler).

I am trying to show him that most of the advanced features of C++
(templates, overloading, multiple inheritance) have their equivalent
in Ocaml thru real source code (or that they are less useful, like C++
overloading).

I did not yet convince Franck that functional programming has many
advantages of OO style -at least in our domain of static analysis (on
which Franck is an expert and I am still a newscomer)-. So
I am sticked to exhibit excellent object oriented Ocaml code.

I tried to show the interest of garbage collection by coding a precise
[mostly copying generational, with some finalized marked objects]
garbage collector in C++ (conservative GCs à la Boehm or Barlett was
considered not enough safe at my place at that time). So I would
believe that Franck knows somehow the interest of GC today - and the
possibility of efficient garbage collection in practice.

I initiated on this Ocaml mailing list in july 1999 a very remotely
related thread on the subject "convincing management to switch to
Ocaml" (I did not succeed on that point, but I am still trying....)
see for instance
"http://pauillac.inria.fr/bin/wilma_hiliter/caml-list/199907/msg00055.html?line=3#hilite"


Does any one have a nearly complete list of OO ocaml code? (I know
about LablGtk, and the ocamlopt machine code emitter)

Regards

================================
Court résumé francais: [[short french abstract]]

Bonjour,

je cherche a convaincre un excellent collegue - Franck VEDRINE-
(specialiste de C++ et expert en interpretation abstraite) de l
interet d Ocaml. J ai donc besoin de code source Ocaml d excellente
qualité utilisant toutes (ou la majorité) des possibilites de
programmation orientée objet d Ocaml-3.00. Franck est un jeune
specialiste de l'analyse statique (par interpretation abstraite) de
code -un domaine [analyse statique de code critique en C] où nous
travaillons ensemble mais où je suis encore débutant.

Cordialement


================================


N.B. Any opinions expressed here are only mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.

---------------------------------------------------------------------
Basile STARYNKEVITCH   ----  Commissariat à l Energie Atomique 
DTA/LETI/DEIN/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX * France
phone: 1,69.08.60.55; fax: 1.69.08.83.95 home: 1,46.65.45.53
email: Basile point Starynkevitch at cea point fr 



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Real excellent object oriented source code examples of Ocaml
  2000-11-17 12:14 Real excellent object oriented source code examples of Ocaml STARYNKEVITCH Basile
@ 2000-11-20 13:46 ` Xavier Leroy
  2000-11-23 19:32 ` Anton Moscal
  2000-11-28 14:12 ` Renaud.Rioboo
  2 siblings, 0 replies; 8+ messages in thread
From: Xavier Leroy @ 2000-11-20 13:46 UTC (permalink / raw)
  To: STARYNKEVITCH Basile, caml-list

> Franck wants to see real good Ocaml-3 code using all -or most of- the
> fancy advanced object-oriented features (with multiple inheritance,
> class types, functors, etc...). And I did not found much of such code
> (e.g. OO features are almost unused in the Ocaml compiler).

Not quite.  The native-code compiler uses classes, inheritance and
method overriding quite a lot to express target-specific optimizations.
(See below.)

> I am trying to show him that most of the advanced features of C++
> (templates, overloading, multiple inheritance) have their equivalent
> in Ocaml thru real source code (or that they are less useful, like C++
> overloading).

I don't want to be picky, but C++ templates are essentially unrelated to
OO programming, and correspond most closely to OCaml's functors, along
with higher-order functions and core-language polymorphism for simpler
cases.  There are plenty of nice examples of the latter (core language
polymorphism and HO functions).  As for functors, the "Set" and "Map"
modules from the standard library are good representative examples, I
think.  But then you can also add "excellent functorized source code
examples" to the subject of your message.

To follow up on Don Syme's reply, examples that demonstrate the
interest of class-based programming, as well as functorized
programming, are hard to find because most closed, stand-alone
applications do not really need classes nor functors.  That is, for
such applications, it is almost always possible to come up with a good
implementation that does not use either classes nor functors, and
indeed such "simple" implementations are often no larger and easier to
read than a class-based or heavily functorized implementation.

To feel the need for classes and functors, you need to look at
code that needs to remain flexible, extensible and reusable in
contexts that were not fully known at the time it was written.  For
instance: libraries, application frameworks, extensible applications
where new stuff will have to be added throughout the life of the
application.

To pick my favorite example, a retargetable native-code compiler needs
to be extended each time support for a new processor is added.  The
new processor can look very much like an already supported one, in
which case it should be possible to reuse a lot of existing code; but
it can also be quite different (e.g. adding an IA32 back-end to a
compiler that supports only RISC processors), in which case it should
be possible to override significant parts of the existing code, but
without rewriting everything from scratch.  I found OCaml classes
quite effective to handle this in the ocamlopt compiler, actually more
handy than functors.

Others on this list can certainly contribute similar examples, but
they tend to be large and hard to comprehend -- just because what they
do is quite complex, and because you have to keep in mind their
evolution over time.

To come back to your original question: why don't you first look at
the kind of things your colleague does in C++ and see whether it
couldn't be expressed nicely using e.g. datatypes, pattern-matching,
polymorphism and HO functions?  Quite often, Java and C++ programmers
program in object-oriented style not because that's the best style for
their application, but because it's the only style supported by the
language.  E.g. they are used to write N+1 classes to encode a
N-constructor datatype, just because it's the way it's done in Java or
C++.

A good thing about having objects and classes in OCaml, in addition to
addressing those relatively few programming tasks that really need
them, is that when someone comes to you and asks "Can you do this
<insert tangle of classes here> in OCaml?", you can often answer "Yes,
I can do this with classes just like in your original code; but I can
also do it without, and see how much clearer and more readable it
gets".  OCaml as a rehabilitation clinic for OO programmers, if you
wish...

Good luck,

- Xavier Leroy



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Real excellent object oriented source code examples of Ocaml
  2000-11-17 12:14 Real excellent object oriented source code examples of Ocaml STARYNKEVITCH Basile
  2000-11-20 13:46 ` Xavier Leroy
@ 2000-11-23 19:32 ` Anton Moscal
  2000-11-28 14:12 ` Renaud.Rioboo
  2 siblings, 0 replies; 8+ messages in thread
From: Anton Moscal @ 2000-11-23 19:32 UTC (permalink / raw)
  To: STARYNKEVITCH Basile; +Cc: caml-list

On Fri, 17 Nov 2000, STARYNKEVITCH Basile wrote:

> I am trying to interest a young collegue Franck VEDRINE
> <franck.vedrine@cea.fr> to Ocaml-3.00. He is an excellent C++ coder
> and a respected young specialist of abstract interpretation (on which
> he got a PhD recently -regarding abstract interpretation of C++
       [...]

See on LablGTK:

http://wwwfun.kurims.kyoto-u.ac.jp/soft/olabl/lablgtk.html

This is wrapper to GTK library with very sophisticated usage of O'Caml OO
features. 

Regards, 
Anton Moscal



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Real excellent object oriented source code examples of Ocaml
  2000-11-17 12:14 Real excellent object oriented source code examples of Ocaml STARYNKEVITCH Basile
  2000-11-20 13:46 ` Xavier Leroy
  2000-11-23 19:32 ` Anton Moscal
@ 2000-11-28 14:12 ` Renaud.Rioboo
  2 siblings, 0 replies; 8+ messages in thread
From: Renaud.Rioboo @ 2000-11-28 14:12 UTC (permalink / raw)
  To: caml-list; +Cc: foc

STARYNKEVITCH Basile <Basile.Starynkevitch@cea.fr> writes:

> I am trying to interest a young collegue Franck VEDRINE
> <franck.vedrine@cea.fr> to Ocaml-3.00.

wish you luck.

> Franck wants to see real good Ocaml-3 code using all -or most of- the
> fancy advanced object-oriented features (with multiple inheritance,
> class types, functors, etc...). And I did not found much of such code
> (e.g. OO features are almost unused in the Ocaml compiler).
> 
> I am trying to show him that most of the advanced features of C++
> (templates, overloading, multiple inheritance) have their equivalent
> in Ocaml thru real source code (or that they are less useful, like C++
> overloading).

The goal of the Foc project is to have a certified computer algebra library,
and, as part of it we wrote a fairly complete library for abstract and
concrete mathematics which covers the basis for a computer agebra system.
Tthe Foc code is not really public, but is not secret either ; it is simply
not ready for public distribution.


<URL:http://www-calfor.lip6.fr/~foc> 

will give you an idea of what the project is about. 

As of excellency of the code, I don't really know, but you will find
comparisons with the Axiom computer algebra system on our page.

You will also find there an announcement for a meeting we will have on
december 21 and 22. You are welcome if you want to discuss the different
object oriented features we use in the library with us.

Regards,

                        R. Rioboo,
                        for the Foc Project







^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Real excellent object oriented source code examples of Ocaml
  2000-11-20 20:43 David McClain
@ 2000-11-21 16:49 ` Brian Rogoff
  0 siblings, 0 replies; 8+ messages in thread
From: Brian Rogoff @ 2000-11-21 16:49 UTC (permalink / raw)
  To: David McClain; +Cc: caml-list

On Mon, 20 Nov 2000, David McClain wrote:
> ... in response to Xavier...
> 
> But as someone who learned to appreciate what CLOS had to offer over the
> conventional Smalltalk style of OO, and as an avid user of OCaml, I have to
> say that I really miss CLOS sometimes...

I'm guessing that what you miss is multiple dispatch, right? That is 
the distinguishing feature of CLOS with respect to Smalltalk. I hope you
aren't talking about the CLOS MOP since I think that would play havoc with 
static typing. 

I certainly agree that multiple dispatch has advantages, and some of my
own OO Ocaml code relies on uses of the Visitor pattern, which is obviated 
by the presence of multiple dispatch. If I understood the paper correctly, 
the "extensional polymorphism" approach which has been discussed here for 
adding overloading and safe value IO has some similarities with CLOS 
generic functions but I don't know how it interacts with the object system 
or polymorphic variants. Maybe Jun or Pierre will comment on this. 

With regards to the original poster's query, you may wish to direct your
colleague to Didier Remy's APPSEM notes, which discuss the object system 
of Ocaml in detail. If he or you wish to post questions of the form "how
to do this with Ocaml objects" here I'm sure someone will help. I know I 
had a tough time initially working around the lack of downcasting and type 
querying from Java and C++, but now that I'm a little more proficient I'm
convinced that the designers were right not to include them. If the
designers wish to improve the current OO system, rather than C++ I'd 
look to Eiffel for ideas, in particular Eiffel's renaming capabilities. 
Of course, there is also the (temporary I hope!) lack of polymorphic
methods, which correspond to C++ member template functions...

Here's the URL for the APPSEM notes: 
http://cristal.inria.fr/~remy/cours/appsem/

It is true that OO features are less needed in a language like Ocaml, but
I for one am sure glad they are there. 

-- Brian




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Real excellent object oriented source code examples of Ocaml
@ 2000-11-20 20:43 David McClain
  2000-11-21 16:49 ` Brian Rogoff
  0 siblings, 1 reply; 8+ messages in thread
From: David McClain @ 2000-11-20 20:43 UTC (permalink / raw)
  To: caml-list

... in response to Xavier...

But as someone who learned to appreciate what CLOS had to offer over the
conventional Smalltalk style of OO, and as an avid user of OCaml, I have to
say that I really miss CLOS sometimes...

I have implemented several large OCaml programs, and I ended up using OO
only sparingly to support a simple hierarchy of COM/OLE encapsulator
objects. So I don't really have any particular example of need for CLOS.  I
just miss its elegant beauty sometimes. Every now and again I sit and write
some Lisp/CLOS just so that I can enjoy the experience. Call me crazy, but I
love functional closures, pattern matching, efficient tail recursion, etc.,
etc. Of course some of these are missing in Common Lisp and so I also write
a great deal of OCaml just so I can experience its special pleasures...

- DM




^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Real excellent object oriented source code examples of Ocaml
  2000-11-17 14:38 Don Syme
@ 2000-11-19 15:48 ` Mattias Waldau
  0 siblings, 0 replies; 8+ messages in thread
From: Mattias Waldau @ 2000-11-19 15:48 UTC (permalink / raw)
  To: caml-list

The reason I don't use the OO-features is not because I don't like OO, but
since Ocaml support for OO isn't as good as it could be.

The OO-features are just built on top of the normal environment. For
example, the toplevel don't understand objects, you just get the message "-
: with_oo = <obj>". The support for terms is much better. Thus, my
Caml-programs have the structure of OO, but I code them without the
OO-features of Ocaml. For example, I wouldn't normally write the
'with_oo'-class below, instead I code it as 'nooo' below.

However, if the support for showing/browsing objects on the toplevel would
be better (or maybe it is already there and I should just read the manual
better), I will start using OO in Ocaml.

The only problem with OO is that OO and functional programs don't mix well,
since OO is built on state-change. My background is from functionalal and
logic programming.

/mattias

P.s. How is the speed of methods calls, object creation compare to standard
calls and creating terms?

WITH OO:
========

class with_oo =
object
  val mutable x = 0
  val mutable y = 0
  method get_x = x
  method move d = x <- x + d; y <- y + d
end

(*

# let t = new with_oo;;
val t : with_oo = <obj>
# t;;
- : with_oo = <obj>
# t#get_x;;
- : int = 0
# t#move 10;;
- : unit = ()
# t#get_x;;
- : int = 10
#

*)

SAME CODE WITHOUT OO:
=====================

type nooo = {
  mutable x:int;
  mutable y:int;
  }

let nooo_init =
  { x=0; y=0 }

let nooo_get_x this = this.x

let nooo_move this d =
  this.x <- this.x + d;
  this.y <- this.y + d


(*

# let t = nooo_init;;
val t : nooo = {x=0; y=0}
# nooo_get_x t;;
- : int = 0
# nooo_move t 10;;
- : unit = ()
# t;;
- : nooo = {x=10; y=10}

*)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Real excellent object oriented source code examples of Ocaml
@ 2000-11-17 14:38 Don Syme
  2000-11-19 15:48 ` Mattias Waldau
  0 siblings, 1 reply; 8+ messages in thread
From: Don Syme @ 2000-11-17 14:38 UTC (permalink / raw)
  To: 'STARYNKEVITCH Basile', caml-list

>From previous discussions on this list, it seems to me that most people find
the OO features of OCaml pretty unnecessary for most applications.  There
are exceptions, but I'd be really surprised if implementing static analyses
was one of these.  

I think perhaps it should be the other way around: maybe your friend should
be trying to convince you why objects are the right idiom for encoding the
constructs he's interested in.  There is nearly always a satisfactory way of
expressing the code using the non-object features of OCaml.  And, if not,
then the OCaml object system normally suffices.

To be a little more provocative, it may be that the lack of "excellent OO
source code examples in OCaml" is a symptom of the general lack of excellent
OO source code examples at all, in any language.  There are exceptions, but
it's not like I look at many OO programs and think "that's just perfect" - I
think "I guess it does the job, but it's kind of gross".  Please feel free
to point me to samples to convince me otherwise.

Cheers,
Don


-----Original Message-----
From: STARYNKEVITCH Basile [mailto:Basile.Starynkevitch@cea.fr]
Sent: 17 November 2000 12:15
To: caml-list@inria.fr
Subject: Real excellent object oriented source code examples of Ocaml


Hello All,

I am trying to interest a young collegue Franck VEDRINE
<franck.vedrine@cea.fr> to Ocaml-3.00. He is an excellent C++ coder
and a respected young specialist of abstract interpretation (on which
he got a PhD recently -regarding abstract interpretation of C++
code). We are both working in the domain of static analysis of
embedded C code (eg critical C code in nuclear plants or aircrafts)
using abstract interpretation techniques and are supposed to deliver
some working prototype (sadly proprietary) tools on that subject.

Franck wants to see real good Ocaml-3 code using all -or most of- the
fancy advanced object-oriented features (with multiple inheritance,
class types, functors, etc...). And I did not found much of such code
(e.g. OO features are almost unused in the Ocaml compiler).

I am trying to show him that most of the advanced features of C++
(templates, overloading, multiple inheritance) have their equivalent
in Ocaml thru real source code (or that they are less useful, like C++
overloading).

I did not yet convince Franck that functional programming has many
advantages of OO style -at least in our domain of static analysis (on
which Franck is an expert and I am still a newscomer)-. So
I am sticked to exhibit excellent object oriented Ocaml code.

I tried to show the interest of garbage collection by coding a precise
[mostly copying generational, with some finalized marked objects]
garbage collector in C++ (conservative GCs a la Boehm or Barlett was
considered not enough safe at my place at that time). So I would
believe that Franck knows somehow the interest of GC today - and the
possibility of efficient garbage collection in practice.

I initiated on this Ocaml mailing list in july 1999 a very remotely
related thread on the subject "convincing management to switch to
Ocaml" (I did not succeed on that point, but I am still trying....)
see for instance
"http://pauillac.inria.fr/bin/wilma_hiliter/caml-list/199907/msg00055.html?l
ine=3#hilite"


Does any one have a nearly complete list of OO ocaml code? (I know
about LablGtk, and the ocamlopt machine code emitter)

Regards

================================
Court resume francais: [[short french abstract]]

Bonjour,

je cherche a convaincre un excellent collegue - Franck VEDRINE-
(specialiste de C++ et expert en interpretation abstraite) de l
interet d Ocaml. J ai donc besoin de code source Ocaml d excellente
qualite utilisant toutes (ou la majorite) des possibilites de
programmation orientee objet d Ocaml-3.00. Franck est un jeune
specialiste de l'analyse statique (par interpretation abstraite) de
code -un domaine [analyse statique de code critique en C] ou nous
travaillons ensemble mais ou je suis encore debutant.

Cordialement


================================


N.B. Any opinions expressed here are only mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le
CEA.

---------------------------------------------------------------------
Basile STARYNKEVITCH   ----  Commissariat a l Energie Atomique 
DTA/LETI/DEIN/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX *
France
phone: 1,69.08.60.55; fax: 1.69.08.83.95 home: 1,46.65.45.53
email: Basile point Starynkevitch at cea point fr 



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2000-11-28 21:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-17 12:14 Real excellent object oriented source code examples of Ocaml STARYNKEVITCH Basile
2000-11-20 13:46 ` Xavier Leroy
2000-11-23 19:32 ` Anton Moscal
2000-11-28 14:12 ` Renaud.Rioboo
2000-11-17 14:38 Don Syme
2000-11-19 15:48 ` Mattias Waldau
2000-11-20 20:43 David McClain
2000-11-21 16:49 ` Brian Rogoff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).