Skip to content

format6

Weng Shiwei edited this page Jan 8, 2021 · 27 revisions
Value or type Note 'a 'b 'c 'd 'e 'f rest type
Definitions
format6 'a 'b 'c 'd 'e 'f
format ('a, 'b, 'c, 'c) format4` 'a 'b 'c 'c 'c 'c
format4 ('a, 'b, 'c, 'c, 'c, 'd) format6 'a 'b 'c 'c 'c 'd
Scanf.scanner ('a, Scanf.Scanning.scanbuf, 'b, 'c, 'a -> 'd, 'd) format6 -> 'c 'a scanbuf 'b 'c 'a -> 'd 'd 'c
Manual final result type
Scanf type of values read by the fmt in_channel the type of the arg to the first arg of kprintf kscanf type of parameters for scanf type of receiver function for scanf result type of the receiver function
Printf type of parameters of the fmt out_channel type of the result of %a(%t) usually unit
Format Format.formatter
Paper 'functional_type = 'argument_sequence -> 'result_type 'low_level_device 'poly_printer_result 'poly_reader_functional_type = 'poly_reader_sequence -> 'poly_reader_result 'poly_reader_result 'result_type
Printf where 'argument_sequence is the type of sequence of arguments to print or value to read a polymorphic pretty-printer, which prints value of 't has type 'low_level_device -> 't -> 'poly_printer_result %a or %t n/a n/a the result type of printf-like functions
Scanf 'functional_type is also the type of receiver function a polymorphic reader, which reads value of 't has type 'low_level_device -> 't n/a 'poly_reader_sequence is the type of sequence of polymorphic readers required by all the %r the result type of 'poly_reader_functional_type the result type of the receiver function for scanf-like functions
Examples fmt omit CamlinternalFormatBasics for simplicity
("%d" : _ format6) Format (Int (Int_d, No_padding, No_precision, End_of_format), "%d") int -> 'a 'b 'c 'd 'd 'a
("%d %d" : _ format6) Format (Int (Int_d, No_padding, No_precision, Char_literal ( , Int (Int_d, No_padding, No_precision, End_of_format))), "%d %d") int -> int -> 'a 'b 'c 'd 'd 'a
("%a" : _ format6) Format (Alpha End_of_format, "%a") ('a -> 'b -> 'c) -> 'b -> 'd 'a 'c 'e 'e 'd
("%a %a" : _ format6) Format (Alpha (Char_literal ( , Alpha End_of_format)), "%a %a") ('a -> 'b -> 'c) -> 'b -> ('a -> 'd -> 'c) -> 'd -> 'e 'a 'c 'f 'f 'e
("%r" : _ format6) Format (Reader End_of_format, "%r") 'a -> 'b 'c 'd ('c -> 'a) -> 'e 'e 'b
("%r %r" : _ format6) Format (Reader (Char_literal ( , Reader End_of_format)), "%r %r") 'a -> 'b -> 'c 'd 'e ('d -> 'a) -> ('d -> 'b) -> 'f 'f 'c
Scanf.sscanf string -> ('a, 'b, 'c, 'd) Scanf.scanner
Scanf.scanner ('a, Scanf.Scanning.scanbuf, 'b, 'c, 'a -> 'd, 'd) format6 -> 'c 'a scanbuf 'b 'c 'a -> 'd 'd 'c
"%d %d" let fmt = format_of_string "%d %d" in let _ = Scanf.sscanf "1 2" fmt (fun x y -> x = y) in fmt int -> int -> bool scanbuf '_weak1 (int -> int -> bool) -> bool (int -> int -> bool) -> bool bool
"%r %r" let fmt = format_of_string "%r %r" in let _ = Scanf.sscanf "f1 b1" fmt scan_foo scan_bar (fun x y -> true) in fmt" in let _ = Scanf.sscanf "1 2" fmt (fun x y -> x = y) in fmt int -> int -> bool scanbuf '_weak1 (int -> int -> bool) -> bool (int -> int -> bool) -> bool bool
Printf.printf ('a, out_channel, unit) format 'a out_channel unit unit unit unit
"%d %d" let fmt = format_of_string "%d %d" in let _ = Format.printf fmt 1 2 in fmt int -> int -> unit unit string string string int
Printf.ksprintf (string -> 'd) -> ('a, unit, string, 'd) format4 -> 'a 'a unit string string string 'd
"%d %d" let fmt = format_of_string "%d %d" in let _ = Printf.ksprintf String.length fmt 1 2 in fmt int -> int -> int unit string string string int
"%a %a" let fmt = format_of_string "%a %a" in let _ = Printf.printf fmt out_foo F1 out_bar B1 in fmt (out_channel -> foo -> unit) -> foo -> (out_channel -> bar -> unit) -> bar -> unit out_channel unit unit unit unit
"%a %a" let fmt = format_of_string "%a %a" in let _ = Format.printf fmt pp_foo F1 pp_bar B1 in fmt (Format.formatter -> foo -> unit) -> foo -> (Format.formatter -> bar -> unit) -> bar -> unit Format.formatter unit unit unit unit

Clone this wiki locally