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 XAA24786; Sun, 7 Jul 2002 23:49:29 +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 XAA24695 for ; Sun, 7 Jul 2002 23:49:28 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a84.tin.it [62.211.4.84]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g67LnR928266 for ; Sun, 7 Jul 2002 23:49:27 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 135912739C for ; Sun, 7 Jul 2002 23:55:59 +0200 (CEST) Message-ID: <3D28B8EE.9070104@baretta.com> Date: Sun, 07 Jul 2002 23:55:58 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 X-Accept-Language: it, en MIME-Version: 1.0 To: Ocaml Subject: Re: [Caml-list] New Object Creation References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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