Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* It seems that the ability of the Format and Printf modules to compose
- printing functions with "%a" format strings do not mix well with functions
- defined with optional arguments.
- In the following code, I think that "test2" should be accepted, but is not
- because of some bug int the format-string typing code. OCaml 3.12.0 fails
- with the message:
- File "...", line 23, characters 37-45:
- Error: This expression has type ?a:bool -> out_channel -> string -> unit
- but an expression was expected of type out_channel -> 'a -> unit
- *)
- module F = Printf (* (* same for *) Format *)
- let with_opt ?(a = true) fmt x = F.fprintf fmt "%b %s" a x
- (* Works *)
- let ok f fmt x = F.fprintf fmt "%a" f x
- let g = ok with_opt
- (* Fails *)
- let wrong fmt x = F.fprintf fmt "%a" with_opt x
Add Comment
Please, Sign In to add comment