Source file prelude.ml

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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
(* SPDX-License-Identifier: AGPL-3.0-or-later *)
(* Copyright © 2024 The Prelude programmers *)

(* This module is automatically opened in all files in order to hide certain unwanted parts of the standard library. *)

include Stdlib

type ('a, 'b) result = ('a, 'b) Stdlib.result

module Empty = struct end

(* Hide unwanted functions. *)
type you_are_trying_to_use_a_function_that_has_been_hidden_by_prelude = |

type because_it_is_unwanted = |

type this_function_has_been_hidden_by_prelude_because_it_is_unwanted =
     you_are_trying_to_use_a_function_that_has_been_hidden_by_prelude
  -> because_it_is_unwanted

let hidden : this_function_has_been_hidden_by_prelude_because_it_is_unwanted =
 fun (_ : you_are_trying_to_use_a_function_that_has_been_hidden_by_prelude) ->
  (assert false : because_it_is_unwanted)

module Float = struct
  include Float

  let of_string = hidden

  module Infix = struct
    external ( < ) : float -> float -> bool = "%lessthan"

    external ( <= ) : float -> float -> bool = "%lessequal"

    external ( <> ) : float -> float -> bool = "%notequal"

    external ( = ) : float -> float -> bool = "%equal"

    external ( > ) : float -> float -> bool = "%greaterthan"

    external ( >= ) : float -> float -> bool = "%greaterequal"

    external compare : float -> float -> int = "%compare"

    external equal : float -> float -> bool = "%equal"
  end
end

module Int32 = struct
  include Int32

  module Infix = struct
    external ( < ) : int32 -> int32 -> bool = "%lessthan"

    external ( <= ) : int32 -> int32 -> bool = "%lessequal"

    external ( <> ) : int32 -> int32 -> bool = "%notequal"

    external ( = ) : int32 -> int32 -> bool = "%equal"

    external ( > ) : int32 -> int32 -> bool = "%greaterthan"

    external ( >= ) : int32 -> int32 -> bool = "%greaterequal"

    external compare : int32 -> int32 -> int = "%compare"

    external equal : int32 -> int32 -> bool = "%equal"
  end
end

module Int64 = struct
  include Int64

  module Infix = struct
    external ( < ) : int64 -> int64 -> bool = "%lessthan"

    external ( <= ) : int64 -> int64 -> bool = "%lessequal"

    external ( <> ) : int64 -> int64 -> bool = "%notequal"

    external ( = ) : int64 -> int64 -> bool = "%equal"

    external ( > ) : int64 -> int64 -> bool = "%greaterthan"

    external ( >= ) : int64 -> int64 -> bool = "%greaterequal"

    external compare : int64 -> int64 -> int = "%compare"

    external equal : int64 -> int64 -> bool = "%equal"
  end
end

module Hashtbl = struct
  include Hashtbl

  let find = hidden

  module type S = sig
    include Hashtbl.S

    val find : this_function_has_been_hidden_by_prelude_because_it_is_unwanted
  end

  module Make (H : HashedType) : S with type key = H.t = struct
    include Hashtbl.Make (H)

    let find = hidden
  end

  module type SeededS = sig
    include Hashtbl.SeededS

    val find : this_function_has_been_hidden_by_prelude_because_it_is_unwanted
  end

  module MakeSeeded (H : SeededHashedType) : SeededS with type key = H.t =
  struct
    include Hashtbl.MakeSeeded (H)

    let find = hidden
  end
end

module List = struct
  include List

  (* use a match to deconstruct the list *)
  let hd = hidden

  (* use a match to deconstruct the list *)
  let tl = hidden

  let nth = hidden

  let find = hidden

  let assoc = hidden

  let assq = hidden
end

module Map = struct
  module type OrderedType = Map.OrderedType

  module type S = sig
    include Map.S

    val min_binding :
      this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val max_binding :
      this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val choose : this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val find : this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val find_first :
      this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val find_last :
      this_function_has_been_hidden_by_prelude_because_it_is_unwanted
  end

  module Make (Ord : OrderedType) : S with type key = Ord.t = struct
    include Map.Make (Ord)

    let min_binding = hidden

    let max_binding = hidden

    let choose = hidden

    let find = hidden

    let find_first = hidden

    let find_last = hidden
  end
end

module Option = struct
  include Option

  let get = hidden
end

module Result = struct
  include Result

  let get_ok = hidden

  let get_error = hidden
end

module Queue = struct
  include Queue

  let take = hidden

  let pop = hidden

  let peek = hidden

  let top = hidden
end

module Stack = struct
  include Stack

  let pop = hidden

  let drop = hidden

  let top = hidden
end

module Set = struct
  module type OrderedType = Set.OrderedType

  module type S = sig
    include Set.S

    val min_elt :
      this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val max_elt :
      this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val choose : this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val find : this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val find_first :
      this_function_has_been_hidden_by_prelude_because_it_is_unwanted

    val find_last :
      this_function_has_been_hidden_by_prelude_because_it_is_unwanted
  end

  module Make (Ord : OrderedType) : S with type elt = Ord.t = struct
    include Set.Make (Ord)

    let min_elt = hidden

    let max_elt = hidden

    let choose = hidden

    let find = hidden

    let find_first = hidden

    let find_last = hidden
  end
end

