caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Dmitry Grebeniuk <gdsfh1@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] ocaml, objects, classes, type ascription, virtual methods
Date: Mon, 23 May 2011 19:11:40 +0900	[thread overview]
Message-ID: <6966A071-C6AB-4549-A7AD-E58A4067D6CA@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <BANLkTik6eujEYmnJKP83Ev0G6b0r0WX+fg@mail.gmail.com>

On 2011/05/23, at 16:50, Dmitry Grebeniuk wrote:

> Hello.
> 
>  I have a base class with virtual methods and an extended classes
> where these methods are implemented.
>  When I'm ascribing type "base" to class "ext", I get an error:
> 
> =============
>        OCaml version 3.13.0+dev3 (2011-03-07)
> 
> # class virtual base = object method virtual m : unit end;;
> class virtual base : object method virtual m : unit end
> # class ext : base = object method m = () end;;
> Characters 6-43:
>  class ext : base = object method m = () end;;
>        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Error: This class should be virtual. The following methods are undefined : m
> #
> =============
> 
>  Is it the expected behaviour?

It is indeed the expected behaviour.
Like a module signature, a class signature provides complete information.
If you declare a method as virtual in the signature, it will be made virtual by
the ascription (this is allowed, since virtual is a "supertype" of concrete).

In such a case you should rather use a class type:

  class type base = object method m : unit end

As suggested by others, if you don't want to suggest such a class
type you can also use the derived object type:

  class ext = object (_ : #base) method m = () end

These different approaches are described in the manual.

Jacques Garrigue

  parent reply	other threads:[~2011-05-23 10:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23  7:50 Dmitry Grebeniuk
2011-05-23  8:29 ` Matthieu Dubuget
2011-05-23  8:40   ` Dmitry Grebeniuk
2011-05-23  9:08     ` Lauri Alanko
2011-05-23  9:21       ` Dmitry Grebeniuk
2011-05-23 10:11 ` Jacques Garrigue [this message]
2011-05-23 10:25   ` Dmitry Grebeniuk

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=6966A071-C6AB-4549-A7AD-E58A4067D6CA@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=gdsfh1@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).