Why does printing 5,000 numbers in F # Interactive raise a StackOverflowException?

Tested on F # 3.1 on windows 7

fsi.PrintLength <- 5000 ;;

[1..5000] ;;

The process terminates due to a StackOverflowException. Session termination detected. Press "Enter" to reboot.

in Mono (F # 4.0), there seems to be no such limitation.

+7
f # f # -interactive
source share
1 answer

I think this is a bug in a module that takes care of pretty printing for F # Interactive.

There are several irregular recursive functions that use PrintLength , for example. boundedUnfoldL on this line. The implementation of boundedUnfoldL really not recursive:

 let boundedUnfoldL (itemL : 'a -> layout) (project : 'z -> ('a * 'z) option) (stopShort : 'z -> bool) (z : 'z) maxLength = let rec consume nz = 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 

I do not know why he will not explode on Mono. It would be surprising if F # Interactive on Mono can handle lengths> 5000 successfully.

You can report this as an error at https://visualfsharp.codeplex.com/workitem/list/basic .

+8
source share

All Articles