<?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="2002/07/f3f66088ad1575a8c6b10b09ffdfcded"
  from="Michael Vanier &lt;mvanier@c...&gt;"
  author="Michael Vanier"
  date="2002-07-07T09:20:21"
  subject="Re: [Caml-list] yet another question on lazy lists"
  prev="2002/07/362b26b59e19e369fc41bedf17213b18"
  next="2002/07/7a6ee632d474fca6535ff230e8cf2e20"
  prev-in-thread="2002/07/d1b9c9518820db66620939f4ea73e1a4"
  next-in-thread="2002/07/99c5bb60f441d6e61974021204d72812"
  prev-thread="2002/07/1eefe810f7f0f0aa410a2eab708b2234"
  next-thread="2002/07/061b98c60a3aae3e13a775ccfea73028"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] yet another question on lazy lists">
<msg 
  url="2002/07/746ede35d7b862c4b263842d67508891"
  from="Michael Vanier &lt;mvanier@c...&gt;"
  author="Michael Vanier"
  date="2002-07-06T14:18:48"
  subject="[Caml-list] yet another question on lazy lists">
<msg 
  url="2002/07/efd8bf1158b6562718435420a02fd7f2"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2002-07-06T15:26:37"
  subject="Re: [Caml-list] yet another question on lazy lists">
<msg 
  url="2002/07/d1b9c9518820db66620939f4ea73e1a4"
  from="William Lovas &lt;wlovas@s...&gt;"
  author="William Lovas"
  date="2002-07-06T18:22:57"
  subject="Re: [Caml-list] yet another question on lazy lists">
<msg 
  url="2002/07/f3f66088ad1575a8c6b10b09ffdfcded"
  from="Michael Vanier &lt;mvanier@c...&gt;"
  author="Michael Vanier"
  date="2002-07-07T09:20:21"
  subject="Re: [Caml-list] yet another question on lazy lists">
<msg 
  url="2002/07/99c5bb60f441d6e61974021204d72812"
  from="John Max Skaller &lt;skaller@o...&gt;"
  author="John Max Skaller"
  date="2002-07-08T00:34:06"
  subject="Re: [Caml-list] yet another question on lazy lists">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>

&gt; Date: Sat, 6 Jul 2002 14:22:52 -0400
&gt; From: William Lovas &lt;wlovas@stwing.upenn.edu&gt;
&gt; 
&gt; On Sat, Jul 06, 2002 at 05:26:33PM +0200, Pierre Weis wrote:
&gt; &gt; &gt;  Does this mean
&gt; &gt; &gt; that my "stream_cons" function is useless?
&gt; &gt; &gt;
&gt; &gt; &gt; Thanks in advance,
&gt; &gt; &gt; 
&gt; &gt; &gt; Mike
&gt; &gt; 
&gt; &gt; No. It means you cannot always use it in place of a constructor
&gt; &gt; application. Note that a similar phenomenon occurs for pattern
&gt; &gt; matching: constructors are mandatory, you cannot subtitute them by
&gt; &gt; equivalent function calls!
&gt; 
&gt; Actually, i think stream_cons may be useless, due to OCaml's eager
&gt; evaluation strategy.  If you try to delegate the recursion to a function
&gt; call, the following happens:
&gt; 
&gt;     # let rec constant n = stream_cons n (constant n);;
&gt;     val constant : 'a -&gt; 'a stream = &lt;fun&gt;
&gt;     # constant 1;;
&gt;     Stack overflow during evaluation (looping recursion?).
&gt; 
&gt; ... but the constructor still works:
&gt; 
&gt;     # let rec constant n = Cons (n, lazy (constant n));;
&gt;     val constant : 'a -&gt; 'a stream = &lt;fun&gt;
&gt;     # constant 1;;
&gt;     - : int stream = Cons (1, {contents = Lazy.Delayed &lt;fun&gt;})
&gt; 
&gt; The second argument needs to be treated lazily (which it is, explicitly, 
&gt; using the Cons constructor call), but stream_cons will never achieve that,
&gt; unless i'm missing something.
&gt; 
&gt; William

You're right.  I realized this shortly after sending out the question.
Because of ocaml's eager evaluation, the whole point of 'stream_cons' is
thwarted by writing it as a function, because by definition all the
arguments to the function are evaluated.  I got confused because I was
trying to imitate some scheme code from SICP in ocaml, and there was (what
looked like) a 'stream-cons' function in the SICP code.  It turns out that
'stream-cons' has to be implemented as a macro in scheme (a point glossed
over in SICP).

&gt; 
&gt; P.S. Michael, why not call your type something like `lazy_list', instead of
&gt; `stream'?  The latter conjures up images of stateful Stream.t's, for me at
&gt; least.  Just a thought!

Right again.  This is SICP terminology.  I'll change it if I post any more
questions on this subject to this list.

Thanks for your input (and to Pierre Weis for his explanation of the error
message).

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

