1
votes

If I type the following into an fsx in Visual Studio Code

let longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

and run F# interactive on it by highlighting and pressing Alt+Enter, the output in the interactive window is

- let longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepte- ur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";;
val longString : string =
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "+[384 chars]

or as screenshot:

screenshot output

How can I tell the F# interactive window to display the full string? Is there a shortcut or else?

I am aware of this post, but as fas as I know this is different here because a string is not lazily-evaluated.

2

2 Answers

3
votes

printfn will print it completely:

printfn "%s" longString

Alternatively, you can change the fsi object properties, for instance:

fsi.PrintWidth <- 1000;;

Also, you can use AddPrinter:

fsi.AddPrinter (fun (s:string) -> s)

Here is the documentation: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/fsharp-interactive-options#f-interactive-structured-printing

2
votes

If it is just for testing/debugging: If you are in VSC you can run your script interactively as you mentioned. You can take advantage of that by using the interactive terminal and typing (in said interactive terminal)

longString;;

//output
val it : string =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

This will then show the whole string and is in most cases sufficient (since you do not want to clutter your script with unnecessary outputs anyway).