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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 663A57EE34 for ; Thu, 31 Mar 2016 12:41:17 +0200 (CEST) IronPort-PHdr: 9a23:CdLH+REemuQjqSbEspj1Cp1GYnF86YWxBRYc798ds5kLTJ75o86wAkXT6L1XgUPTWs2DsrQf27qQ6PirADxIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/nh6bpo9aKM01hv3mUX/BbFF2OtwLft80b08NJC50a7V/3mEZOYPlc3mhyJFiezF7W78a0+4N/oWwL46pyv50IbaKvdK09SflcDS86G2Ez/szi8xfZHiWV4X5JfWINjRtOSxbC6lnQRJr9vzH+sfU1jCadJtL3S/UqHD6K8KphDhPl3nRUfwUl+X3a35QjxJlQpwis8kRy Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=goswin-v-b@web.de; spf=Pass smtp.mailfrom=goswin-v-b@web.de; spf=None smtp.helo=postmaster@mout.web.de Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.14; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of goswin-v-b@web.de designates 212.227.15.14 as permitted sender) identity=mailfrom; client-ip=212.227.15.14; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.14; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0D/AQCY/fxWkw4P49RdhDWzcogAgXCGDQKBPjkTAQEBAQEBAQERAQEBAQcNCQkhL0EOAYFdghQBAQEDAScLATgTCwsYCSUPBSiIRQENCAS8Fh+FPQELAR2KZIUKgl+CKwEEjUeKK41+iTQKhVmPFSEBglWBVIdWggEBAQE X-IPAS-Result: A0D/AQCY/fxWkw4P49RdhDWzcogAgXCGDQKBPjkTAQEBAQEBAQERAQEBAQcNCQkhL0EOAYFdghQBAQEDAScLATgTCwsYCSUPBSiIRQENCAS8Fh+FPQELAR2KZIUKgl+CKwEEjUeKK41+iTQKhVmPFSEBglWBVIdWggEBAQE X-IronPort-AV: E=Sophos;i="5.24,422,1454972400"; d="scan'208";a="171840310" Received: from mout.web.de ([212.227.15.14]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Mar 2016 12:41:16 +0200 Received: from frosties.localnet ([134.3.242.84]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0Letgd-1ZwVNc41OB-00qheO for ; Thu, 31 Mar 2016 12:41:16 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.84) (envelope-from ) id 1ala2N-0004rJ-A8 for caml-list@inria.fr; Thu, 31 Mar 2016 12:41:15 +0200 Date: Thu, 31 Mar 2016 12:41:15 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20160331104114.GB17174@frosties> References: <56FBAA37.5080403@tu-berlin.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <56FBAA37.5080403@tu-berlin.de> User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:Qgn9dSczXKrJ0eHJsEClkl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] Infer least upper bound for arguments to functions in rows On Wed, Mar 30, 2016 at 12:28:07PM +0200, Christoph Höger wrote: > Dear experts, > > is there a way to infer a compatible type for the argument to t#x in the > function: > > let a t = ignore (t#x t) ; t#x (object end) ;; > > I can easily provide a compatible t, e.g.: > > let t = object method x _ = 23 end > > I can also use a coercion: > > let a t = ignore (t#x (t :> < >)) ; t#x (object end) ;; > > Since < > is the common supertype of both arguments. > > My problem is that in general < > won't suffice for the common type, and > finding it is a rather complicated process. I found that this is often a huge problem, esspecially for methods. You can't always coerce the type and type inference won't infere polymorphic methods (like t#x above). I've spend hours trying different ways to not run into "self type may not escape it's class" or "'a is unbound" errors. In the end I found a quite simple way: For each class (type) define a method as_ that returns (self :> name). That way you function or method does not take a supertype of some long winded, complex and possibly recursive class type but a simple supertype of a class having the as_ method and nothing else, e.g. method add_widget : 'a . ( as 'a) -> unit Coming up with the right as_ is straight forward and the type never gets longer than this no matter how complex classes are. > So I wonder if there is some > clever rewriting of the function that makes ocamlc infer that type for me? > > Is there any expression that for two (expressions with) different input > types yields (an expression of) the largest common supertype? > > regards, > > Christoph I don't think there is any way to get type inference to magically do the right thing here. The inferecne of polymorphic methods simply doesn't work that way. MfG Goswin