Version française
Home     About     Download     Resources     Contact us    
Browse thread
printf "%a" vs sprintf "%a"
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Tiphaine Turpin <Tiphaine.Turpin@i...>
Subject: printf "%a" vs sprintf "%a"
Hi,

I'am confused by the interpretation of "%a":

# Printf.printf "%a";;
- : (out_channel -> '_a -> unit) -> '_a -> unit = <fun>
# Printf.sprintf "%a";;
- : (unit -> '_a -> string) -> '_a -> string = <fun>

Usually, the typing of formatting functions is such that

printf something

has type unit if and only if

sprintf something

has type string. But %a breaks this rule. Wouldn't it be simpler to have
two separate directives which accept respectively string printers and
channel printers, regardless of the outer printing function ?

Tiphaine