File: typeable_tests.ml

package info (click to toggle)
ocaml-deriving-ocsigen 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 628 kB
  • ctags: 1,159
  • sloc: ml: 6,334; makefile: 63; sh: 18
file content (106 lines) | stat: -rw-r--r-- 2,230 bytes parent folder | download | duplicates (3)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
open Deriving_Typeable

type t1 = F deriving (Typeable)
type t2 = F deriving (Typeable)

let eq_types t1 t2 = TypeRep.eq (Lazy.force t1) (Lazy.force t2)

let _ =
  begin
    assert (eq_types
	      Typeable.type_rep<t1>
              Typeable.type_rep<t1>);
    assert (eq_types
              Typeable.type_rep<t2>
              Typeable.type_rep<t2>);
    assert (not (eq_types
                   Typeable.type_rep<t1>
                   Typeable.type_rep<t2>));
    assert (not (eq_types
                   Typeable.type_rep<t2>
                   Typeable.type_rep<t1>));
  end

type t3 = int deriving (Typeable)

let _ =
  begin
    assert (eq_types
              Typeable.type_rep<int>
              Typeable.type_rep<t3>);
  end


type t4 = [`T of int] deriving (Typeable)
type t5 = [`T of t3] deriving (Typeable)

let _ =
  begin
    assert (eq_types
              Typeable.type_rep<t4>
              Typeable.type_rep<t5>);
  end

type t6 = [`T of t5]
    deriving (Typeable)

let _ =
  begin
    assert (not (eq_types
                   Typeable.type_rep<t5>
                   Typeable.type_rep<t6>));

  end

type t7 = [`T of t6]
    deriving (Typeable)

let _ =
  begin
    assert (not (eq_types
                   Typeable.type_rep<t6>
                   Typeable.type_rep<t7>));
  end


type t8 = [`A | `B] deriving (Typeable)
type t9 = [`B | `A] deriving (Typeable)

let _ =
  begin
    assert (eq_types
              Typeable.type_rep<t8>
              Typeable.type_rep<t9>);
  end


type ('a,'r) openr = [`Nil | `Cons of 'a * 'r]
 deriving (Typeable)
type 'a closedr = [`Nil | `Cons of 'a * 'a closedr]
 deriving (Typeable)
type l1 = [ `A of (int, l1) openr ]
and l2 = [ `A of int closedr ] deriving (Typeable)

(* The following fail without recursive module : *)
(* type l3 = (int, l3) openr deriving (Typeable) *)

let _ =
  begin
    assert (eq_types
              Typeable.type_rep<l1>
              Typeable.type_rep<l1>);
  end

type nil = [`Nil] deriving (Typeable)
type t10 = [ `A of ([nil| `Cons of int * 'a ] as 'a)] list
    deriving (Typeable)
type t11 = l2 list deriving (Typeable)

let _ =
  begin
    assert
      (eq_types
         Typeable.type_rep<t10>
         Typeable.type_rep<t11>);
  end