Guest User

Untitled

a guest
Feb 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. (* It seems that the ability of the Format and Printf modules to compose
  2. printing functions with "%a" format strings do not mix well with functions
  3. defined with optional arguments.
  4.  
  5. In the following code, I think that "test2" should be accepted, but is not
  6. because of some bug int the format-string typing code. OCaml 3.12.0 fails
  7. with the message:
  8.  
  9. File "...", line 23, characters 37-45:
  10. Error: This expression has type ?a:bool -> out_channel -> string -> unit
  11. but an expression was expected of type out_channel -> 'a -> unit
  12. *)
  13.  
  14. module F = Printf (* (* same for *) Format *)
  15.  
  16. let with_opt ?(a = true) fmt x = F.fprintf fmt "%b %s" a x
  17.  
  18. (* Works *)
  19. let ok f fmt x = F.fprintf fmt "%a" f x
  20. let g = ok with_opt
  21.  
  22. (* Fails *)
  23. let wrong fmt x = F.fprintf fmt "%a" with_opt x
Add Comment
Please, Sign In to add comment