File: examples.mlt

package info (click to toggle)
ppx-yojson-conv 0.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 360 kB
  • sloc: ml: 3,498; makefile: 14
file content (46 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Position_for_polymorphic_variant_errors = struct
  type t1 = [ `A ] [@@deriving of_yojson]
  type t2 = [ `B ] [@@deriving of_yojson]
  type t3 = A of [ t1 | t2 ] [@@deriving of_yojson]

  let (_ : t3) = t3_of_yojson (`List [ `String "A"; `String "C" ])
end

[%%expect
  {|
Exception:
(Of_yojson_error
  "examples.mlt.Position_for_polymorphic_variant_errors.t1_of_yojson: unexpected variant constructor"
  "\"C\"")
|}]

let _ = [%yojson_of: 'a]

[%%expect
  {|
Line _, characters _-_:
Error: Type variables not allowed in [%yojson_of: ]. Please use locally abstract types instead.
|}]

let _ = [%of_yojson: 'a]

[%%expect
  {|
Line _, characters _-_:
Error: Type variables not allowed in [%of_yojson: ]. Please use locally abstract types instead.
|}]

let (_ : _) = [%yojson (() : 'a)]

[%%expect
  {|
Line _, characters _-_:
Error: Extension `yojson' was not translated
|}]

type 'a t =
  | None
  | Something_else of { value : 'a }
[@@deriving yojson]

[%%expect {| |}]