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 AC7667EE6B for ; Tue, 3 Dec 2013 09:35:03 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain@frisch.fr) identity=pra; client-ip=193.252.23.211; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="alain@frisch.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain@frisch.fr) identity=mailfrom; client-ip=193.252.23.211; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="alain@frisch.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@msa.smtpout.orange.fr) identity=helo; client-ip=193.252.23.211; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="postmaster@msa.smtpout.orange.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnYBAGaXnVLB/BfTnGdsb2JhbABahwyyaIMFgS8OAQEBAQEICwkJFCiCJQEBBSMEEUABEAsYAgIFFgsCAgkDAgECAUUGAQwBBwEBFgGHarBPkDoXgSmNIjMHgmuBSAOYFIZFjng X-IPAS-Result: AnYBAGaXnVLB/BfTnGdsb2JhbABahwyyaIMFgS8OAQEBAQEICwkJFCiCJQEBBSMEEUABEAsYAgIFFgsCAgkDAgECAUUGAQwBBwEBFgGHarBPkDoXgSmNIjMHgmuBSAOYFIZFjng X-IronPort-AV: E=Sophos;i="4.93,816,1378850400"; d="scan'208";a="39045220" Received: from msa02.smtpout.orange.fr (HELO msa.smtpout.orange.fr) ([193.252.23.211]) by mail3-smtp-sop.national.inria.fr with ESMTP; 03 Dec 2013 09:35:03 +0100 Received: from [192.168.1.132] ([92.151.88.188]) by mwinf5d58 with ME id wwb01m00H43pGFQ03wb1zd; Tue, 03 Dec 2013 09:35:02 +0100 Message-ID: <529D97B4.9070108@frisch.fr> Date: Tue, 03 Dec 2013 09:35:00 +0100 From: Alain Frisch User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: Jeremy Yallop , Dmitri Boulytchev CC: caml-list References: <529BAB43.3080105@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Confusing behaviour of type inference for polymorphic classes. On 12/02/2013 04:24 PM, Jeremy Yallop wrote: > There's good news and bad news. The good news is that the problem can > be solved for your particular example. The bad news is that the > approach doesn't work in the general case. A more general solution is based on recursive modules: ======================================================================= type ('a, 'b) t = A of 'a * ('b, 'a) t | B of 'a module rec X : sig class ['a, 'b, 'ta, 'tb] m : object method t : ('a -> 'ta) -> ('b -> 'tb) -> ('a, 'b) t -> ('ta, 'tb) t end end = struct class ['a, 'b, 'ta, 'tb] m = object method t : ('a -> 'ta) -> ('b -> 'tb) -> ('a, 'b) t -> ('ta, 'tb) t = fun fa fb s -> match s with | A (a, bat) -> A (fa a, (new X.m)#t fb fa bat) | B a -> B (fa a) end end ======================================================================= This technique also works e.g. for defining mutually recursive classes and nominal types. Alain