I wonder why F-Sharp does not support infinity.
This will work in Ruby (but not in f #):
let numbers n = [1 .. 1/0] |> Seq.take(n)
-> System.DivideByZeroException: Attempted division by zero.
I can write the same functionality in a very complicated way:
let numbers n = 1 |> Seq.unfold (fun i -> Some (i, i + 1)) |> Seq.take(n)
-> works
However, I think the first one would be much clearer. I cannot find an easy way to use dynamically typed infinity in F #. There is an infinity keyword, but it is equal to float:
let a = Math.bigint +infinity;;
System.OverflowException: BigInteger cannot represent infinity. in System.Numerics.BigInteger..ctor (double value) at. $ FSI_0045.main @ () stopped due to an error
Edit: this also works on iteration:
let numbers n = Seq.initInfinite (fun i -> i+1) |> Seq.take(n)