Consider that
Pentagonal numbers are generated by the formula, Pn=n(3nā1)/2.
I decided to create a sequence of pentagonal numbers in F #:
let pentagonalSeq = { 1..Int32.MaxValue } |> Seq.map (fun n -> n*(3*n-1)/2)
So far so good. For most purposes, I only want to compute a pair of small integer pentagonal numbers. But maybe I would like, for example, to get all the Int32pentagonal numbers. I thought it would be possible to simply calculate them until I get it OverflowException(I use verified arithmetic). The trouble is that F # is not very happy with his idea, shouting that
'try/with' cannot be used inside sequence expressions
What is the best way to keep this young lady satisfied?
Suppose I want to create int32_pentagonalSeqone that:
- uses
pentagonalSeq - It does not require any additional calculations, trying to predict whether or not the next element may overflow.