<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/55aaf067448698d1a8dd460ca582ba39"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-07T21:49:29"
  subject="Re: [Caml-list] New Object Creation"
  prev="2002/07/b4d857a65ae262207463c99e98abb5f7"
  next="2002/07/99c5bb60f441d6e61974021204d72812"
  prev-in-thread="2002/07/bc2a965ab496aafdf2907a6d9bf85822"
  prev-thread="2002/07/362b26b59e19e369fc41bedf17213b18"
  next-thread="2002/07/0753c3188698d9ea0f77236a0e41c552"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] New Object Creation">
<msg 
  url="2002/07/bc2a965ab496aafdf2907a6d9bf85822"
  from="Gaurav Chanda &lt;gaurav_chanda@l...&gt;"
  author="Gaurav Chanda"
  date="2002-07-07T20:13:03"
  subject="[Caml-list] New Object Creation">
<msg 
  url="2002/07/55aaf067448698d1a8dd460ca582ba39"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-07T21:49:29"
  subject="Re: [Caml-list] New Object Creation">
</msg>
</msg>
</thread>

<contents>
Gaurav Chanda wrote:
&gt; class point =
&gt;         object
&gt;                 value mutable x = 0;
&gt;                 method addunit v = v+1 ;
&gt;         end;
&gt; 
&gt; class type point =
&gt;         object
&gt;                 value mutable x : int;
&gt;                 method addunit : int -&gt; int ;
&gt;         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 -&gt; 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:
 &gt; class type point_sig =
 &gt;	object
 &gt; 
	val mutable x : int
 &gt; 
	method addunit : int -&gt; int
 &gt;	end
 &gt; class point : point_sig

Copy the following in point.ml:
 &gt; class type point_sig =
 &gt;	object
 &gt; 
	val mutable x : int
 &gt; 
	method addunit : int -&gt; int
 &gt;	end
 &gt; class point : point_sig =
 &gt;	object
 &gt; 
	val mutable x = 0
 &gt; 
	method addunit v = v+1
 &gt;	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

</contents>

</message>

