From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 47ED7BB84 for ; Tue, 1 Jul 2008 17:15:22 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq0AAEznaUiBaB4iZGdsb2JhbACSIRoFCAcSn2I X-IronPort-AV: E=Sophos;i="4.27,732,1204498800"; d="scan'208";a="26912109" Received: from mx1.polytechnique.org ([129.104.30.34]) by mail4-smtp-sop.national.inria.fr with ESMTP; 01 Jul 2008 17:14:40 +0200 Received: from is005115 (is005115.intra.cea.fr [132.166.135.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTP id 6899933175 for ; Tue, 1 Jul 2008 17:14:39 +0200 (CEST) Date: Tue, 1 Jul 2008 17:14:37 +0200 From: Virgile Prevosto To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Open class types Message-ID: <20080701171437.0cddf254@is005115> In-Reply-To: <486A36DE.4040605@stork.ru> References: <486A36DE.4040605@stork.ru> X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.9; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-AV-Checked: ClamAV using ClamSMTP at djali.polytechnique.org (Tue Jul 1 17:14:39 2008 +0200 (CEST)) X-Org-Mail: virgile.prevosto.1996@polytechnique.org X-Spam: no; 0.00; subtype:01 subtype:01 ocaml:01 syntax:01 tutto:98 oggi:98 volta:98 polymorphic:01 polymorphic:01 caml-list:01 constraint:01 constraint:01 int:01 int:01 expression:02 Hello, Le mar 01 jui 2008 17:53:34 CEST, SerP a =C3=A9crit : > class type session_t =3D > object > method id:int; > method location: #location_t; > end; >=20 ... >=20 > Error: This expression has type session =3D < id : int; location : > location > but is here used with type > #session_t as 'a =3D < id : int; location : 'b. > #location_t; .. > My guess is that session_t is a bit too polymorphic: location is a polymorphic method (indicated by the 'b. in the error message). Thus, a class implementing session_t should have a location method able to return any subtype of location_t, which might be a bit complicated to say the least. A more sensible class type would require that the location method returns a subtype of location_t, which may differ from one implementation to the other, but is fixed for a given implementation. By the way, this matches more or less your second solution. At the class/class type level, this can be done by adding a type parameter to the class type and using a constraint as shown below (warning, this is the regular ocaml syntax, not the revised one): class type ['a]session_t =3D object method id:int method location: 'a constraint 'a =3D #location_t end let check_session (session:'a #session_t) =3D begin print_int session#id; print_int session#location#a; print_string session#location#b; end --=20 E tutto per oggi, a la prossima volta. Virgile