From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p4NABkQs021548 for ; Mon, 23 May 2011 12:11:46 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiUCAGQy2k3RVaA2kGdsb2JhbACmGggUAQEBAQkJDQcUBCKIcJ1rjlCDZIkZAQEDBoYTBIZOiUOEL4ERhUU7gSeCHQ X-IronPort-AV: E=Sophos;i="4.65,255,1304287200"; d="scan'208";a="83716595" Received: from mail-pw0-f54.google.com ([209.85.160.54]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 May 2011 12:11:39 +0200 Received: by pwj8 with SMTP id 8so3877457pwj.27 for ; Mon, 23 May 2011 03:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:subject:mime-version:content-type:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to:x-mailer; bh=seb4VkdXHmsfGEVuPETDDxMWFtpc/TwMzKIIlp1Fs08=; b=BdwMRRxyg6alTwiSM7xUAiMMQpDR6KxZROS028eT/NSPxLtwtlsHtxbnC5v2/UcNAN 61x5sqQjuDI852oL7WNhk0yoz1UmUXE/Lev4VfZ6UxHOStxzHpouNV8RyySUsA51ifYW PO7q0ls0HHqnsqXUrAgvePgocBbe9j1jR1YXM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; b=feOlFLPQ26aVgdAJDCmOtvoPE4kAL/HsKutG9sA0p4d4hke3XgoMtlx1nRlnCS0dbE 8mRyjwuwDhSfnv8AYhPgfHh2famm5DlDhyBvra44FsNTzqN2oSTuvSGyX9b4gKjRhzkV CjiwHYhH/FXBDhrrDB3Cw26apwsECyffd5KKw= Received: by 10.68.63.100 with SMTP id f4mr2081127pbs.339.1306145497831; Mon, 23 May 2011 03:11:37 -0700 (PDT) Received: from [10.2.83.213] (O-TK-MSC52000001.w-lan.jp [143.90.238.110]) by mx.google.com with ESMTPS id i9sm4251925pbd.38.2011.05.23.03.11.33 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 May 2011 03:11:36 -0700 (PDT) Sender: Jacques Garrigue Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Jacques Garrigue In-Reply-To: Date: Mon, 23 May 2011 19:11:40 +0900 Cc: caml-list@inria.fr Message-Id: <6966A071-C6AB-4549-A7AD-E58A4067D6CA@math.nagoya-u.ac.jp> References: To: Dmitry Grebeniuk X-Mailer: Apple Mail (2.1084) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p4NABkQs021548 Subject: Re: [Caml-list] ocaml, objects, classes, type ascription, virtual methods 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