From: William Lovas <wlovas@stwing.upenn.edu>
To: caml-list@inria.fr
Subject: Re: [Caml-list] yet another question on lazy lists
Date: Sat, 6 Jul 2002 14:22:52 -0400 [thread overview]
Message-ID: <20020706182252.GA23247@force.stwing.upenn.edu> (raw)
In-Reply-To: <200207061526.RAA06532@pauillac.inria.fr>
On Sat, Jul 06, 2002 at 05:26:33PM +0200, Pierre Weis wrote:
> > Does this mean
> > that my "stream_cons" function is useless?
> >
> > Thanks in advance,
> >
> > Mike
>
> No. It means you cannot always use it in place of a constructor
> application. Note that a similar phenomenon occurs for pattern
> matching: constructors are mandatory, you cannot subtitute them by
> equivalent function calls!
Actually, i think stream_cons may be useless, due to OCaml's eager
evaluation strategy. If you try to delegate the recursion to a function
call, the following happens:
# let rec constant n = stream_cons n (constant n);;
val constant : 'a -> 'a stream = <fun>
# constant 1;;
Stack overflow during evaluation (looping recursion?).
... but the constructor still works:
# let rec constant n = Cons (n, lazy (constant n));;
val constant : 'a -> 'a stream = <fun>
# constant 1;;
- : int stream = Cons (1, {contents = Lazy.Delayed <fun>})
The second argument needs to be treated lazily (which it is, explicitly,
using the Cons constructor call), but stream_cons will never achieve that,
unless i'm missing something.
William
P.S. Michael, why not call your type something like `lazy_list', instead of
`stream'? The latter conjures up images of stateful Stream.t's, for me at
least. Just a thought!
-------------------
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
next prev parent reply other threads:[~2002-07-06 18:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-06 1:48 Michael Vanier
2002-07-06 15:26 ` Pierre Weis
2002-07-06 18:22 ` William Lovas [this message]
2002-07-07 0:26 ` Michael Vanier
2002-07-08 0:33 ` John Max Skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020706182252.GA23247@force.stwing.upenn.edu \
--to=wlovas@stwing.upenn.edu \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox