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 6EF66800DB for ; Thu, 9 Mar 2017 20:18:03 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-qk0-f175.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.220.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.220.175 as permitted sender) identity=mailfrom; client-ip=209.85.220.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; 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@mail-qk0-f175.google.com) identity=helo; client-ip=209.85.220.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-qk0-f175.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AI9baaxdeVST6UUTWScTSv75glGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxcW9Zh7h7PlgxGXEQZ/co6odzbGH7ua8BydZuMfJmUtBWaQEbwUCh8?= =?us-ascii?q?QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6?= =?us-ascii?q?OPn+FJLMgMSrzeCy/IDYbxlViDanb75/KBW7oR/eu8QXjoduN7s9xx/UqXZUZu?= =?us-ascii?q?pawn9lK0iOlBjm/Mew+5Bj8yVUu/0/8sNLTLv3caclQ7FGFToqK2866tHluhnF?= =?us-ascii?q?VguP+2ATUn4KnRpSAgjK9w/1U5HsuSbnrOV92S2aPcrrTbAoXDmp8qlmRAP0hC?= =?us-ascii?q?oBKjU063/chNBug61HoRKhvx1/zJDSYIGJL/p1Y6fRccoHSWZdQspdUipMDYSh?= =?us-ascii?q?YYsSFOoBJfhXoJXhp1UAqhu+ABOjBOLpyjRVgnP70qk33+EnHArb3gIvAsgOvW?= =?us-ascii?q?zWo9X7NKkcX+O7wrTWwzrfYP1bwiv96JHSfxw9vf2AQbB9fMzMwkcvDQPFiVCQ?= =?us-ascii?q?pJTkMTyPzesNqWmb4PRkVemylmAotwFxrSa1xsgykInCm4UYyl/e+ipi2oY1JM?= =?us-ascii?q?O3SEphbd6/DJRQtz+VN5FoTcM4WGxotyM6xacHuZ6/ZiQF1JMnxxvGZvGBboOG?= =?us-ascii?q?7BXjVOOLLjd5gnJoYLO/hxCo8Uih0OLwTMe00ExSoitFiNbMtncN1xvJ5sebTf?= =?us-ascii?q?t9+0Gs0iuM2QDL8uxIP1w4mK7BJ5MiwrM8jIQfvVrfEiPshUn7jq+be0M58eay?= =?us-ascii?q?8evneK/pppqEOo90lA7+NqMul9S6AesiMwgOW3GX+f2/1LH/5EH5TqhGg/82n6?= =?us-ascii?q?XDv5DaIsMbpqG9AwBLyIos9xG/DzK+3NQZm3kIMk5FdQqZg4T1P1zCOvP1APel?= =?us-ascii?q?j1iyjjtn2+rKMqDjD5jNNnTDla3ufbd5605S0gozytVf6opbCr4bO/3zQE7xu8?= =?us-ascii?q?LcDhMjKAy73+bnB8tn1owAQ2KCGaCZMKbIvl+J4uIjOfWDZIgQuDrlMfgq++bu?= =?us-ascii?q?jWMlmV8aZaSp04MXaHekHvR6IkWWf2Dsj8wAEGcLuwoxV/bqh0eYXT5SYXayRa?= =?us-ascii?q?M86SshBIKoF4fJXpqtj6CZ3CenAp1WYXhLBUyWHnftc4WIQvMMaCOJIs99iTEE?= =?us-ascii?q?TrigS4o51R60rgP6yrxnLvDV+iICr57j2sJ1tKXvkkQc7zVygMOcyFa1SH1on2?= =?us-ascii?q?4SD2s4xql5qkt80RGb1rRkgvFCPd1V/fJAFAkgY83y1et/Xv/7UBjAc9PBc12m?= =?us-ascii?q?T8+rG3llQds72d4DZwBmENWvlB3Z9yWvCr4R0beMAcpnoernw3HtKpMlmD7936?= =?us-ascii?q?47ggxjH5JC?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CZAQDEqcFYhq/cVdFdFgQBAQEBAgEBA?= =?us-ascii?q?QEIAQEBARUBAQEBAgEBAQEIAQEBAYNIP4EKB4NZm1uCOoZBjksqhXgCgioHQxQ?= =?us-ascii?q?BAQEBAQEBAQEBARIBAQEICwsIKC+CMyKCQQECAyMEGQEbEgsBAwwGBQsNAgIJH?= =?us-ascii?q?QICIgERAQUBChIGExIJiUwBAxUOpFA/jAOBbBgFARyDCQWDXgoZJwMKVYJOAQE?= =?us-ascii?q?BAQEBAQMBAQEBAQEaAgYSeYVDg2aBCYRUgwaCXwWHPwyBYocqi2KCA4Rzi0KCT?= =?us-ascii?q?otngmuRdxQfgRU2gSQiFR9UF4QuDxEMggEiNYorAQEB?= X-IPAS-Result: =?us-ascii?q?A0CZAQDEqcFYhq/cVdFdFgQBAQEBAgEBAQEIAQEBARUBAQE?= =?us-ascii?q?BAgEBAQEIAQEBAYNIP4EKB4NZm1uCOoZBjksqhXgCgioHQxQBAQEBAQEBAQEBA?= =?us-ascii?q?RIBAQEICwsIKC+CMyKCQQECAyMEGQEbEgsBAwwGBQsNAgIJHQICIgERAQUBChI?= =?us-ascii?q?GExIJiUwBAxUOpFA/jAOBbBgFARyDCQWDXgoZJwMKVYJOAQEBAQEBAQMBAQEBA?= =?us-ascii?q?QEaAgYSeYVDg2aBCYRUgwaCXwWHPwyBYocqi2KCA4Rzi0KCTotngmuRdxQfgRU?= =?us-ascii?q?2gSQiFR9UF4QuDxEMggEiNYorAQEB?= X-IronPort-AV: E=Sophos;i="5.36,137,1486422000"; d="scan'208";a="216208142" Received: from mail-qk0-f175.google.com ([209.85.220.175]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 09 Mar 2017 20:18:02 +0100 Received: by mail-qk0-f175.google.com with SMTP id p64so135371765qke.1; Thu, 09 Mar 2017 11:18:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=UhJyfEHo+ZXsH/0VqJpA7EMSD9U+JfS7BpXQS2o+FxU=; b=kc8pGW868PQ4iVaiAKg6gbTF89GnZp2Bv8AWfmxUMBmcsvb7MI3pWv79Q60GfkQDey JTTqOxB/qnm1PpNmeBGUFXpnrgH0Usxr7o1H4xDVdxIvrjIOpRDsA2WEWdVE6L26eji/ II4Jq+ALA4b6ILpx3lmkFYvn7IZgO/K/cTnF4OalW8agY50yQR6P3SmSDAFi4FnNb5MV IbGtg40jTCGH3erEZh0i0yakGM/8b2Y0PFrH1LR6Mwk4ulH+yyrjLaR6u1CoE0Rq5Mq9 wDUaHwS+RXrJKydO7S8mrXYF12sfnFCGv2mYzNIzRw7eHu7DLKMwpQoLbv8mU1AKsA49 ZCjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=UhJyfEHo+ZXsH/0VqJpA7EMSD9U+JfS7BpXQS2o+FxU=; b=JDpeuZo+lkt0iIOebzLodzyoSwkO/dTLr1kNQ/NZTkACaH+x3vK3PdjxsA1xv8E2zC a40TIeY0SVgNnK+++t9j91Gz+Vd7yYKkWrjDUt4gKR/g/3/UqL38ZwUPrO9gfHH2voJ1 WtEl6qpzO5TH2W2Xp10+QOS48JlwKA9uEFuoqncUaqYTGrP1o88ZfH5oknwFnwR9JD3I Rd2sMBVKFP595xhJUpg1jGePE5Q1b8eTFE/RfIhwTkoZqrJ27IVuVvf5maUOS2Jlbh7u Lt+IInrM+cB7Yj/pX3aKcDOR1QCRgLNcsE62yEoazV0aJvoof5HHxDY2Ts9kYxEd8PY7 skzA== X-Gm-Message-State: AFeK/H3VJGGuX1cVoKnYu/lS5WlOAQNTcS82AF75JFzAAuXT25TSTe9IHsaIlVsRhnnypq81EPTnoUJVeo6lTw== X-Received: by 10.55.79.23 with SMTP id d23mr15900531qkb.172.1489087080344; Thu, 09 Mar 2017 11:18:00 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.156.8 with HTTP; Thu, 9 Mar 2017 11:17:19 -0800 (PST) In-Reply-To: <58C19FF4.1030200@inria.fr> References: <58C19FF4.1030200@inria.fr> From: Gabriel Scherer Date: Thu, 9 Mar 2017 14:17:19 -0500 Message-ID: To: =?UTF-8?Q?Fran=C3=A7ois_Pottier?= Cc: KC Sivaramakrishnan , caml users Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] [ANN] New release of visitors This use of the monoid structure is very nice. I believe that you could cut through the intermediate tree structure as follows. Is there any downside? type 'a delayed_tree =3D 'a cascade -> 'a cascade let delayed_tree_to_cascade k =3D k nil let delayed_tree_to_iterator (dt : 'a delayed_tree) : 'a iterator =3D cascade_to_iterator (delayed_tree_to_cascade dt) type 'a delay =3D 'a class ['self] delayed_tree_monoid =3D object (_ : 'self) method zero =3D fun k -> k method plus s1 s2 =3D fun k -> s1 (s2 k) method visit_delay : 'env 'a . ('env -> 'a -> 'b delayed_tree) -> 'env -> 'a delay -> 'b delayed_tree =3D fun visit_ env x k -> (fun () -> visit_ env x k ()) end let yield _env x =3D fun k () -> Cons (x, k) On Thu, Mar 9, 2017 at 1:33 PM, Fran=C3=A7ois Pottier wrote: > > Dear KC, > > On 09/03/2017 12:53, KC Sivaramakrishnan wrote: >> >> Thanks for the wonderful library and the excellent documentation. I have >> a feature request. Could you provide a python-style generator for >> traversing the data structure on demand? For a binary tree: >> >> type 'a t =3D Leaf | Node of 'a t * 'a * 'a t >> >> I envision a `mk_gen` function: >> >> val mk_gen : 'a t -> (unit -> 'a option) >> (** [mk_gen t] returns a generator function [f], which when invoked >> performs 1-step of the traversal and returns [Some v], where [v] >> is the node value. [f] returns [None] when the traversal is don= e. >> *) > > > Thanks for this excellent question, which I had not thought about. > > A quick answer might be that, if you are using OCaml + effect handlers, > it should be fairly easy for you to perform control inversion and turn > a producer-controlled traversal (as performed by an [iter] visitor) into > a consumer-controlled traversal. > > That said, I was able to come up with a solution in pure OCaml. It is > somewhat > unexpected and (I think) quite nice, so I am posting it (with comments) on > the > list (see attached file). If there is demand, most of this code could be > made > part of the VisitorsRuntime library. > > Best regards, > > > -- > Fran=C3=A7ois Pottier > francois.pottier@inria.fr > http://gallium.inria.fr/~fpottier/ > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs