From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA07609; Mon, 16 Jun 2003 16:02:48 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA07371 for ; Mon, 16 Jun 2003 16:02:46 +0200 (MET DST) Received: from mwinf0502.wanadoo.fr (smtp4.wanadoo.fr [193.252.22.26]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h5GE2kH02641 for ; Mon, 16 Jun 2003 16:02:46 +0200 (MET DST) Received: from debian (unknown [80.8.90.209]) by mwinf0502.wanadoo.fr (SMTP Server) with ESMTP id 07A8FE80035D for ; Mon, 16 Jun 2003 16:02:46 +0200 (CEST) Received: from moi by debian with local (Exim 3.36 #1 (Debian)) id 19Ruaa-0006EZ-00 for ; Mon, 16 Jun 2003 16:04:04 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Types of classes References: <20030614172512.GA1255@redhat.com> <878ys4zeis.dlv@wanadoo.fr> <20030614200747.GA2300@redhat.com> <87adcj8umf.dlv@wanadoo.fr> <20030616124246.GB16324@redhat.com> From: Remi Vanicat Mail-Copy-To: never Date: Mon, 16 Jun 2003 16:04:04 +0200 In-Reply-To: <20030616124246.GB16324@redhat.com> (Richard Jones's message of "Mon, 16 Jun 2003 13:42:46 +0100") Message-ID: <87n0gi6rvv.dlv@wanadoo.fr> User-Agent: Gnus/5.090024 (Oort Gnus v0.24) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; caml-list:01 foo:01 bug:01 conciseness:01 ints:01 ocaml:01 caml:01 int:01 dept-info:01 labri:01 u-bordeaux:01 0200,:01 writes:01 remi:01 vanicat:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Richard Jones 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