From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p89BEOQt016634 for ; Fri, 9 Sep 2011 13:14:24 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8BAJz0aU7RVaC2kGdsb2JhbABChFWjMAgUAQEBAQkJDQcUBCKBRgEBAQECARICDwQZARseAwELBgULAwwCJgICIgERAQUBHAYuB4dUnB4KinxCgleFWTuIbQIDBoEmhDGBEQSHZ4tRjHI8g24 X-IronPort-AV: E=Sophos;i="4.68,355,1312149600"; d="scan'208";a="108265632" Received: from mail-gy0-f182.google.com ([209.85.160.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 09 Sep 2011 13:14:18 +0200 Received: by gyf2 with SMTP id 2so2335876gyf.27 for ; Fri, 09 Sep 2011 04:14:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=/wPm2PLw9Eml0rZqc0MsA6chSOXrExNODTNLOgSAuUY=; b=f3SHRI7G5c4KkvMcftHioaurpKEnGkDUTF0zqzFnuh1muCm8AJPrBVOyKCmbMGh9ZF XQXgv2azazC3Lrjyp/RC2/KYE7fwxOvLGnVguOzvzeAHVaygwayBdpc92cEggkaKcUTx FGK5NenSmIZPtZz/aaH0jenWZgQFInuxwnTY0= MIME-Version: 1.0 Received: by 10.42.29.196 with SMTP id s4mr227683icc.12.1315566857652; Fri, 09 Sep 2011 04:14:17 -0700 (PDT) Received: by 10.42.218.10 with HTTP; Fri, 9 Sep 2011 04:14:17 -0700 (PDT) In-Reply-To: <14203FCD-811F-41CC-A0D7-5A360D4815CA@math.nagoya-u.ac.jp> References: <14203FCD-811F-41CC-A0D7-5A360D4815CA@math.nagoya-u.ac.jp> Date: Fri, 9 Sep 2011 14:14:17 +0300 Message-ID: From: Dmitry Grebeniuk To: Jacques Garrigue Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] recursive module, object types, tying knot Hello. >> Error: This type scheme cannot quantify 'b : >> it escapes this scope. > The answer is unfortunately short: there is no solution. Thank you for the definitive and quick answer! > Namely recursive types in ocaml must be regular. > I.e., they must expand to a finite graph. > In particular this means that, inside the class lst, all occurences > of lst must have exactly the parameter 'a. Just interesting: where this graph and its finiteness property are used? > As you have already found, you can avoid this problem by > defining a record which "hides" the use of lst. > Namely, you must break the cycle with a datatype, > either record or sum type. > Unfortunately this also means that this type has to belong > to some module, and you also lose subtyping. I've tried to make the type (lst 'b) belong to some first-class module returned by some method call (to object with type lst 'a), but without any success. And while playing with first-class modules I've noted that I can't constrain the parametric type of module: let module M = (lst#mapmodule : Mappable with type t 'a = list a) -- one more way is blocked (but don't know was it the way really). But I can reformulate (and maybe make easier) my task: I can move the code that work with different type parameters (lst 'a -> lst 'b) to simple functions. For example, "map" for containers -- to the function like "container_map", which will work with containers (objects that have some methods), to make the code work: container_map func (new lst [1;2;3]); container_map func (new arr [|1;2;3|]). I understand that the imaginable "container_map" function should require some method with some type, that can give me the value of type lst 'b for lst 'a in case of lists, and the value of type arr 'b for arr 'a in case of arrays, but I can't write such type (even with first-class modules). Is it impossible too?