summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-modules/applicative_functor_type.ml
blob: 172a0dd30a86843f2d83e5a45c8b95ed0e549513 (plain)
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
(* TEST
 expect;
*)

type t = Set.Make(String).t
[%%expect{|
type t = Set.Make(String).t
|} ]


(* Check the error messages of an ill-typed applicatived functor type. *)
module M = struct type t let equal = (=) end
[%%expect{|
module M : sig type t val equal : 'a -> 'a -> bool end
|} ]

type t = Set.Make(M).t
[%%expect{|
Line 1, characters 9-22:
1 | type t = Set.Make(M).t
             ^^^^^^^^^^^^^
Error: Modules do not match:
       sig type t = M.t val equal : 'a -> 'a -> bool end
     is not included in Set.OrderedType
     The value `compare' is required but not provided
     File "set.mli", line 55, characters 4-31: Expected declaration
|} ]


(* We would report the wrong error here if we didn't strengthen the
   type of the argument (type t wouldn't match). *)
module F(X : sig type t = M.t val equal : unit end)
  = struct type t end
[%%expect{|
module F :
  functor (X : sig type t = M.t val equal : unit end) -> sig type t end
|} ]

type t = F(M).t
[%%expect{|
Line 1, characters 9-15:
1 | type t = F(M).t
             ^^^^^^
Error: Modules do not match:
       sig type t = M.t val equal : 'a -> 'a -> bool end
     is not included in sig type t = M.t val equal : unit end
     Values do not match:
       val equal : 'a -> 'a -> bool
     is not included in
       val equal : unit
     The type 'a -> 'a -> bool is not compatible with the type unit
|} ]


(* MPR#7611 *)
module Generative() = struct type t end
[%%expect{|
module Generative : functor () -> sig type t end
|}]

type t = Generative(M).t
[%%expect{|
Line 1, characters 9-24:
1 | type t = Generative(M).t
             ^^^^^^^^^^^^^^^
Error: The functor Generative is generative, it cannot be applied in type
       expressions
|}]



module F(X : sig module type S module F : S end) = struct
  type t = X.F(Parsing).t
end
[%%expect{|
Line 2, characters 11-25:
2 |   type t = X.F(Parsing).t
               ^^^^^^^^^^^^^^
Error: The module X.F is abstract, it cannot be applied
|}]