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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 5F9737FA80 for ; Fri, 23 Oct 2015 08:48:44 +0200 (CEST) IronPort-PHdr: 9a23:eCzueBDmlnXlimHn/K+uUyQJP3N1i/DPJgcQr6AfoPdwSP7zosbcNUDSrc9gkEXOFd2CrakU1qyO7uu5ADdIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/niqbqptaKOl4ArQH+SI0xBS3+lR/WuMgSjNkqAYcK4TyNnEF1ff9Lz3hjP1OZkkW0zM6x+Jl+73YY4Kp5pIZoGJ/3dKUgTLFeEC9ucyVsvJWq5lH/Sl6s52ARVnQRjFJvBwXKpEX9Wpr+miz5s+t/ni6AMpulY6ozXGGA5qxyVRLzwAgOLSQ4/3zawph/hbhBoR28qjR6ypLUJoecO/1vd+bAO9oRA2hZCJUCHxddC5+xOtNcR9EKOvxV+syk/wMD Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=garrigue@math.nagoya-u.ac.jp; spf=None smtp.mailfrom=garrigue@math.nagoya-u.ac.jp; spf=None smtp.helo=postmaster@mailhost.math.nagoya-u.ac.jp Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=pra; client-ip=133.6.130.5; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=mailfrom; client-ip=133.6.130.5; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mailhost.math.nagoya-u.ac.jp) identity=helo; client-ip=133.6.130.5; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="postmaster@mailhost.math.nagoya-u.ac.jp"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DkAAAD2ClWlwWCBoVehHm+M4FZhh0CgX0TAQEBAQEBAQEQAQEBAQEIFgdPgiuCCAEBBCMEGQMBNQEBDgsYAgIYDgICVwYuiBSxbXGEawKJbIQYAQEBAQEBAQMBAQEBAQEBAQETAQaBIodlgm6EWjMHgmkxgRSNGXSII40enCYjA4JkgWtjhkMBAQE X-IPAS-Result: A0DkAAAD2ClWlwWCBoVehHm+M4FZhh0CgX0TAQEBAQEBAQEQAQEBAQEIFgdPgiuCCAEBBCMEGQMBNQEBDgsYAgIYDgICVwYuiBSxbXGEawKJbIQYAQEBAQEBAQMBAQEBAQEBAQETAQaBIodlgm6EWjMHgmkxgRSNGXSII40enCYjA4JkgWtjhkMBAQE X-IronPort-AV: E=Sophos;i="5.20,185,1444687200"; d="scan'208";a="184118310" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail2-smtp-roc.national.inria.fr with ESMTP; 23 Oct 2015 08:48:15 +0200 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 906026427; Fri, 23 Oct 2015 15:48:14 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (rabbit-172 [172.16.254.254]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 238E624CB; Fri, 23 Oct 2015 15:48:14 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s=alpha; bh=st/TWXB9on+CehAZFV8Y57WBAyE=; b=h9vdCYNzHa3kJxDBNHevvKOo0sK2 FkRYb6KPVH4o1dTi4yTGs/9MNi7HT5PinhcJFCLH8Ng9/LAsDhwp7YdwyWJIoZhN RD1JBCIopKhZZ9PwwGBoGC/2FkPURGA7M05fiNHY5d4tpDv4f4aZsOVNQaRIMF00 xx83IdgqDf3OZ4g= DomainKey-Signature: a=rsa-sha1; h=Received:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=agC3DuHdWq0vbxsNQI9Jyj8dsIMHMRuJ8hvqU8yAuPHLFliXC79W+Oz5VPGIUfpCv7gwOyM2NA3kgRJAJEzVtwWIaad13MR0vhYzE90zubJO1kgsG5r6F0+0wgX3vb9aGbLSzRkGmv5x2MH//Und6w6BbADqNNaXVsJtdwgB20o=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; s=alpha Received: from tet.garrigue.jp (58x158x128x157.ap58.ftth.ucom.ne.jp [58.158.128.157]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTPSA id 4F8C165A4; Fri, 23 Oct 2015 15:46:56 +0900 (JST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) From: Jacques Garrigue In-Reply-To: <20151022150430.GA2917@Magus.sf-private> Date: Fri, 23 Oct 2015 15:48:12 +0900 Cc: seliopou@gmail.com, OCaML List Mailing Content-Transfer-Encoding: quoted-printable Message-Id: References: <20151022150430.GA2917@Magus.sf-private> To: Kiselyov Oleg X-Mailer: Apple Mail (2.2104) Subject: Re: [Caml-list] "map"-ing parameterized class types Hi Oleg, The externalizing solution has been known since the beginning of OCaml, but it is nice to know that it has such a cute name=E2=80=A6 Jacques On 2015/10/23 00:04, Oleg wrote: >=20 > The question was about creating a class of the following type >=20 >> class type ['a] container : 'a -> >> object >> method map : 'b. ('a -> 'b) -> 'b container >> end >=20 > with a mapping method that makes a container of a different > type. Jeremy Yallop has explained very well the class of exactly such > type is not possible. The following is perhaps the simplest workaround > requiring neither modules nor other higher-class artillery. It should > have been possible even in OCaml 3.10 or earlier. >=20 > The idea was inspired by some high-falutin' Math, namely, left Kan > extension from Category Theory. I actually don't know CT but I think I > got the gist of the left Kan extension: rather than execute an an > operation, just collect all the needed arguments and declare the > operation performed. The recent paper on Freer monads (Haskell > Symposium 2015) used two instances of this new kind of laziness. >=20 > Here is the whole solution >=20 > type 'a cont_proxy =3D P of 'a >=20 > class ['a] container (x : 'a) =3D object > method get_x =3D x > method map' : 'b. ('a -> 'b) -> 'b cont_proxy =3D fun f -> > P (f x) > end >=20 > The class container has one argument, which is the value needed to > construct the container. The data type cont_proxy contains all the > information needed to construct the container, but not the container > itself (for one, the container type is not yet defined when we > declared P). The method map' doesn't actually construct anything; it > merely returns the data needed for the construction. >=20 > The map itself is then easy to define: >=20 > let map : ('a -> 'b) -> ('a container -> 'b container) =3D fun f c -> > match c#map' f with > P x -> new container x >=20 > let c =3D new container 3 > val c : int container =3D > let _ =3D c#get_x > - : int =3D 3 > let c' =3D map string_of_int c > val c' : string container =3D > let _ =3D c'#get_x > - : string =3D "3"