The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

sjoshi (6) [Avatar] Offline
I tried to take 20 elns from the infinite factorial e.g but get this error:

> factorial |> Seq.take 20 |>Seq.iter (fun i-> printfn "%s" i);;
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
System.InvalidOperationException: The input sequence has an insufficient number of elements.
at Microsoft.FSharp.Collections.SeqModule.Take@967.GenerateNext(IEnumerable`1& next)
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System-Collections-IEnumerator-MoveNext()
at Microsoft.FSharp.Collections.SeqModule.Iterate[T](FSharpFunc`2 action, IEnumerable`1 source)
at <StartupCode$FSI_0092>.$FSI_0092.main@()
Stopped due to error
Tomas Petricek (160) [Avatar] Offline
Re: Infinite factorial error
Hi, are you referring to the "factorials" value defined in listing 12.4? If yes, the problem is that the function doesn't actually define an infinite factorial - it only demonstrates how to define recursive sequence, but infinite sequences are discussed later (section 12.2.2). The "factorials" value only returns factorials smaller than 1000000, and there are less than 20 of them - you can remove the "if" condition from the listing 12.4 to get an infinite sequence.
sjoshi (6) [Avatar] Offline
Re: Infinite factorial error
Yes thanks. I did figure it out in the next section.