caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Vincent Aravantinos <vincent.aravantinos@yahoo.fr>
To: Luca de Alfaro <luca@dealfaro.org>
Cc: "Inria Ocaml Mailing List" <caml-list@inria.fr>
Subject: Re: [Caml-list] Why can't I call a function over a subclass?
Date: Fri, 5 Oct 2007 13:08:27 +0200	[thread overview]
Message-ID: <A5C24FBB-AF67-412D-A7C5-578E68AEAB5D@yahoo.fr> (raw)
In-Reply-To: <28fa90930710050108k34cff56dge24e1e9c4a01f9bd@mail.gmail.com>


Le 5 oct. 07 à 10:08, Luca de Alfaro a écrit :

> I don't understand this.  I thought the whole idea of oo  
> programming was that you could use a subclass in place of a  
> superclass...
>
> I also thought that the strict typing of Ocaml was there to avoid  
> runtime errors, but if so, why does it complain in this situation,  
> when no runtime error can possibly happen?
>
> It seems to me that the idea of oo programming is broken for no  
> good reason...

- This is absurd in an oo context. Here, the main paradigm is not oo.  
It is simply strongly typed. So if you write that a function expects  
a particular type, this function should be applied with this  
particular type and nothing else. *You* wrote this so you claimed for  
it.

You want more generality ? Then let the type checker do its job as  
Pietro said. *The default behaviour is not to write any type info.*  
If you stay with this you get the standard oo behaviour.

Annotations are there to give more info to the compiler in case it  
does infer what you have in mind.

- Strict typing of Ocaml is not to avoid runtime errors. It simply  
stays that if two types expected to be the same differ, we suppose  
*the program does not match what the programmer has in mind*. As a  
little side-effect, this can avoid runtime errors :)

If you keep this idea of "what the programmer has in mind", in this  
particular case you said to the compiler with your type annotation  
that what you had in mind was that the function only takes a r. What  
you said to the compiler was not what you had in mind.


And I insist again: the default behaviour (don't anotate) gives you  
what you would expect.

Cheers,
Vincent

  parent reply	other threads:[~2007-10-05 11:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-05  7:48 Luca de Alfaro
2007-10-05  8:01 ` [Caml-list] " Florian Hars
2007-10-05  8:08   ` Luca de Alfaro
2007-10-05  8:08     ` Fwd: " Luca de Alfaro
2007-10-05 11:08     ` Vincent Aravantinos [this message]
2007-10-05 11:47       ` Christophe Raffalli
2007-10-05 10:30   ` David Teller
2007-10-05 10:53     ` Zheng Li
2007-10-05 14:02       ` [Caml-list] " David Teller
2007-10-05 14:59         ` Luca de Alfaro
2007-10-05 15:12           ` Luca de Alfaro
     [not found]             ` <20071005152130.M41697@cs.unm.edu>
2007-10-05 15:49               ` Luca de Alfaro
2007-10-05 16:34                 ` Edgar Friendly
2007-10-05 17:39                   ` Luca de Alfaro
2007-10-05 17:49                     ` Martin Jambon
     [not found]                       ` <28fa90930710052153k2128bb63m5132455868eb2008@mail.gmail.com>
2007-10-07 22:19                         ` Martin Jambon
2007-10-07 22:57                         ` Classes and polymorphism (Re: [Caml-list] Re: Why can't I call a function over a subclass?) Martin Jambon
2007-10-05 19:48                 ` Why can't I call a function over a subclass? Zheng Li
2007-10-06  1:49                   ` [Caml-list] " Jake Donham
2007-10-09  4:18                 ` Jacques Garrigue
2007-10-05  8:07 ` [Caml-list] " Pietro Abate
2007-10-05 10:55 ` Andrej Bauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=A5C24FBB-AF67-412D-A7C5-578E68AEAB5D@yahoo.fr \
    --to=vincent.aravantinos@yahoo.fr \
    --cc=caml-list@inria.fr \
    --cc=luca@dealfaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).