(* Use Re instead. *)
module Str = Empty

module String = struct
  include String

  type nonrec t = t

  let index_from = hidden

  let rindex_from = hidden

  let index = hidden

  let rindex = hidden
end

(* Use the fmt library instead. *)
module Printf = Empty

module Fmt = struct
  type formatter = Format.formatter

  include Fmt
end

module Format = Empty

(* Use Cmdliner instead. *)
module Arg = Empty
module Cmdliner = Cmdliner

(* Use unlabeled version instead. *)
module ArrayLabels = Empty
module BytesLabels = Empty
module ListLabels = Empty
module MoreLabels = Empty
module StdLabels = Empty
module StringLabels = Empty

(* Use Fpath instead. *)
module Filename = Empty

(* Be safe instead. *)
(* TODO: enable it again, it is disabled otherwise the generated menhir file does not compile.
   module Obj = Empty
*)

(* Use Menhir instead. *)
module Parsing = Empty

(* Hidden to avoid exposing an escape hatch to get access to the previously hiddden modules. *)
module Stdlib = Empty

(* Use Bos instead. *)
module Sys = struct
  (* Signals *)
  type signal_behavior = Sys.signal_behavior =
    | Signal_default
    | Signal_ignore
    | Signal_handle of (int -> unit)

  let set_signal = Sys.set_signal

  let sigabrt = Sys.sigabrt

  let sigalrm = Sys.sigalrm

  let sigfpe = Sys.sigfpe

  let sighup = Sys.sighup

  let sigill = Sys.sigill

  let sigint = Sys.sigint

  let sigkill = Sys.sigkill

  let sigpipe = Sys.sigpipe

  let sigquit = Sys.sigquit

  let sigsegv = Sys.sigsegv

  let sigterm = Sys.sigterm

  let sigusr1 = Sys.sigusr1

  let sigusr2 = Sys.sigusr2

  let sigchld = Sys.sigchld

  let sigcont = Sys.sigcont

  let sigstop = Sys.sigstop

  let sigtstp = Sys.sigtstp

  let sigttin = Sys.sigttin

  let sigttou = Sys.sigttou

  let sigvtalrm = Sys.sigvtalrm

  let sigprof = Sys.sigprof

  let sigbus = Sys.sigbus

  let sigpoll = Sys.sigpoll

  let sigsys = Sys.sigsys

  let sigtrap = Sys.sigtrap

  let sigurg = Sys.sigurg

  let sigxcpu = Sys.sigxcpu

  let sigxfsz = Sys.sigxfsz

  (* Other stuff *)
  let opaque_identity = Sys.opaque_identity
end

(* Hide dangerous polymorphic operations. *)

let ( <> ) (a : int) (b : int) = a <> b

let ( = ) (a : int) (b : int) = Int.equal a b

let ( < ) (a : int) (b : int) = a < b

let ( > ) (a : int) (b : int) = a > b

let ( <= ) (a : int) (b : int) = a <= b

let ( >= ) (a : int) (b : int) = a >= b

let compare (a : int) (b : int) = Int.compare a b

let min (a : int) (b : int) = Int.min a b

let max (a : int) (b : int) = Int.max a b

(* Rename some functions. *)
let phys_equal = ( == )

(* Make some functions safe. *)
(* TODO: there's no `_opt` version in the Stdlib for now, there's a PR for it.
   We should enforce its use once it has been added, and remove the unsafe one.

let char_of_int = hidden
*)

let bool_of_string = hidden

let int_of_string = hidden

let float_of_string = hidden

(* Use a proper Result type. *)
let invalid_arg = hidden

let failwith = hidden

(* Use phys_equal instead. *)
let ( == ) = hidden

(* Use not_phys_equal instead. *)
let ( != ) = hidden

(* Use Fmt instead. *)
let ( ^ ) = hidden

(* Use a proper `let (_ : t) = e1` construct, don't forget to annotate the type to avoid getting partial application bugs. *)
let ignore = hidden

(* Use Fmt instead. *)
let print_char = hidden

let print_string = hidden

let print_bytes = hidden

let print_int = hidden

let print_float = hidden

let print_endline = hidden

let print_newline = hidden

let prerr_char = hidden

let prerr_string = hidden

let prerr_bytes = hidden

let prerr_int = hidden

let prerr_float = hidden

let prerr_endline = hidden

let prerr_newline = hidden

(* Use Bos instead. *)
let read_line = hidden

let read_int = hidden

let read_int_opt = hidden

let read_float = hidden

let read_float_opt = hidden

let open_out = hidden

let open_out_bin = hidden

let open_out_gen = hidden

let flush = hidden

let flush_all = hidden

let output_char = hidden

let output_string = hidden

let output_bytes = hidden

let output = hidden

let output_substring = hidden

let output_byte = hidden

let output_binary_int = hidden

let output_value = hidden

let seek_out = hidden

let pos_out = hidden

let out_channel_length = hidden

let close_out = hidden

let close_out_noerr = hidden

let set_binary_mode_out = hidden

let open_in = hidden

let open_in_bin = hidden

let open_in_gen = hidden

let input_char = hidden

let input_line = hidden

let input = hidden

let really_input = hidden

let really_input_string = hidden

let input_byte = hidden

let input_binary_int = hidden

let input_value = hidden

let seek_in = hidden