From: Nick Grey <nickgrey0112@farrand.net>
To: caml-list@inria.fr
Cc: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
Subject: Re: [Caml-list] Streams.from
Date: Tue, 10 Dec 2002 00:00:48 +0000 [thread overview]
Message-ID: <20021210000048.GA27713@farrand.net> (raw)
In-Reply-To: <15861.5601.937494.839811@lri.lri.fr>
On Mon, Dec 09, 2002 at 11:14:57PM +0100, Jean-Christophe Filliatre wrote:
> No. For instance, repeated calls to Stream.peek will clearly call f
> several times on the same count value (see the code in stdlib/stream.ml)
It seems to me that the values are cached, and that
repeated calls to peek do not cause f to be called again.
Output below demonstrates what I mean. Note that f is called on the
first peek but not the second. Similarly with npeek. Also, the
parameters to f are 0, 1, 2, 3 ..., with no repeats.
Objective Caml version 3.06
# open Stream ;;
# let f i =
begin
print_string "f " ;
print_int i ;
print_string "\n" ;
Some (i*i)
end ;;
val f : int -> int option = <fun>
# f 1 ;;
f 1
- : int option = Some 1
# f 2 ;;
f 2
- : int option = Some 4
# let s = from f ;;
val s : int Stream.t = <abstr>
# next s ;;
f 0
- : int = 0
# next s ;;
f 1
- : int = 1
# peek s ;;
f 2
- : int option = Some 4
# peek s ;;
- : int option = Some 4
# peek s ;;
- : int option = Some 4
# npeek 5 s ;;
f 3
f 4
f 5
f 6
- : int list = [4; 9; 16; 25; 36]
# npeek 5 s ;;
- : int list = [4; 9; 16; 25; 36]
-------------------
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-12-10 7:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-09 19:04 Nick Grey
2002-12-09 22:14 ` Jean-Christophe Filliatre
2002-12-09 23:54 ` Remi VANICAT
2002-12-10 0:00 ` Nick Grey [this message]
2002-12-10 12:29 ` Daniel de Rauglaudre
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=20021210000048.GA27713@farrand.net \
--to=nickgrey0112@farrand.net \
--cc=Jean-Christophe.Filliatre@lri.fr \
--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