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

Jon*_*ing 7 f# f#-interactive

在Windows 7上测试F#3.1

fsi.PrintLength < - 5000 ;;

[1..5000] ;;

由于StackOverflowException,进程终止.检测到会话终止.按Enter重新启动.

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

pad*_*pad 8

我认为这是格式化模块中的一个错误,它负责F#Interactive的漂亮打印.

有一些非尾递归函数,PrintLength例如boundedUnfoldL在这一行中使用.实现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  
Run Code Online (Sandbox Code Playgroud)

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

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