2014-12-11 8 views
7

provata su F # 3.1 su Windows 7Perché la stampa di 5000 numeri in F # Interactive causa una StackOverflowException?

fsi.PrintLength <-5000 ;;

[1.,5000] ;;

Il processo è terminato a causa di StackOverflowException. Rilevata la fine della sessione. Premi Invio per riavviare.

su Mono (F # 4.0), non sembra esserci una tale limitazione.

+0

Suoni come l'F # Interactive trarrebbero vantaggio da https://fslang.uservoice.com/forums/245727-f-language/suggestions/5663074-enable-a-compiler-warning-when-a-recursive-algorit – Asik

risposta

8

Penso che questo sia un bug nel formatting module che si occupa di una bella stampa su F # Interactive.

Esistono alcune funzioni ricorsive non tail che utilizzano PrintLength ad es. boundedUnfoldL in questo line. L'attuazione del boundedUnfoldL effetti non è ricorsiva in coda:

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 

Non so perché non saltare in aria su Mono. Sarebbe sorprendente se F # Interactive su Mono possa gestire con successo la lunghezza> 5000.

È possibile segnalare questo come un errore a https://visualfsharp.codeplex.com/workitem/list/basic.

+0

Forse l'hanno risolto in F # 4.0? –