Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. (* compile with ppx_implicits 0.2.0 *)
  2. (* ocamlfind ocamlc -c -package ppx_implicits implicit_read.ml *)
  3. module Read = struct
  4. type 'v t = (string -> 'v option, [%imp Instances]) Ppx_implicits.t
  5.  
  6. let read ?(d:'v t option) x = Ppx_implicits.imp ?d x
  7. end
  8.  
  9. module Instances = struct
  10. let _int : string -> int option = fun s ->
  11. try
  12. Some (int_of_string s)
  13. with
  14. _ -> None
  15. let _a : string -> [`A] option = function
  16. | "[`A]" -> Some(`A)
  17. | _ -> None
  18. end
  19.  
  20. let _ =
  21. ignore @@ (Read.read "1" : int option); (* ok *)
  22. ignore @@ (Read.read "[`A]" : [`A] option) (* error *)
  23.  
  24. (* File "_none_", line 1: *)
  25. (* Error: File "implicit_read.ml", line 22, characters 13-22: *)
  26. (* The experssion has type string -> [ `A ] option which is too ambiguous to resolve this implicit. *)
  27. (* The following instances may cause infinite loop of the resolution: *)
  28. (* Instances._a *)
  29.  
  30. (* File "implicit_read.ml", line 1: *)
  31. (* Error: Error while running external preprocessor *)
  32. (* Command line: /Users/keigoi/.opam/4.04.2/lib/ppx_implicits/./ppx_implicits '/var/folders/kl/bbg2vr1173j8xrmpc3xp9b3h0000gn/T/camlppx6ed0ad' '/var/folders/kl/bbg2vr1173j8xrmpc3xp9b3h0000gn/T/camlppx1a7f20' *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement