caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: Pierre-Alexandre Voye <ontologiae@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Trouble with subtyping
Date: Thu, 7 Apr 2011 23:44:49 +0200	[thread overview]
Message-ID: <20110407214449.GE4136@localhost> (raw)
In-Reply-To: <BANLkTi=7a9+hjgYEDHD3Kbj2krmR9B7dGQ@mail.gmail.com>

Le Thursday 07 Apr 2011 à 18:48:45 (+0200), Pierre-Alexandre Voye a écrit :
>    Hi all, I'm working on a lib to modelize a Multi-Agent System where
>    each agent are driven by a Hierarchical Finite State Machine (HFSM).

Hi.

>    class agent :
>      object
>        val mutable birthtime : int
>        val mutable currentState : agent state option

OK.

>    So, it doesn't want to accept currentState to become a inheritedDwarf
>    state option and thus, I can't use my inheritedDwarf

Not surprising.

'class agent' defines a class, i.e. a piece of code that can be
inherited.

As of now, the currentState field mentions the type 'agent', so if you
inherit from 'agent', currentState field will keep 'agent'.

If you want the field to refer to a subclass, do, in the signature:

class agent : object ('self)
	val mutable birthtime		: int
	val mutable currentState	: 'self state option
	...

>    Pierre-Alexandre
>    --
>    ---------------------
>    Isaac Project - [1]http://www.lisaac.org/

-- 
     Guillaume Yziquel


      reply	other threads:[~2011-04-07 21:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-07 16:48 Pierre-Alexandre Voye
2011-04-07 21:44 ` Guillaume Yziquel [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=20110407214449.GE4136@localhost \
    --to=guillaume.yziquel@citycable.ch \
    --cc=caml-list@inria.fr \
    --cc=ontologiae@gmail.com \
    /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).