Printfn "% A" "c" using F #

By running printfn "%A" "c" , I get "c" .

By running printfn "%s" "c" , I get c .

Why is the difference? The same goes for char .

+4
source share
2 answers

The %A specifier is trying to hint at the types of objects - "c" trying to show that it is a string. When you execute %s , the compiler knows that you want to print the string so that it does not print quotes

+6
source

Since printfn "%A" uses reflection, it displays the results in the same way as values โ€‹โ€‹automatically printed by F # Interactive. %s , on the other hand, is for strings only, and it displays the contents of strings.

The general case of "%s" is "%O" when using ToString methods. The %A specifier is slow, but useful for structure types and types without overridden ToString methods.

+4
source

Source: https://habr.com/ru/post/1401776/


All Articles