我想編寫一個函數,它接受一對字符串並將第二個元素轉換爲格式。我以爲我可以使用format_of_string
函數,但似乎是行不通的。這是一個簡化版本:OCaml函數format_of_string未按預期工作
let pp fmt (e:string * string) =
let msg = format_of_string (snd e) in Format.fprintf fmt (" - "^^msg^^"@.");;
^^^^^^^
Error: This expression has type string but an expression was expected of type
('a, 'b, 'c, 'd, 'e, 'f) format6
有沒有辦法讓我的函數接受一對字符串?
您應該閱讀http://caml.inria.fr/mantis/view.php?id=5591 –
的錯誤報告的確如此!這提供了一個使用'Scanf.format_from_string'的解決方案。非常感謝 ! – Anne