caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: micha-1@fantasymail.de
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] state pattern...
Date: Tue, 28 Jun 2005 22:20:37 +0900 (JST)	[thread overview]
Message-ID: <20050628.222037.106273273.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <200506281424.28051.micha-1@fantasymail.de>

From: Michael Wohlwend <micha-1@fantasymail.de>

> 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


      reply	other threads:[~2005-06-28 13:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-26 19:57 Michael Wohlwend
2005-06-26 22:13 ` [Caml-list] " james woodyatt
2005-06-26 22:45   ` Michael Wohlwend
2005-06-27 23:23   ` Michael Wohlwend
2005-06-28  0:54     ` Jacques Garrigue
2005-06-28 12:24       ` Michael Wohlwend
2005-06-28 13:20         ` Jacques Garrigue [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=20050628.222037.106273273.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=micha-1@fantasymail.de \
    /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;
as well as URLs for NNTP newsgroup(s).