以此阶乘序列为例:
factTake 5;;
val it : seq<System.Numerics.BigInteger> =
seq [1 {IsEven = false;
IsOne = true;
IsPowerOfTwo = true;
IsZero = false;
Sign = 1;}; 2 {IsEven = true;
IsOne = false;
IsPowerOfTwo = true;
IsZero = false;
Sign = 1;}; 6 {IsEven = true;
IsOne = false;
IsPowerOfTwo = false;
IsZero = false;
Sign = 1;}; 24 {IsEven = true;
IsOne = false;
IsPowerOfTwo = false;
IsZero = false;
Sign = 1;}; ...]
如何将结果中的数字收集到列表中,如下所示:
[1; 2; 6; 24]
更新
感谢@Nicole A和@ RCH的评论。问题变得简单:
factTake 8 |> Seq.toList |> printfn "%A"
[1; 2; 6; 24; 120; 720; 5040; 40320]
val it : unit = ()
来自 F#的printfn上有关趣味和利润的帖子也很有用: Formatted text using printf!
答案 0 :(得分:2)
正如我们共同发现的那样:
factTake 8 |> Seq.toList |> printfn "%A"