caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Remi Vanicat <vanicat@labri.u-bordeaux.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Types of classes
Date: Mon, 16 Jun 2003 16:04:04 +0200	[thread overview]
Message-ID: <87n0gi6rvv.dlv@wanadoo.fr> (raw)
In-Reply-To: <20030616124246.GB16324@redhat.com> (Richard Jones's message of "Mon, 16 Jun 2003 13:42:46 +0100")

Richard Jones <rich@annexia.org> writes:

> On Sun, Jun 15, 2003 at 01:09:44PM +0200, Remi Vanicat wrote:
>> this is not true, the type 'a stack is only an alias for the type :
>> 
>> < push : 'a -> unit; pop : 'a; peek : 'a; size : int >
>> 
>> and, as such, drain_stack can be called (for example) with an
>> argument of class stack_of_ints, but also on a object of the following
>> class :
>> 
>> class ['a] foo (x : 'a) =
>> object
>>   method push (y : 'a) = ()
>>   method pop = x
>>   method peek = x
>>   method size = 1
>> end
>
>
> Isn't this a bug in OCaml? Is there a way to force a specific type
> for an arg to a function?

But < push : 'a -> unit; pop : 'a; peek : 'a; size : int > is a
specific type. stack is not exactly a type it is a class, and as such,
when seen as a type, it is just an alias of the former.

The type of an object is not the name of its class, it is the list of
its method with their type. Then, for conciseness and readability, caml
use the name of class as an alias for the corresponding type, but
this is nothing else, an alias, not a new type.



-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      reply	other threads:[~2003-06-16 14:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20030614172512.GA1255@redhat.com>
     [not found] ` <878ys4zeis.dlv@wanadoo.fr>
     [not found]   ` <20030614200747.GA2300@redhat.com>
     [not found]     ` <87adcj8umf.dlv@wanadoo.fr>
2003-06-16 12:42       ` [Caml-list] Types of classes (was: Re: "ocaml_beginners"::[] OCaml tutorial) Richard Jones
2003-06-16 14:04         ` Remi Vanicat [this message]

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=87n0gi6rvv.dlv@wanadoo.fr \
    --to=vanicat@labri.u-bordeaux.fr \
    --cc=caml-list@inria.fr \
    /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).