Ian T Zimmerman | 2 Jun 1996 01:19
Picon

ocaml, inheritance vs. subtyping?


Hi, I am just starting with ocaml, so please have mercy on a newbie
:-)

I am somewhat perplexed by the passage in the manual on virtual
methods (pp. 29-30).  Let's start with the first paragraph on p.30: it
says that int_comparable2 is not a subtype of int_comparable, even
though the former inherits from the latter!  Now for a person with an
experience in a non-functional OO language (C++ or Eiffel or Sather)
it seems _very strange_ that the subtype and inheritance (derivation)
relations aren't the same.  It even seems that not having such an
overlap defeats the purpose of having OO features in the first place.
How is the programmer to predict where a subtype relation actually
exists?

Now the manual goes on to say that this occurs because `the self type
appears in contravariant position in the type of method leq'.  First,
am I right in decoding this as `the types of the argument of
int_comparable#leq and int_comparable2#leq are in covariant relation,
but they would have to be in contravariant relation for a subtyping
relation to exist between int_comparable and int_comparable2'?
Second, and this may be the heart of the issue, _WHY_ is type 'a ->
bool inferred for leq, and not < x: unit -> int; .. > -> bool , as
it surely would for a global function?

If these are stupid questions, I apologize again.  Maybe it's a sign
that the OO features need more explanation in the manual, though.

Best,

(Continue reading)

Didier Remy | 3 Jun 1996 19:52
Picon
Picon
Favicon

Re: ocaml, inheritance vs. subtyping?


> I am somewhat perplexed by the passage in the manual on virtual
> methods (pp. 29-30).  Let's start with the first paragraph on p.30: it
> says that int_comparable2 is not a subtype of int_comparable, even
> though the former inherits from the latter!  Now for a person with an
> experience in a non-functional OO language (C++ or Eiffel or Sather)

> it seems _very strange_ that the subtype and inheritance (derivation)
> relations aren't the same.  

No, the two relations are not the same.  This is one of the main
problem with object orientation: subtyping and subclassing should not
be identified.  The are different notions.

Inheritance is the ability to build a class from some older ones, and in
particular to share its source and compiled code. The subclassing relation
is defined between classes, and is purely syntactic. 

On the opposite, the subtyping relation is defined between types, and the
coercions are defined between values, usually objects.  The subtyping
relation tells wether an object of some type can safely be considered as an
object of another type.  This is a more semantic concept. 

There is *no* relation between sub-classing and sub-typing as illustrated by
the two following examples (You may read [1] for a longer discussion of
this problem):

Let first see an example of subclassing were subtyping fails:           ;;

    class point x as self : 'mytype = 
(Continue reading)

Pierre Weis | 4 Jun 1996 09:09
Picon
Picon

timer


Date: Mon, 3 Jun 1996 21:52:48 +0100
To: caml-list <at> pauillac.inria.fr
Subject: fonction pour mesurer le temps

[English: there is no means to measure elapsed time in Caml Light under PC or
Macintosh. Is there the necessary C code primitive already written somewhere ?]

j'avais pose a P.W. la question suivante:

> 1) d'un eleve: existe-t-il une fonction de bibliotheque pour mesurer le
> temps ecoule?

la reponse de P.W.:

> Elle existe dans la librairie Unix. Sinon il faut e'crire un bout de
> code C qui la procure...

d'ou une nouvelle question, a destination de la liste: quelqu'un a-t-il
ecrit cette fonction 1) pour caml-win 2) pour caml-dos 3) pour caml-mac ?
ceci pour eviter de re-inventer la roue (qui tourne, arf).

amicalement,

Bruno Petazzoni <bpetazzoni <at> sancerre.ac-idf.jussieu.fr>
Lyc. M. Berthelot
94100 SAINT-MAUR

Ian T Zimmerman | 4 Jun 1996 08:51
Picon

Re: ocaml, inheritance vs. subtyping?


In article <199606031649.SAA14505 <at> pauillac.inria.fr>
Didier.Remy <at> inria.fr (Didier Remy) writes:

> I (itz) wrote this...:

