From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 8DA2E7EC41 for ; Thu, 25 Oct 2012 13:49:30 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of lambda.q.q@gmail.com) identity=pra; client-ip=209.85.215.54; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="lambda.q.q@gmail.com"; x-sender="lambda.q.q@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of lambda.q.q@gmail.com designates 209.85.215.54 as permitted sender) identity=mailfrom; client-ip=209.85.215.54; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="lambda.q.q@gmail.com"; x-sender="lambda.q.q@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-la0-f54.google.com) identity=helo; client-ip=209.85.215.54; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="lambda.q.q@gmail.com"; x-sender="postmaster@mail-la0-f54.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai8CAFgmiVDRVdc2k2dsb2JhbABEhU+8SAgjAQEBAQkJCwkUBCOCNwImBgE5Aw0FJjQBBCABBQFXh1ADDwScNoIIYAkDjx6FGCcNiU4BBQyPHoMkA4hWiGCEPo5cP4FYgj4 X-IronPort-AV: E=Sophos;i="4.80,646,1344204000"; d="scan'208";a="178893224" Received: from mail-la0-f54.google.com ([209.85.215.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 25 Oct 2012 13:49:30 +0200 Received: by mail-la0-f54.google.com with SMTP id e12so2402050lag.27 for ; Thu, 25 Oct 2012 04:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:user-agent:mime-version :content-type; bh=4ZUn5j6foRsCk7KHm+c6xhqrTxAykq0HWePfsvrCIk8=; b=qBcxi9smPl5/4+3JluMVYUwIOb5JNphZ4AXdbiSLlzME5r21LqJfGnX+TG/MvWStLF GMle3W0Ny05qk86sAO1Ec1tIUJOm5LHCoK162w9TtKoIuvhbU7/DHxw2sZsTbL3YAPvb HscxiwlRFrw1OvooI3PjkeaSAtEfWszkNVpVJruEQDgccj/z7LI7ecHYqlxc4nvW8e/K x3RpUXO0yVt2oxgtZVjZStmZ8Ub7tef/8A5MguMVewqEyH2UTOwO3G1yyKMTi8ZjQF6o 9WUaf7pCXKTIeCayUCJlyGKbMcePE16S9IoDDv2TqN+MWJ6L464PMQMspJeFnsouy4as 56AA== Received: by 10.112.104.4 with SMTP id ga4mr7613954lbb.86.1351165769469; Thu, 25 Oct 2012 04:49:29 -0700 (PDT) Received: from golf.niidar.ru.niidar.ru ([178.176.138.65]) by mx.google.com with ESMTPS id gt17sm5820440lab.6.2012.10.25.04.49.27 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 25 Oct 2012 04:49:28 -0700 (PDT) Sender: Ivan Gotovchits From: Ivan Gotovchits To: caml-list@inria.fr Date: Thu, 25 Oct 2012 15:54:36 +0400 Message-ID: <87txtiix6r.fsf@golf.niidar.ru> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Caml-list] Polymorphic variants and inheritance Here a simple example that illustrates the problem: type odds = [`One | `Three ] type evens = [`Two | `Four ] type numbers = [ odds | evens ] class type number = object method category: numbers end class type odd = object inherit number method category: odds end class type even = object inherit number method category: evens end It fails to compile, stating the following error: The method category has type odds but is expected to have type numbers Type odds = [ `One | `Three ] is not compatible with type numbers = [ `Four | `One | `Three | `Two ] The first variant type does not allow tag(s) `Four, `Two Just by theory, odds are covariant to numbers, so this kind of subtyping can be done. Is it possible to persuade compiler? -- (__) (oo) /------\/ / | || * /\---/\ ~~ ~~ ...."Have you mooed today?"...