File: first_class_module.ml

package info (click to toggle)
ocamlformat 0.29.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,820 kB
  • sloc: ml: 65,176; pascal: 4,877; lisp: 229; sh: 217; makefile: 121
file content (148 lines) | stat: -rw-r--r-- 2,872 bytes parent folder | download
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
module type S = sig end

type t = (module S)

module type S = sig
  val x : int
end

module M = struct
  let x = 0
end

let m = (module M : S)

let () =
  let (module M : S) = m in
  (* error here *)
  ()

module type S = sig
  val x : int
end

module M = struct
  let x = 0
end

let m = (module M : S)

let f ((module M : S) as u) = ignore u ; M.x

let f (T {m= (module M)}) = ignore u ; M.x

let f (T {m= (module M : S)}) = ignore u ; M.x

let v = f (module M : S with type t = t)

module type S = sig
  type a

  val va : a

  type b

  val vb : b
end

let f (module M : S with type a = int and type b = int) = M.va + M.vb

let f (module M : S with type a = int and type b = int)
    (module N : SSSS
      with type a = int
       and type b = int
       and type c = int
       and type d = int
       and type e = int )
    (module N : SSSS
      with type a = int
       and type b = int
       and type c = int
       and type d = int )
    (module O : S with type a = int and type b = int and type c = int) =
  M.va + N.vb

module type M = sig
  val storage : (module S with type t = t)
end

let _ =
  let module M = (val m : M) in
  ()

let _ =
  ( module Ephemeron (HHHHHHHHHHHHHHHHHHHHHHHHHH) (HHHHHHHHHHHHHHHHHHHHHHHHHH)
  : Ephemeron.S )

let _ =
  ( module Ephemeron (HHHHHHHHHHHHHHHHHHHHHHHHHH) (HHHHHHHHHHHHHHHHHH)
  : Ephemeron.S )

let _ = (module Ephemeron (HHHHHHHHHHHHHHH) (HHHHHHHHHHHHH) : Ephemeron.S)

let _ = (module Ephemeron (HHH) : Ephemeron.S)

let _ =
  ( module Ephemeron (struct
    type t = t
  end) : Ephemeron.S )

let _ =
  ( module struct
    let a = b
  end )

(* Tests for dropped comment *)

module M = (val x : S (* a *))

module M = (val x (* b *))

[@@@ocamlformat "break-struct=natural"]

let _ =
  ( module struct
    let x = 0

    let y = 1
  end )

(* Three form that had an equivalent AST at some point: *)
let x : (module S) = (module M)
let x = ((module M) : (module S))
let x = (module M : S)

(* Unpack containing a [pexp_constraint]. *)
module T = (val (x : (module S)))

let _ = (module Int : T [@foo])

let _ = fun ((module X) : (module M.S with type a = a)) -> X.v
let _ = fun (module X : M.S with type a = a) -> X.v

let _ =
  let module MS = struct module type S = sig end end in
  (fun _ -> ())
    (fun (module M1 : MS.S) ((module M2) : (module MS.S)) ->
       (module M1 : MS.S), ((module M2) : (module MS.S)))

let _ =
  let module MS = struct module type S  = sig  end end in
  (fun _ -> ())
    (fun (module M1 : MS.S) ((module M2)  : (module MS.S)) ->
       (((module M1) : (module MS.S)), ((module M2) : (module MS.S))))

let f :
    (* a *)
    (module (* a *) M (* a *) : (* a *) S) (* a *) ->
    (* a *)
    fooo =
  f

let f :
    (* a *)
    (module (* a *) Foooooooooooooooooooooooooooooooooooooo (* a *) : (* a *) Foooooooooooooooooooooooooooooooooooooo) (* a *) ->
    (* a *)
    fooo =
  f