> > I am somewhat perplexed by the passage in the manual on virtual
> > methods (pp. 29-30).  Let's start with the first paragraph on p.30: it
> > says that int_comparable2 is not a subtype of int_comparable, even
> > though the former inherits from the latter!  Now for a person with an
> > experience in a non-functional OO language (C++ or Eiffel or Sather)
> > it seems _very strange_ that the subtype and inheritance (derivation)
> > relations aren't the same.  
> 

> No their are intendedly not the same.  This is one of the main
> problem with object orientation: subtyping and subclassing should
> not be identified.  The are different notions.  Inheritance is the
> ability to build a class from some older ones, and in particular to
> share its source and compiled code. The subclassing relation is
> defined between classes, and is purely syntactic.  On the opposite,
> the subtyping relation is defined between types, and the coercions
> are defined between values, usually objects.  The subtyping relation
> tells wether an object of some type can safely be considered as an
> object of another type.  This is a more semantic concept.

OK, I now see that this is mainly a matter of terminology.  What
you're saying is that subtyping and subclassing _as used by ocaml_ are
distinct.  I already knew that when I wrote my post :-) But ocaml's
notion of subclassing is different from the one in C++ and Sather, and
(Continue reading)

Robbert VanRenesse | 6 Jun 1996 18:14
Picon
Favicon

Re: timer


I have ported part of the Unix library to Windows.  It includes gettimeofday
and all the socket stuff.  I have to put some finishing touches on it, but
will make it available soon.  Unfortunately, I'm gone most of next week, and
very busy this week, but I'll see what I can do.

Robbert

At 09:09 AM 6/4/96 +0200, Pierre Weis wrote:
>
>Date: Mon, 3 Jun 1996 21:52:48 +0100
>To: caml-list <at> pauillac.inria.fr
>Subject: fonction pour mesurer le temps
>
>[English: there is no means to measure elapsed time in Caml Light under PC or
>Macintosh. Is there the necessary C code primitive already written somewhere ?]
>
>j'avais pose a P.W. la question suivante:
>
>> 1) d'un eleve: existe-t-il une fonction de bibliotheque pour mesurer le
>> temps ecoule?
>
>la reponse de P.W.:
>
>> Elle existe dans la librairie Unix. Sinon il faut e'crire un bout de
>> code C qui la procure...
>
>d'ou une nouvelle question, a destination de la liste: quelqu'un a-t-il
>ecrit cette fonction 1) pour caml-win 2) pour caml-dos 3) pour caml-mac ?
>ceci pour eviter de re-inventer la roue (qui tourne, arf).
(Continue reading)

Andrew Stevens | 7 Jun 1996 14:46
Picon
Picon

CaML tk lib. under Windows FAQ?


Probably an FAQ... what is the status of the CaML Tk library
with regard to the Win-32 port of Object-CaML?

- Are the plans for it be ported 'eventually' as part of the official
distirbution?

- Has anyone attempted/begun a port (the latest iteration of tcl/tk for WIn-32
is reputed to be pretty stable so it seems an obvious thing to try)?

Andrew

PGP KEY: email, or finger as <at> mercury.comlab.ox.ac.uk

Robbert VanRenesse | 7 Jun 1996 19:49
Picon
Favicon

socket library for ocaml


I have made an initial distribution of a socket library.  It is supported not
only under Unix, but, using Winsock, also under systems like Windows 95.  I
have only compiled it under Unix, and compiled and tested it under WinNT 4.0,
but expect little difficulty.  For WinNT, I used Visual C++ 4.1.

The socket module supports all socket operations, select(), and gettimeofday().
It's called Socket.  For documentation, see the Unix documentation (but use
Socket. rather than Unix.).  For many applications, it should make the Unix
library obsolete, resulting in greater portability among platforms.  For
example, it should make a port of CamlTk to Windows pretty easy, for those
whom are inclined to try this.

You can get the socket module by anonymous ftp from
   ftp.cs.cornell.edu/pub/isis/horus/ocaml/socket.tar[.gz]
