From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA00698; Tue, 9 Dec 2003 13:07:57 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA27766 for ; Tue, 9 Dec 2003 13:07:56 +0100 (MET) Received: from mwinf0602.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.25]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hB9C7tr20169 for ; Tue, 9 Dec 2003 13:07:56 +0100 (MET) Received: from debian (ca-bordeaux-11-bdcst.w80-8.abo.wanadoo.fr [80.8.83.255]) by mwinf0602.wanadoo.fr (SMTP Server) with ESMTP id A066B54002DB for ; Tue, 9 Dec 2003 13:07:55 +0100 (CET) Received: from moi by debian with local (Exim 3.36 #1 (Debian)) id 1ATgf0-00012p-00 for ; Tue, 09 Dec 2003 13:08:14 +0100 To: caml-list@inria.fr Subject: Re: [Caml-list] stream conversion References: <2111F26F-2A1D-11D8-8637-000393CB0F1E@spy.net> From: Remi Vanicat Mail-Copy-To: never Date: Tue, 09 Dec 2003 13:08:13 +0100 In-Reply-To: <2111F26F-2A1D-11D8-8637-000393CB0F1E@spy.net> (Dustin Sallings's message of "Mon, 8 Dec 2003 23:56:00 -0800") Message-ID: <87brqi8a8i.dlv@wanadoo.fr> User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 char:01 prettier:01 writes:01 remi:01 remi:01 vanicat:01 vanicat:01 string:03 string:03 chunk:03 chunk:03 let:04 let:04 assumption:06 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Dustin Sallings writes: > I have a need to convert a ``string stream'' to a ``char > stream.'' It's a little unclear to me how I'd accomplish this. This > is the best I've been able to come up with so far, but I have to > imagine there's a prettier solution: > > let stream_convert source = > let chunk = ref (Stream.of_string (Stream.next source)) in > Stream.from (fun x -> > try > Stream.empty !chunk; > try > Stream.empty source; > None > with Stream.Failure -> > chunk := (Stream.of_string (Stream.next source)); > Some (Stream.next !chunk) > with Stream.Failure -> > Some (Stream.next !chunk) > ) > ;; > > Any suggestions? why do you use Stream.empty ? it would be more natural to use only Stream.next. As in : let stream_convert source = let chunk = ref (Stream.of_string (Stream.next source)) in Stream.from (fun x -> try Some (Stream.next !chunk) with Stream.Failure -> (* code needed when the chunk is empty *) ) By the way, your code make the assumption that no string in the source stream are empty (look at what would happen in such case). -- Rémi Vanicat ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners