English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] stream conversion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-12-09 (07:56)
From: Dustin Sallings <dustin@s...>
Subject: [Caml-list] stream conversion

	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 ->
             Stream.empty !chunk;
                 Stream.empty source;
             with Stream.Failure ->
                 chunk := (Stream.of_string (Stream.next source));
                 Some (Stream.next !chunk)
         with Stream.Failure ->
             Some (Stream.next !chunk)

	Any suggestions?

SPY                      My girlfriend asked me which one I like better.
pub  1024/3CAE01D5 1994/11/03 Dustin Sallings <dustin@spy.net>
|    Key fingerprint =  87 02 57 08 02 D0 DA D6  C8 0F 3E 65 51 98 D8 BE
L_______________________ I hope the answer won't upset her. ____________

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