From: Richard Jones <rich@annexia.org>
To: caml-list@inria.fr
Subject: [Caml-list] Types of classes (was: Re: "ocaml_beginners"::[] OCaml tutorial)
Date: Mon, 16 Jun 2003 13:42:46 +0100 [thread overview]
Message-ID: <20030616124246.GB16324@redhat.com> (raw)
In-Reply-To: <87adcj8umf.dlv@wanadoo.fr>
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
next parent reply other threads:[~2003-06-16 12:42 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 ` Richard Jones [this message]
2003-06-16 14:04 ` [Caml-list] Types of classes Remi Vanicat
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=20030616124246.GB16324@redhat.com \
--to=rich@annexia.org \
--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