f# - 为什么在 F# Interactive 中打印 5000 个数字会导致 StackOverflowException?

标签 f# f#-interactive

在 Windows 7 上的 F# 3.1 上测试

fsi.PrintLength <- 5000;;

[1..5000];;

Process is terminated due to StackOverflowException. Session termination detected. Press Enter to restart.


在 Mono (F# 4.0) 上,似乎没有这样的限制。

最佳答案

我认为这是 formatting module 中的一个错误它负责将 pretty-print 到 F# Interactive。

有一些非尾递归函数使用 PrintLength例如boundedUnfoldL在此 line . boundedUnfoldL 的实现确实不是尾递归的:

let boundedUnfoldL
                (itemL     : 'a -> layout)
                (project   : 'z -> ('a * 'z) option)
                (stopShort : 'z -> bool)
                (z : 'z)
                maxLength =
      let rec consume n z =
        if stopShort z then [wordL "..."] else
        match project z with
          | None       -> []  // exhaused input 
          | Some (x,z) -> if n<=0 then [wordL "..."]               // hit print_length limit 
                                  else itemL x :: consume (n-1) z  // cons recursive... 
      consume maxLength z  

我不知道为什么它不会在 Mono 上爆炸。如果 F# Interactive on Mono 可以成功处理长度 > 5000,那将是令人惊讶的。

您可以将此作为错误报告给 https://visualfsharp.codeplex.com/workitem/list/basic .

关于f# - 为什么在 F# Interactive 中打印 5000 个数字会导致 StackOverflowException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27432657/

相关文章:

f# - 如何将这种命令式风格的合并排序实现转换为函数式风格?

.net - F# 可以强制参数为 byte[8] 吗?

f# - 如何插入代码质量指标 - FAKE F#MAKE

f# - 控制台输入给出虚假值

f# - 如何使用 F# 在 Akka.Remote 中发送带有元组的消息?

emacs - 如何在 Emacs 中运行 F# interactive (*nix)

.net - 如何将函数调用嵌入到另一个函数中?

f# - 如何在F#中创建具有out参数的成员

visual-studio - F#Interactive #I命令如何知道项目路径?

f# - 如何在 VS 2015 中使用 FSharp.Data?