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 025B27EEAF for ; Wed, 23 Jan 2013 11:15:39 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of raphlalou@gmail.com) identity=pra; client-ip=209.85.223.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="raphlalou@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of raphlalou@gmail.com designates 209.85.223.174 as permitted sender) identity=mailfrom; client-ip=209.85.223.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="raphlalou@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-ie0-f174.google.com) identity=helo; client-ip=209.85.223.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="postmaster@mail-ie0-f174.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4BANm2/1DRVd+um2dsb2JhbABEhkWlDJJQCBYOAQEBAQEICQsJFCeCHgEBBAEjBBkBGxILAQMMBgULAwoCAgkdAgIiAREBBQEKEgYTEgmHawEDCQYMnkyLZU+Ce4R2ChknAwpZiHYBBQyBF459gRMDlgyBHI1MFimEFw X-IPAS-Result: Ah4BANm2/1DRVd+um2dsb2JhbABEhkWlDJJQCBYOAQEBAQEICQsJFCeCHgEBBAEjBBkBGxILAQMMBgULAwoCAgkdAgIiAREBBQEKEgYTEgmHawEDCQYMnkyLZU+Ce4R2ChknAwpZiHYBBQyBF459gRMDlgyBHI1MFimEFw X-IronPort-AV: E=Sophos;i="4.84,520,1355094000"; d="scan'208";a="6291" Received: from mail-ie0-f174.google.com ([209.85.223.174]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Jan 2013 11:15:38 +0100 Received: by mail-ie0-f174.google.com with SMTP id k11so7394332iea.5 for ; Wed, 23 Jan 2013 02:15:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:content-transfer-encoding; bh=AJatxAtFmNXJLXuJw1iiSQG4I11XycCrn0k7wTz9hvE=; b=bMvYZZWBK8+Nqeqka49B6xH5ToY6fVt40gNK+IrmPx6ZBQ6Vu+oCxmTQxstviXkKAZ qJG+oZDXLb2lh96zm99GXo7cOBlaxW9VeL4jewkxqgL5In4RzBq60ibco03KevLPN7+U j+gOzQnaU2ilAMbuokuci3GM62jAPmr7TyeafiMwCPh0w7s1ydN0pXL2XcLReuvW4Y7v 1aB1dNt5/t5zOnfwMYMULj4BrSk7RVCJ3+uYdlNWa4Rr7ixv8449y8sLVZjUzCfNxMcF nDD3xziqcbje5dAoCPthpWAeutMWj0yOerlD0T9q15ux8sGRUfihdhhqOusL/dFpt8Ii Opkg== MIME-Version: 1.0 X-Received: by 10.50.222.132 with SMTP id qm4mr555896igc.99.1358936137821; Wed, 23 Jan 2013 02:15:37 -0800 (PST) Received: by 10.42.197.198 with HTTP; Wed, 23 Jan 2013 02:15:37 -0800 (PST) In-Reply-To: <87pq0w4hlh.fsf@golf.niidar.ru> References: <87pq0w4hlh.fsf@golf.niidar.ru> Date: Wed, 23 Jan 2013 10:15:37 +0000 Message-ID: From: Raphael Proust To: Ivan Gotovchits Cc: caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Lwt idioms: iterating On Wed, Jan 23, 2013 at 5:02 AM, Ivan Gotovchits wrote: > > What is a best practice to implement a common iterative operations with > Lwt? > > For example, I have a data structure incapsulating some > collection. Interface of the structure includes some iterators, i.e. > > val iter (e -> unit) -> t -> unit > > > Now, I would like to output each element of type e using one of the > functions from Lwt_io module. > > I see two solutions and neither I like: > > 1. Use Buffer.t to accumulate text while iterating, then output it. > > 2. Use Lwt_stream.t for the same purpose. 3. Just write it directly and trust the Lwt scheduler to flush the write bu= ffer. The page https://ocsigen.org/lwt/api/Lwt_io explains that writes are automatically flushed ``when there is nothing else to do'' ~~~~~~~ If you are familiar with buffered channels you may be familiar too with the flush operation. Note that byte channles of this modules are automatically flushed when there is nothing else to do (i.e. before the program goes into idle), so this means that you no longer have to write: eprintf "log message\n"; flush stderr; to have you messages displayed. ~~~~~~~ > > Both solutions a rather imperative and too ad-hoc (not scales to other > iterators and tasks). > > Are there any idiomatic solutions for such common tasks in Lwt? > > -- > (__) > (oo) > /------\/ > / | || > * /\---/\ > ~~ ~~ > ...."Have you mooed today?"... > > -- > 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 --=20 ______________ Rapha=C3=ABl Proust