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 OAA19192; Tue, 23 Mar 2004 14:36:01 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA18575 for ; Tue, 23 Mar 2004 14:36:00 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i2NDZwHd026283 for ; Tue, 23 Mar 2004 14:35:59 +0100 Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id WAA03269; Tue, 23 Mar 2004 22:35:51 +0900 (JST) To: xm@xmunkki.org Cc: caml-list@inria.fr Subject: Re: [Caml-list] Basic quation about object methods In-Reply-To: <20040323135747.A3439@xmunkki.org> References: <20040323135747.A3439@xmunkki.org> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20040323223551D.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 23 Mar 2004 22:35:51 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 jacques:01 newbie:01 val:01 params:01 params:01 -argument:01 -argument:01 jacques:01 ocaml:01 mutable:01 int:01 int:01 garrigue:01 garrigue:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 331 From: Jere Sanisalo > I'm a relatively newbie ocaml user, and I'm currently trying to understand a > basic thing about methods. Can someone clarify the following: > > class test = > object > val mutable v = 0 > method no_params = v<-v+1; print_int v > method has_params () = v<-v+1; print_int v > end;; > > Now what's the basic difference between methods "no_params" and > "has_params"? The o'reilly book says "Note that some methods do not need > parameters" and "We usually access instance variables with parameterless > methods.". There is no difference (except that with has_params you will have to pass unit to call the method). The reason is that internally a method takes the object itself as first argument, so no_params is actually a 1-argument function, while has_params is a 2-argument function. But for practical reasons, it may be nice to add a parameter to methods causing side-effects. This makes easier to distinguish them from effect-free ones, and also lets you extract the method itself by calling it without parameter, when you want to pass it around. All this is purely practical, since there is really no theoretical difference between the two. Jacques Garrigue ------------------- 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