Oldrich Svec
Oldrich Svec

Reputation: 4231

printfn "%A" "c" using F#

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

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

Why the difference? The same goes for char.

Upvotes: 5

Views: 2934

Answers (2)

pad
pad

Reputation: 41290

Because printfn "%A" uses reflection, it displays results the same as values automatically printed out by F# Interactive. On the other hand, %s is for strings only, and it shows contents of strings.

The generic case of "%s" is "%O" when ToString methods are used. The %A specifier is slow, but helpful for structural types and types without overridden ToString methods.

Upvotes: 4

John Palmer
John Palmer

Reputation: 25516

The %A specifier tries to hint at object types - the "c" is it trying to show it is a string. When you do %s the compiler knows you want to print a string so it doesn't print the quotes

Upvotes: 8

Related Questions