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 OAA05029; Mon, 16 Jun 2003 14:42:49 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA05115 for ; Mon, 16 Jun 2003 14:42:47 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h5GCglT22530 for ; Mon, 16 Jun 2003 14:42:47 +0200 (MET DST) Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 19RtJu-0004Gg-00 for ; Mon, 16 Jun 2003 13:42:46 +0100 Date: Mon, 16 Jun 2003 13:42:46 +0100 To: caml-list@inria.fr Subject: [Caml-list] Types of classes (was: Re: "ocaml_beginners"::[] OCaml tutorial) Message-ID: <20030616124246.GB16324@redhat.com> References: <20030614172512.GA1255@redhat.com> <878ys4zeis.dlv@wanadoo.fr> <20030614200747.GA2300@redhat.com> <87adcj8umf.dlv@wanadoo.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87adcj8umf.dlv@wanadoo.fr> User-Agent: Mutt/1.5.4i From: Richard Jones X-Spam: no; 0.00; beginners:01 ted:99 narrowing:01 val:01 foo:01 bug:01 freshmeat:01 team's:01 ltd:98 ints:01 ocaml:01 int:01 0200,:01 remi:01 vanicat:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, Jun 15, 2003 at 01:09:44PM +0200, Remi Vanicat wrote: > Well, I've spot[ted] another mistake : > > http://merjis.com/richj/computers/ocaml/tutorial/ch8.shtml > > Say (about function acting over object) : > > " > We can force OCaml to be more specific and only allow drain_stack to > be called on 'a stacks by narrowing the type of the s argument, like > this: > > # let drain_stack (s : 'a stack) = > while s#size > 0 do > ignore (s#pop) > done;; > val drain_stack : 'a stack -> unit = > " > > 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? Rich. -- Richard Jones, Red Hat Inc. (London) and Merjis Ltd. http://www.merjis.com/ http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj 'There is a joke about American engineers and French engineers. The American team brings a prototype to the French team. The French team's response is: "Well, it works fine in practice; but how will it hold up in theory?"' ------------------- 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