# error "`%s' is defined as function\n" "foo"
error: `foo' is defined as function
- : unit = ()
みたいなerror関数は次のように定義できる:
let error fmt = Printf.printf ("error: " ^^ fmt) ;;
結構悩んでしまったが、簡単なことだった。
補足
^^はPervasivesモジュールの関数でformat6を連結する働きをする。
# "%d" ^^ "%s" ;;
- : (int -> string -> '_a, '_b, '_c, 'd, '_d, '_a) format6 = <abstr>
format6というのが出てきたが、もともとformatはformat4のエイリアスで、さらにformat4はformat6のエイリアスになっている。
type ('a, 'b, 'c, 'd) format4 = ('a, 'b, 'c, 'c, 'c, 'd) format6
type ('a, 'b, 'c) format = ('a, 'b, 'c, 'c) format4
特に何も考えずformatを繋げてるという理解でいいんではないだろうか……
参考
OCaml 標準ライブラリ探訪 #3.0: Printf: 便利だけどいろいろ謎のある奴
Module Pervasives