From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id DAB687EFCD for ; Thu, 30 Oct 2014 15:51:55 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of philippe.veber@gmail.com) identity=pra; client-ip=74.125.82.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of philippe.veber@gmail.com designates 74.125.82.52 as permitted sender) identity=mailfrom; client-ip=74.125.82.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wg0-f52.google.com) identity=helo; client-ip=74.125.82.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="postmaster@mail-wg0-f52.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjcBAG1PUlRKfVI0m2dsb2JhbABchDoE1kMHFgEBAQEBEQEBAQEBBgsLCRQuhBsuARseAxIJB10BEQEFASI1iAkBAxKlMYMhPTGNJYMRiG4KGScNZ4V3AQUOlVQFkxWKVZREGCmFMzwvgksBAQE X-IPAS-Result: AjcBAG1PUlRKfVI0m2dsb2JhbABchDoE1kMHFgEBAQEBEQEBAQEBBgsLCRQuhBsuARseAxIJB10BEQEFASI1iAkBAxKlMYMhPTGNJYMRiG4KGScNZ4V3AQUOlVQFkxWKVZREGCmFMzwvgksBAQE X-IronPort-AV: E=Sophos;i="5.07,286,1413237600"; d="scan'208";a="103791517" Received: from mail-wg0-f52.google.com ([74.125.82.52]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 30 Oct 2014 15:51:55 +0100 Received: by mail-wg0-f52.google.com with SMTP id b13so3848347wgh.25 for ; Thu, 30 Oct 2014 07:51:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=Ly0WrPFS5T2rxLaVu/MtpVTjq0jBMWFxS4Ku2NRcKOA=; b=OyGrEjb97qycfnr+Tez9rftrLd0DIEZZozFPXeU8g+78o6SgVqpuweuQhJiD4PHujq GQ7yPf6Tv8UFaHp0CLdDKc6zD5jJ/VqU5eLZ7VxY20YAxn2ryyvjpZf+MiOiVTK0sSkX wUCZQVb4aLD2cGv9MRN5Y1I52Xyx8Q5TSzl2ZAIgbTWcgpnhJk5Dmm5rdRTle8GsxEZ5 uST2hEqWx6Gahz46HjZEqucxY32xqw803+KisjB+8bhUYKZAYzqDminnik37N5cyOycM Q6sx2DVbDEogArgve+ccKc6yikQlOG4i7SLxEe/mQrqDyH+ZXp8yIKUVY4jH1pkinUNj u2MA== X-Received: by 10.180.206.14 with SMTP id lk14mr44343835wic.47.1414680715284; Thu, 30 Oct 2014 07:51:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.63.237 with HTTP; Thu, 30 Oct 2014 07:51:35 -0700 (PDT) From: Philippe Veber Date: Thu, 30 Oct 2014 15:51:35 +0100 Message-ID: To: caml users Content-Type: multipart/alternative; boundary=001a11c38dac8158db0506a50570 X-Validation-by: philippe.veber@gmail.com Subject: [Caml-list] Typing of a parameterized class where the type parameter is the type of self. --001a11c38dac8158db0506a50570 Content-Type: text/plain; charset=ISO-8859-1 Dear list, I'm not sure why the following class definition is typed the way it is: OCaml version 4.02.1 # class type ['a] c = object ('a) method m : 'b end;; class type ['a] c = object ('a) constraint 'a = < m : 'b. 'b; .. > method m : 'b end In particular I don't understand why the method m gets a polymorphic type. This bites me when I try to specialize the type : # type 'a t = (< m : int ; .. > as 'a) c;; Error: This type < m : int; .. > should be an instance of type 'a c as 'a Types for method m are incompatible Instead of the type with polymorphic methods, I would have expected the following type: # class type ['a] c = object ('a) constraint 'a = < m : 'b; .. > method m : 'b end;; class type ['a] c = object ('a) constraint 'a = < m : 'b; .. > method m : 'b end And then have no problems doing what I wanted: # type 'a t = (< m : int ; .. > as 'a) c;; type 'a t = 'a constraint 'a = < m : int > What did I get wrong? Cheers, Philippe. --001a11c38dac8158db0506a50570 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Dear list,

I'= ;m not sure why the following class definition is typed the way it is:
<= /span>
=A0=A0=A0=A0=A0=A0=A0 OCaml version 4.02.1

# class type [&= #39;a] c =3D object ('a) method m : 'b end;;
class type ['a]= c =3D object ('a) constraint 'a =3D < m : 'b. 'b; .. &g= t; method m : 'b end


In particular I don't understand= why the method m gets a polymorphic type. This bites me when I try to spec= ialize the type :

# type 'a t =3D (< m : int ; .. > as 'a) c;;
Error: = This type < m : int; .. > should be an instance of type 'a c as &= #39;a
Types for method m are incompatible


Instead of the t= ype with polymorphic methods, I would have expected the following type:
=
# class type ['a]= c =3D object ('a) constraint 'a =3D < m : 'b; .. > metho= d m : 'b end;;
class type ['a] c =3D object ('a) constraint = 'a =3D < m : 'b; .. > method m : 'b end

And= then have no problems doing what I wanted:

# type 'a t =3D (< m : int ; .. > as &#= 39;a) c;;
type 'a t =3D 'a constraint 'a =3D < m : int &g= t;


What did I get wrong?

Cheers,
=A0 Philippe.
<= br>
--001a11c38dac8158db0506a50570--