F#'s list is eager or lazy evaluated? Or only "seq" is lazy evaluated in F#
Asked Answered
N

1

5

Which elements in F# are lazy evaluated, which elements are eager evaluated? So far as I know, if "seq" is lazy evaluated, does it mean "list" is eager evaluated? How I prove it? Thanks

Negress answered 25/2, 2016 at 9:19 Comment(2)
Lists are eagerly evaluated. The answers you got to your question from February 3 demonstrate that.Coliseum
For proof you can look at the type definitions of said types. F# list is defined row 1789: github.com/Microsoft/visualfsharp/blob/master/src/fsharp/…Disorient
D
7

Yes, list is eager. You can try and watch it in Task Manager for example:

#time
let l = List.init 100000000 (fun x -> 0.)
let s = Seq.init 100000000 (fun x -> 0.)
let s2l = s |> Seq.take 10000000 |> Seq.toList
Dowitcher answered 25/2, 2016 at 9:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.