4

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

vik santata
  • 2,989
  • 8
  • 30
  • 52
  • 10
    Lists are eagerly evaluated. The answers you got to [your question from February 3](http://stackoverflow.com/q/35169269/126014) demonstrate that. – Mark Seemann Feb 25 '16 at 09:32
  • 1
    For proof you can look at the type definitions of said types. F# list is defined row 1789: https://github.com/Microsoft/visualfsharp/blob/master/src/fsharp/FSharp.Core/prim-types.fsi – Just another metaprogrammer Feb 25 '16 at 15:10

1 Answers1

6

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
s952163
  • 6,276
  • 4
  • 23
  • 47