From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 72965BC69 for ; Tue, 2 Oct 2007 18:16:00 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CANsLAkdA6aLokGdsb2JhbACCOzaLRAEBAQEHBAQiBw X-IronPort-AV: E=Sophos;i="4.21,220,1188770400"; d="scan'208";a="17199543" Received: from nz-out-0506.google.com ([64.233.162.232]) by mail4-smtp-sop.national.inria.fr with ESMTP; 02 Oct 2007 18:15:59 +0200 Received: by nz-out-0506.google.com with SMTP id x7so2786204nzc for ; Tue, 02 Oct 2007 09:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=NxtS9I29nsYZPxRTACbtjJjSd/BNWPKb6simNLWa3H4=; b=mobmIVAkS8JXyRSMYkZkdi23Cz1NYJeKv4xBFkZBvW5zWRAzJR4ZGrE1NiApr4gGpa7s2fnGmdWdr6OwVJdqq5Kzk47etdfdNtNd8D7TcTAAmDYJYpg3PBRJ3SwlxkZLWPQAPodpaR3UF3dgXd21sIcQzjjlCMwud5HAc3O4uxE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=YHmtEj/YKHNJtKYX/QX0djD4/brTrdjTqpzrU2/6NZ8RaQNq8OLwhywkMKg2CF4OZqfXJ4rdfcAIa7IUQlN/WpJKkrf2H4hnRU/xpMEjoL5jJ+96Nuyx8/osVeOkI+0bTDAK9I6B5yWDR+DF7CNRGPXhyzw/qq9JENldv0qI4Zk= Received: by 10.114.38.2 with SMTP id l2mr2437155wal.1191341757810; Tue, 02 Oct 2007 09:15:57 -0700 (PDT) Received: by 10.114.25.8 with HTTP; Tue, 2 Oct 2007 09:15:57 -0700 (PDT) Message-ID: Date: Tue, 2 Oct 2007 18:15:57 +0200 From: kirillkh To: "Brian Hurt" Subject: Re: [Caml-list] best and fastest way to read lines from a file? Cc: caml-list@yquem.inria.fr In-Reply-To: <47024002.2080206@janestcapital.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_19023_11973677.1191341757805" References: <779bf2730710011427g5983da4cw6ad8b715a9e38771@mail.gmail.com> <47016CEE.8010704@crans.org> <200710021239.l92CdwZ15641@virtutech.se> <47024002.2080206@janestcapital.com> X-Spam: no; 0.00; iterating:01 combinator:01 invokes:01 combinator:01 byte:01 ocaml:01 trivial:01 trivial:01 iterating:01 invokes:01 byte:01 ocaml:01 char:01 char:01 faq:01 ------=_Part_19023_11973677.1191341757805 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > This should be a FAQ. > Since we're talking of 10+ lines of code and only one case among many possible (you might also want to do something fairly similar, but not quite the same, as iterating over all words or characters in a file, doing something else than counting, etc.), I would rather see it implemented in a library as combinator. What I have in mind is a function that goes over a file and invokes some user code on each block of bytes/characters/lines/words/... The points of customization would be: * how to detect the start and end of block * routine to pass the blocks to Then, on top of this combinator, build block-specific ones: for byte, char, line, word blocks. Also make it possible to customize buffering behavior. Being new to OCaml, I'm interested in comments - is what I suggest a good idea? If yes, why hasn't anyone implemented it yet? One could argue that it's trivial and can be implemented in each use case anew, but among 5 different solutions posted so far, each has its own problems, besides the supposedly ideal 5-th -- I'd take this as an indication that, although simple, it's not really trivial to write this thing. ------=_Part_19023_11973677.1191341757805 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
This should be a FAQ.

Since we're talking of 10+ lines of code and only one case among many possible (you might also want to do something fairly similar, but not quite the same, as iterating over all words or characters in a file, doing something else than counting, etc.), I would rather see it implemented in a library as combinator. What I have in mind is a function that goes over a file and invokes some user code on each block of bytes/characters/lines/words/... The points of customization would be:
* how to detect the start and end of block
* routine to pass the blocks to

Then, on top of this combinator, build block-specific ones: for byte, char, line, word blocks. Also make it possible to customize buffering behavior.

Being new to OCaml, I'm interested in comments - is what I suggest a good idea? If yes, why hasn't anyone implemented it yet? One could argue that it's trivial and can be implemented in each use case anew, but among 5 different solutions posted so far, each has its own problems, besides the supposedly ideal 5-th -- I'd take this as an indication that, although simple, it's not really trivial to write this thing.
------=_Part_19023_11973677.1191341757805--