Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyList.map2 is not as lazy as LazyList.map #805

Open
mars0i opened this issue Nov 12, 2017 · 0 comments
Open

LazyList.map2 is not as lazy as LazyList.map #805

mars0i opened this issue Nov 12, 2017 · 0 comments

Comments

@mars0i
Copy link
Contributor

mars0i commented Nov 12, 2017

When an element in the result of LazyList.map2 is accessed, this forces the next element to be constructed. LazyList.map doesn't have this behavior:

# let pr = Printf.printf "%d\n%!";;
val pr : int -> unit = <fun>
# let s1 = LL.seq 0 (fun n -> let n' = n + 1 in pr n'; n') (fun _ -> true);;
val s1 : int LL.t = <lazy>
# let s2 = LL.seq 0 (fun n -> let n' = n + 1 in pr n'; n') (fun _ -> true);;
val s2 : int LL.t = <lazy>
# let s3 = LL.seq 0 (fun n -> let n' = n + 1 in pr n'; n') (fun _ -> true);;
val s3 : int LL.t = <lazy>
# let s1' = LL.map (fun n -> n)  s1;;
val s1' : int LL.t = <lazy>
# let s2s3 = LL.map2 (fun x y -> x, y) s2 s3;;
val s2s3 : (int * int) LL.t = <lazy>
# LL.hd s1';;
- : int = 0
# LL.hd s2s3;;
1
1
- : int * int = (0, 0)
# LL.hd (LL.tl s1');;
1
- : int = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant