Created
September 1, 2017 11:15
-
-
Save keigoi/031e4b2e98252e48de0c778be13e1d3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* compile with ppx_implicits ab783d180c35 (0.3.1) *) | |
(* ocamlfind ocamlc -c -package ppx_implicits implicit_polyvar.ml *) | |
module Read = struct | |
type 'a t = (string -> 'a, [%imp Readers]) Ppx_implicits.t | |
let unpack : 'a t -> string -> 'a = fun d -> Ppx_implicits.imp ~d | |
end | |
let read ?(_reader:'a Read.t option) = match _reader with Some x -> Read.unpack x | None -> failwith "no instance" | |
module M = struct | |
module Readers = struct | |
let _a : string -> [`A] = function "`A" -> `A | s -> failwith ("can't parse as `A:" ^s) | |
end | |
end | |
open M | |
let _ = | |
read "`A" |> function | |
| `A -> print_endline "A" | |
| `B -> print_endline "B" | |
(* File "implicit_polyvar.ml", line 23, characters 4-6: *) | |
(* Error: This pattern matches values of type [? `B ] *) | |
(* but a pattern was expected which matches values of type [ `A ] *) | |
(* The second variant type does not allow tag(s) `B *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment