KURO-BOX% ocaml
Objective Caml version 3.09.2
# #load "camlp4o.cma";;
Camlp4 Parsing version 3.09.2
# #load "pa_printf.cmo";;
# myprintf "hoge %% %d %s %c %f" 10 "fuga" 'C' 2.1;;
- : string = "hoge % 10 fuga C 2.1"
# myprintf "hoge %% %d %s %c %f" 3.14 "fuga" 'C' 2.1;;
This expression has type float but is here used with type int
ether
#4412()
[
OCaml
]
Rating6/6=1.00
OCaml で、サポートする書式指定は #4409 の jijixi さんのと大体同じですが、ちゃんと型チェックする版。
基本は参考ページの手法を使って、でもそれだけだと printf っぽく見えないので Camlp4 を被せました。
KURO-BOX% ocaml Objective Caml version 3.09.2 # #load "camlp4o.cma";; Camlp4 Parsing version 3.09.2 # #load "pa_printf.cmo";; # myprintf "hoge %% %d %s %c %f" 10 "fuga" 'C' 2.1;; - : string = "hoge % 10 fuga C 2.1" # myprintf "hoge %% %d %s %c %f" 3.14 "fuga" 'C' 2.1;; This expression has type float but is here used with type intsee: Olivier Danvy (1998) "Functional Unparsing"
Rating6/6=1.00-0+
[ reply ]