Untar it in the otherlibs directory, and run "make" followed by "make install"
(under Windows:  nmake -f Makefile.nt).  You have to define HAS_SOCKETS in
config/s.h first.

Feedback is highly appreciated.  My hope is that Xavier will include this
in the official ocaml distribution, and we know how he insists on quality!
I'm currently not supporting the entire Winsock API (particularly not the
Winsock 2 API), but will probably add this some time in the foreseeable
future.

For those who are interested, I have an initial port of Horus/ML over the
socket library up and running.

Robbert

(Continue reading)

Re: timer


>[English: there is no means to measure elapsed time in Caml Light under PC or
>Macintosh. Is there the necessary C code primitive already written somewhere ?]

I did this for my Mac port of Caml Light 0.7 (which is not the official
port) and for Mac Moscow ML (which is the official port and is based on my
Mac Caml Light 0.7).

In my Mac Caml Light 0.7 and in Mac Moscow ML I implemented three timers:
- elapsed time
- time spent in GC
- time spent in "the cooperative multitasking experience"
and primitives to create additional timers.

To do this, macros to start and stop the various timers must be inserted in
many places in the runtime code. The Caml Light team decided not to include
my stuff, probably because so many changes were required in the source.

If you would like to see how it's done, get the Mac Moscow ML from
<http://www.dina.kvl.dk/~sestoft/mosml.html>. Look at the file runtime.c
and then look for uses of the macros beg_gc_time(), end_gc_time(),
beg_mf_time(), and end_mf_time(). gettimeofday is also implemented there in
e_gettimeofday.c.

e

Michael Jones | 12 Jun 1996 11:31
Picon
Picon
Favicon

Perplexing type error.


Tres petit(e) abstract en Francais:
Il y a une "type error" que je ne comprende pas.  

While tweaking a preterm parser for type expressions in a proof assistant 
written in caml, I came across the following perplexing type error.  At first, 
it looked like a type inference problem so I specified the types in the 
generic function definitions and got a new error:

#Toplevel input:
>  and parse_pretypepred src = P_APPLY Pred (parse_preterm) src
>                                            ^^^^^^^^^^^^^
This expression has type lexcode list -> preterm * lexcode list,
but is used with type lexcode list -> preterm * lexcode list.
# _

So.  Any ideas why this is an error and how I can fix it?  I'm stumped.  The 
line with the error in it is part of a larger mutualy recursive function.  I 
am using caml-light-0.71 on a sun workstation and didn't see anything similar 
in the known bugs file.  

Some more detail about the line of code:  P_APPLY is a parser combinater that 
takes a function (Pred in this case) and applies it to the parser result.   
Pred is a type constructor for making pretypes out of preterms.  parse_preterm 
is the parser and src is the output of the lex. analyzer.  

regards,
mike.

(Continue reading)

Pierre Weis | 12 Jun 1996 20:42
Picon
Picon

Re: Perplexing type error.


> Tres petit(e) abstract en Francais:
> Il y a une "type error" que je ne comprende pas.  

Le proble`me est bien connu et re'fe'rence' dans la FAQ. Regardez dans
http://pauillac.inria.fr/caml/FAQ/FAQ_EXPERT-fra.html, la premie`re
question sur le typage, qui s'intitule 
 <<Un type est incompatible avec lui-même ?>>
et doit re'pondre a` votre question. J'en extrais la conclusion:

La solution: quitter la session et tout recharger dans une nouvelle
session. Si le phénomène apparaît lors de la compilation d'un fichier,
il faut recompiler tous les fichiers dont il dépend. 

J'espe`re que ca marchera pour vous.

> While [...]
>
> This expression has type lexcode list -> preterm * lexcode list,
> but is used with type lexcode list -> preterm * lexcode list.
[...]

This is a well-known pitfall of ML, it is referenced in the Caml
FAQ. Have a look at
http://pauillac.inria.fr/caml/FAQ/FAQ_EXPERT-eng.html, the first
question about type checking is 
<<Error message: a type is not compatible with itself ?>>
it should answer to your question. The conclusion given here is:

Solution: quit your interactive system and reload your files in a new
(Continue reading)


Gmane