From: Alessandro Baretta <alex@baretta.com>
To: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] New Object Creation
Date: Sun, 07 Jul 2002 23:55:58 +0200 [thread overview]
Message-ID: <3D28B8EE.9070104@baretta.com> (raw)
In-Reply-To: <KDOKAGGEPNHINDAA@mailcity.com>
Gaurav Chanda wrote:
> class point =
> object
> value mutable x = 0;
> method addunit v = v+1 ;
> end;
>
> class type point =
> object
> value mutable x : int;
> method addunit : int -> int ;
> end;
Are you sure this class does what you expect it to? Member
variable x gets initialized to 0, cannot be set to anything
else, nor can its value be fetched. Furthermore, method
addunit could be redefined as a simple function:
# let addunit x = x + 1;;
BTW, please try to post correct code. You should have written
class type point :
object
val mutable x : int
method addunit : int -> int
end
class point =
object
val mutable x = 0
method addunit v = v + 1
end
You have misunderstood the use of class interfaces. The
point class which you define in point.ml *is not* the
implementation of the interface point in point.mli. Also,
module point, whose interface is defined in point.mli, does
not export a class point, only *class interface* point.
Here is how to separate class interfaces from class
implementations. Copy the following in point.mli:
> class type point_sig =
> object
>
val mutable x : int
>
method addunit : int -> int
> end
> class point : point_sig
Copy the following in point.ml:
> class type point_sig =
> object
>
val mutable x : int
>
method addunit : int -> int
> end
> class point : point_sig =
> object
>
val mutable x = 0
>
method addunit v = v+1
> end
Alex
-------------------
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
prev parent reply other threads:[~2002-07-07 21:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-07 20:12 Gaurav Chanda
2002-07-07 21:55 ` Alessandro Baretta [this message]
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=3D28B8EE.9070104@baretta.com \
--to=alex@baretta.com \
--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