Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] [Q]: Co(ntra)variance and subtyping?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Clemens Hintze <c.hintze@g...>
Subject: [Caml-list] [Q]: Co(ntra)variance and subtyping?

I am already lurking on this list for some days. Now I would like to
introduce myself. To earn my living I am working for a company writing
software in area of transportation automatisation. There we are using
mainly C/C++, PL/SQL, Perl and some other scripting languages.

But programming is not only my business but also my hobby. So I try to
grasp as much different paradigms and languages as I can get. The
imperative and declarative programming (using Prolog) is already known
to me (I have not said 'mastered' ;-).

Now I have thought about learning functional programming. I had a
closer look to OCaml, Haskell and Erlang for ca. two weeks. Although
Haskell has impressed me a lot and nearly won me, I had decided to
begin my first steps in OCaml. Partly due to the fact that the
paradigms I am already comfortable with, are also supported, partly
because of its really nice type inference scheme and modularity
capabilities and last but not least due to the fact, that OCaml offers
very nice compilers and a very comprehensive library to work with.

But where is light, there is also some shadow. I find OCaml a really
complex language -- perhaps more complex than Haskell. But, ey, C++ or
Perl also can hardly be called a simple language, isn't it? And I was
able to gain enough knowledge to use C++ successfully at my daily
work.  So I think complexity should not hinder me :-)

As I have decided to learn OCaml, I am sure that I will have several
questions in future, that I would like to ask here on the list, as I
found comp.lang.functional do not seem very busy with OCaml topics.

Two things I would like to ask you right now:

- What does subtyping exactly mean in OCaml resp. functional
- What means covariance and contravariance of types and subtypes?

I have already learned that in OCaml classes are not types like in
C++. So subclasses are not be considered as subtypes. But those
co(ntra)variance thingy?  I have read many messages of that list in
the archive. I have found some messages that deal with those terms. I
have also read the OCaml documentation. I think I've got a feeling
what it could mean, but if I should explain it to others, I would
surely fail, i.e. I would not bet my life that I have understood these
terms ;-)

OTOH, these terms seem to be very important in dealing with OCaml or
functional programming.

So excuse me, if I ask a very stupid question, but I really had not
found any me-convincing answer to this. Google also did not help me

So if you wouldn't mind, please try to explain those terms to me. If
possible with some examples.

Let me thank you all in advance and happy OCaml'ing :-)


PS: Sorry, if my english is not flawless, but it is not my
    mother-tongue, and I do not speak french a bit, unfortunately.

Clemens Hintze  mailto:
Bug reports:  FAQ:
To unsubscribe, mail  Archives: