Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Streams.from
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nick Grey <nickgrey0112@f...>
Subject: Re: [Caml-list] Streams.from
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