Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to configure the number of list items shown when using %A formatting in F#?

Tags:

formatting

f#

printfn "%A" [1..1000]

inside f# interactive shows

[1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22;
23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42;
43; 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; 58; 59; 60; 61; 62;
63; 64; 65; 66; 67; 68; 69; 70; 71; 72; 73; 74; 75; 76; 77; 78; 79; 80; 81; 82;
83; 84; 85; 86; 87; 88; 89; 90; 91; 92; 93; 94; 95; 96; 97; 98; 99; 100; ...]

the following settings do not affect the number of list members shown

fsi.PrintSize <- 222        // no effect
fsi.PrintLength <- 222      // no effect
fsi.PrintDepth <- 222       // no effect
fsi.PrintWidth <- 222       // no effect
fsi.ShowIEnumerable <- true // no effect
  1. Is it possible to configure the number of members shown inside f# interactive?
  2. Is it possible t configure this such that (sprintf "%A") considers it outside of f# interactive?

i am asking this because i pretty print records, and currently some of the values are truncated. so the issue on top is to pretty print records without truncated values - just for context.

%A formatting has nice advantages as it nicely layouts records, which i do not want to loose by using StructuredFormatDisplayAttribute.

this formatting is part of formatting a large object with %A, which works perfectly, nicely without any effort. so i am not asking about really printing an isolated list.


inside the f# source:

checked the source code at https://github.com/dotnet/fsharp/blob/b23b2a0f99f12ece94c5ad89aabb9169d51091f3/src/fsharp/utils/sformat.fs

ObjectGraphFormatter apparently does the formatting, accepting format options.

the very last lines might be calling it:

let internal anyToStringForPrintf options (bindingFlags:BindingFlags) (value, typValue) = 
    let formatter = ObjectGraphFormatter(options, bindingFlags) 
    formatter.Format (ShowAll, value, typValue) |> layout_to_string options

which is called by the core Printf module which in turn is internal.

like image 619
citykid Avatar asked Nov 02 '25 02:11

citykid


1 Answers

I think I would just do this:

[1..1000] 
|> List.take 50
|> List.iter (printf "%A;")
like image 86
Scott Hutchinson Avatar answered Nov 04 '25 18:11

Scott Hutchinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!