Sequences in F # are not evaluated immediately, but rather evaluated as they are listed.
This means that your readlines function does nothing efficiently until you try to use it. By doing something with inSeq , you will force an assessment, which in turn will make it behave just as you expect.
To see this in action, do something that will enumerate the sequence, for example, counting the number of elements:
open System open System.Collections.Generic open System.Text open System.IO #nowarn "40" let rec readlines () = seq { let line = Console.ReadLine() if not (line.Equals("")) then yield line yield! readlines () } [<EntryPoint>] let main argv = let inSeq = readlines () inSeq |> Seq.length |> printfn "%d lines read" // This will keep it alive enough to read your output Console.ReadKey() |> ignore 0
source share