caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] stream conversion
@ 2003-12-09  7:56 Dustin Sallings
  2003-12-09 12:08 ` Remi Vanicat
  2003-12-10  1:09 ` Nicolas Cannasse
  0 siblings, 2 replies; 10+ messages in thread
From: Dustin Sallings @ 2003-12-09  7:56 UTC (permalink / raw)
  To: Caml Mailing List


	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?

--
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-12-16 22:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-09  7:56 [Caml-list] stream conversion Dustin Sallings
2003-12-09 12:08 ` Remi Vanicat
2003-12-09 16:58   ` Jean-Baptiste Rouquier
2003-12-09 17:25     ` brogoff
2003-12-09 17:40       ` Jean-Baptiste Rouquier
2003-12-09 18:30       ` Tim Freeman
2003-12-16 22:42         ` Damien Doligez
2003-12-09 19:13     ` Dustin Sallings
2003-12-09 19:15   ` Dustin Sallings
2003-12-10  1:09 ` Nicolas Cannasse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).