Browse thread
[Caml-list] Types of classes (was: Re: "ocaml_beginners"::[] OCaml tutorial)
- Richard Jones
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Richard Jones <rich@a...> |
| Subject: | [Caml-list] Types of classes (was: Re: "ocaml_beginners"::[] OCaml tutorial) |
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 = <fun> > " > > 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