From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id BBAD3BCAE for ; Tue, 28 Jun 2005 15:20:52 +0200 (CEST) Received: from rabbit.math.nagoya-u.ac.jp (rabbit.math.nagoya-u.ac.jp [133.6.130.5]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j5SDKomV027491 for ; Tue, 28 Jun 2005 15:20:52 +0200 Received: from localhost (millas [172.16.30.29]) by rabbit.math.nagoya-u.ac.jp (8.12.11/3.7W) with ESMTP id j5SDKdDV019983; Tue, 28 Jun 2005 22:20:39 +0900 (JST) Date: Tue, 28 Jun 2005 22:20:37 +0900 (JST) Message-Id: <20050628.222037.106273273.garrigue@math.nagoya-u.ac.jp> To: micha-1@fantasymail.de Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] state pattern... From: Jacques Garrigue In-Reply-To: <200506281424.28051.micha-1@fantasymail.de> References: <200506280123.55251.micha-1@fantasymail.de> <20050628.095406.112629429.garrigue@math.nagoya-u.ac.jp> <200506281424.28051.micha-1@fantasymail.de> X-Mailer: Mew version 4.0.69 on Emacs 22.0.50 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 42C14EB2.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 'self:01 'self:01 omitted:01 subtype:01 annotation:01 cheers:01 ...:98 ...:98 polymorphic:01 avoids:01 jacques:01 jacques:01 garrigue:03 garrigue:03 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: From: Michael Wohlwend > thanks for your reply, it's increasing my understanding of the object system, > although there are some (or more... :-) open points: > > In: > class ['state] context s = > object (this:'self) > ... > end > > what are the reasons to give 'this' a type, and isn't 'self a > type-variable? I thought it ('this') has the type of the class (= > _context) ? You're correct. In this case, 'self will be bound to the type of the class. This is useful if you want to write a type using it. But in the code for context, this is not used, so ":'self" could be omitted. > I don't understand why and when it is needed to give the > object a type. > The same with: > class state1 = object (this : _ #state) ... end > > I thought class state1 is a subtype (or implementing the class-type) #state, > since the methods are the same. Why does it help to give the object > a type? Again you're correct. But here the type annotation forces all methods of state1 to have the same type as in state. In practice, this avoids annotating c in the method show. This works with polymorphic methods too. Cheers, Jacques Garrigue