package prelude

  1. Overview
  2. Docs

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
(* 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

module Empty = struct 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
  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 = ( == )

let not_phys_equal = ( != )

(* Make some functions safe. *)
let char_of_int n = try Some (char_of_int n) with Invalid_argument _ -> None

let bool_of_string = bool_of_string_opt

let int_of_string = int_of_string_opt

let float_of_string = float_of_string_opt

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

let this_function_has_been_hidden
  (_ : this_function_has_been_hidden_by_the_prelude_because_it_is_unwanted) :
  this_function_has_been_hidden_by_the_prelude_because_it_is_unwanted =
  assert false

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

let failwith = this_function_has_been_hidden

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

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

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

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

(* Use the redefined version without _opt suffix instead. *)
let bool_of_string_opt = this_function_has_been_hidden

let int_of_string_opt = this_function_has_been_hidden

let float_of_string_opt = this_function_has_been_hidden

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

let print_string = this_function_has_been_hidden

let print_bytes = this_function_has_been_hidden

let print_int = this_function_has_been_hidden

let print_float = this_function_has_been_hidden

let print_endline = this_function_has_been_hidden

let print_newline = this_function_has_been_hidden

let prerr_char = this_function_has_been_hidden

let prerr_string = this_function_has_been_hidden

let prerr_bytes = this_function_has_been_hidden

let prerr_int = this_function_has_been_hidden

let prerr_float = this_function_has_been_hidden

let prerr_endline = this_function_has_been_hidden

let prerr_newline = this_function_has_been_hidden

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

let read_int = this_function_has_been_hidden

let read_int_opt = this_function_has_been_hidden

let read_float = this_function_has_been_hidden

let read_float_opt = this_function_has_been_hidden

let open_out = this_function_has_been_hidden

let open_out_bin = this_function_has_been_hidden

let open_out_gen = this_function_has_been_hidden

let flush = this_function_has_been_hidden

let flush_all = this_function_has_been_hidden

let output_char = this_function_has_been_hidden

let output_string = this_function_has_been_hidden

let output_bytes = this_function_has_been_hidden

let output = this_function_has_been_hidden

let output_substring = this_function_has_been_hidden

let output_byte = this_function_has_been_hidden

let output_binary_int = this_function_has_been_hidden

let output_value = this_function_has_been_hidden

let seek_out = this_function_has_been_hidden

let pos_out = this_function_has_been_hidden

let out_channel_length = this_function_has_been_hidden

let close_out = this_function_has_been_hidden

let close_out_noerr = this_function_has_been_hidden

let set_binary_mode_out = this_function_has_been_hidden

let open_in = this_function_has_been_hidden

let open_in_bin = this_function_has_been_hidden

let open_in_gen = this_function_has_been_hidden

let input_char = this_function_has_been_hidden

let input_line = this_function_has_been_hidden

let input = this_function_has_been_hidden

let really_input = this_function_has_been_hidden

let really_input_string = this_function_has_been_hidden

let input_byte = this_function_has_been_hidden

let input_binary_int = this_function_has_been_hidden

let input_value = this_function_has_been_hidden

let seek_in = this_function_has_been_hidden
OCaml

Innovation. Community. Security.