<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/12/8625cd8b15d41a5025c1435d3710629d"
  from="Remi Vanicat &lt;remi.vanicat@l...&gt;"
  author="Remi Vanicat"
  date="2003-12-09T12:07:57"
  subject="Re: [Caml-list] stream conversion"
  prev="2003/12/05180a6105b7a7c215e5df86df611690"
  next="2003/12/817e19365ada8715c95560fe9bc8c459"
  prev-in-thread="2003/12/3ae47766c120e8d93ed0b4d9330f4667"
  next-in-thread="2003/12/bc9dc2b12a47d4bcfa85daeb30c1aa27"
  prev-thread="2003/12/138d25e04135c86384c9d95218fd7b00"
  next-thread="2003/12/336da68464ef2651ac3a251d0d53f270"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] stream conversion">
<msg 
  url="2003/12/3ae47766c120e8d93ed0b4d9330f4667"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-12-09T07:56:15"
  subject="[Caml-list] stream conversion">
<msg 
  url="2003/12/8625cd8b15d41a5025c1435d3710629d"
  from="Remi Vanicat &lt;remi.vanicat@l...&gt;"
  author="Remi Vanicat"
  date="2003-12-09T12:07:57"
  subject="Re: [Caml-list] stream conversion">
<msg 
  url="2003/12/bc9dc2b12a47d4bcfa85daeb30c1aa27"
  from="Jean-Baptiste Rouquier &lt;jean-baptiste.rouquier@e...&gt;"
  author="Jean-Baptiste Rouquier"
  date="2003-12-09T16:58:50"
  subject="Re: [Caml-list] stream conversion">
<msg 
  url="2003/12/bac10dac5f02b6339a9ca9189c75cddc"
  from="brogoff@s..."
  author="brogoff@s..."
  date="2003-12-09T17:25:29"
  subject="Re: [Caml-list] stream conversion">
<msg 
  url="2003/12/95d033f811e1ab445412e643be3da233"
  from="Jean-Baptiste Rouquier &lt;jean-baptiste.rouquier@e...&gt;"
  author="Jean-Baptiste Rouquier"
  date="2003-12-09T17:40:23"
  subject="Re: [Caml-list] stream conversion">
</msg>
<msg 
  url="2003/12/5c54ecb9bfb3b517c0719bf7c74d646a"
  from="Tim Freeman &lt;tim@f...&gt;"
  author="Tim Freeman"
  date="2003-12-09T19:43:51"
  subject="Re: [Caml-list] stream conversion">
<msg 
  url="2003/12/7705bdf1a3ecb740b46d00b434db07f4"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2003-12-16T22:41:15"
  subject="Re: [Caml-list] stream conversion">
</msg>
</msg>
</msg>
<msg 
  url="2003/12/9947980da386f0a0a076c97377241cae"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-12-09T19:13:29"
  subject="Re: [Caml-list] stream conversion">
</msg>
</msg>
<msg 
  url="2003/12/6ca04e3679ec1004184b76bd53774151"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-12-09T19:15:21"
  subject="Re: [Caml-list] stream conversion">
</msg>
</msg>
<msg 
  url="2003/12/9ee9052e21abd29b23b1757d11f1890b"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2003-12-10T01:09:52"
  subject="Re: [Caml-list] stream conversion">
</msg>
</msg>
</thread>

<contents>
Dustin Sallings &lt;dustin@spy.net&gt; writes:

&gt; 	I have a need to convert a ``string stream'' to a ``char
&gt; stream.''  It's a little unclear to me how I'd accomplish this.  This
&gt; is the best I've been able to come up with so far, but I have to
&gt; imagine there's a prettier solution:
&gt;
&gt; let stream_convert source =
&gt;      let chunk = ref (Stream.of_string (Stream.next source)) in
&gt;      Stream.from (fun x -&gt;
&gt;          try
&gt;              Stream.empty !chunk;
&gt;              try
&gt;                  Stream.empty source;
&gt;                  None
&gt;              with Stream.Failure -&gt;
&gt;                  chunk := (Stream.of_string (Stream.next source));
&gt;                  Some (Stream.next !chunk)
&gt;          with Stream.Failure -&gt;
&gt;              Some (Stream.next !chunk)
&gt;      )
&gt; ;;
&gt;
&gt; 	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 -&gt;
    try 
      Some (Stream.next !chunk)
    with
      Stream.Failure -&gt;
       (* 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

</contents>

</message>

