[英]F# - Display full results in F# interactive window
Disclaimer: Total F# Newbie question!免责声明: Total F# 新手问题!
If I type the following into an F# file in Visual Studio如果我在 Visual Studio 的 F# 文件中键入以下内容
#light
let squares =
seq { for x in 1 .. 10 -> x * x }
printf "%A" squares
and run F# interactive on it by highlighting and pressing Alt + Enter , the output in the interactive window is并通过突出显示并按Alt + Enter在其上运行 F# 交互式,交互式窗口中的输出为
>
seq [1; 4; 9; 16; ...]
val squares : seq<int>
>
But I want to see the full sequence ie但我想看到完整的序列,即
>
seq [1; 4; 9; 16; 25; 36; 49; 64; 81; 100]
val squares : seq<int>
>
Is this possible?这可能吗? I'm hoping that there is a setting for this that I've missed.
我希望有一个我错过的设置。
'seq' is a lazily-evaluated construct; 'seq' 是一个惰性求值的结构; it could be infinite, which is why FSI only shows the first few values.
它可能是无限的,这就是 FSI 只显示前几个值的原因。 If you want to see it all, an easy thing to do is convert to a list, eg
如果您想查看所有内容,一个简单的方法是转换为列表,例如
printf "%A" (squares |> Seq.tolist)
If you want to display all the values in the sequence without transforming into a List, you can iterate directly on the sequence like so:如果要显示序列中的所有值而不转换为 List,可以直接在序列上迭代,如下所示:
Seq.iter (printfn "%A") squares
Note that you're taking a risk: if, as Brian hints, the sequence is infinite, you could be in for a rather long wait.请注意,您是在冒险:如果正如布赖恩所暗示的那样,序列是无限的,那么您可能需要等待很长时间。 (In this case,
Seq.skip
and Seq.take
are your friends) (在这种情况下,
Seq.skip
和Seq.take
是你的朋友)
另一种方法是将fsi.PrintLength
设置为一个合适的大数,例如
> fsi.PrintLength <- 500
If you get output like output"+[121 chars]
如果你得到类似
output"+[121 chars]
fsi.PrintWidth <- 500
Will make it output more to the console.将使其输出更多到控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.