Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* compile with ppx_implicits 0.2.0 *)
- (* ocamlfind ocamlc -c -package ppx_implicits implicit_read.ml *)
- module Read = struct
- type 'v t = (string -> 'v option, [%imp Instances]) Ppx_implicits.t
- let read ?(d:'v t option) x = Ppx_implicits.imp ?d x
- end
- module Instances = struct
- let _int : string -> int option = fun s ->
- try
- Some (int_of_string s)
- with
- _ -> None
- let _a : string -> [`A] option = function
- | "[`A]" -> Some(`A)
- | _ -> None
- end
- let _ =
- ignore @@ (Read.read "1" : int option); (* ok *)
- ignore @@ (Read.read "[`A]" : [`A] option) (* error *)
- (* File "_none_", line 1: *)
- (* Error: File "implicit_read.ml", line 22, characters 13-22: *)
- (* The experssion has type string -> [ `A ] option which is too ambiguous to resolve this implicit. *)
- (* The following instances may cause infinite loop of the resolution: *)
- (* Instances._a *)
- (* File "implicit_read.ml", line 1: *)
- (* Error: Error while running external preprocessor *)
- (* 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