Browse thread
[Caml-list] Types of classes (was: Re: "ocaml_beginners"::[] OCaml tutorial)
-
Richard Jones
- Remi Vanicat
[
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: | Remi Vanicat <vanicat@l...> |
| Subject: | Re: [Caml-list] Types of classes |
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