File: core.html

package info (click to toggle)
ocaml-doc 4.11-2
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 20,580 kB
  • sloc: sh: 37; makefile: 11
file content (212 lines) | stat: -rw-r--r-- 11,102 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
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
<!DOCTYPE html>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="hevea 2.32">

  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="manual.css">
<title>Chapter 25  The core library</title>
</head>
<body>
<a href="instrumented-runtime.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="stdlib.html"><img src="next_motif.svg" alt="Next"></a>
<hr>
<h1 class="chapter" id="sec572">Chapter 25  The core library</h1>
<ul>
<li><a href="core.html#s%3Acore-conventions">Conventions</a>
</li><li><a href="core.html#s%3Acore-builtins">25.1  Built-in types and predefined exceptions</a>
</li><li><a href="core.html#s%3Astdlib-module">25.2  Module <span class="c003">Stdlib</span>: the initially opened module</a>
</li></ul>
<p> <a id="c:corelib"></a></p><p>This chapter describes the OCaml core library, which is
composed of declarations for built-in types and exceptions, plus
the module <span class="c003">Stdlib</span> that provides basic operations on these
built-in types. The <span class="c003">Stdlib</span> module is special in two
ways:
</p><ul class="itemize"><li class="li-itemize">
It is automatically linked with the user’s object code files by
the <span class="c003">ocamlc</span> command (chapter <a href="comp.html#c%3Acamlc">9</a>).</li><li class="li-itemize">It is automatically “opened” when a compilation starts, or
when the toplevel system is launched. Hence, it is possible to use
unqualified identifiers to refer to the functions provided by the
<span class="c003">Stdlib</span> module, without adding a <span class="c003">open Stdlib</span> directive.
</li></ul><h2 class="section" id="s:core-conventions"><a class="section-anchor" href="#s:core-conventions" aria-hidden="true"></a>Conventions</h2>
<p>The declarations of the built-in types and the components of module
<span class="c003">Stdlib</span> are printed one by one in typewriter font, followed by a
short comment. All library modules and the components they provide are
indexed at the end of this report.</p>
<h2 class="section" id="s:core-builtins"><a class="section-anchor" href="#s:core-builtins" aria-hidden="true"></a>25.1  Built-in types and predefined exceptions</h2>
<p>The following built-in types and predefined exceptions are always
defined in the
compilation environment, but are not part of any module. As a
consequence, they can only be referred by their short names.</p><h3 class="subsection" id="ss:builtin-types"><a class="section-anchor" href="#ss:builtin-types" aria-hidden="true"></a>Built-in types</h3>
<pre> type int
</pre><p><a id="hevea_manual6"></a>
</p><blockquote class="quote">
The type of integer numbers.
</blockquote><pre> type char
</pre><p><a id="hevea_manual7"></a>
</p><blockquote class="quote">
The type of characters.
</blockquote><pre> type bytes
</pre><p><a id="hevea_manual8"></a>
</p><blockquote class="quote">
The type of (writable) byte sequences.
</blockquote><pre> type string
</pre><p><a id="hevea_manual9"></a>
</p><blockquote class="quote">
The type of (read-only) character strings.
</blockquote><pre> type float
</pre><p><a id="hevea_manual10"></a>
</p><blockquote class="quote">
The type of floating-point numbers.
</blockquote><pre> type bool = false | true
</pre><p><a id="hevea_manual11"></a>
</p><blockquote class="quote">
The type of booleans (truth values).
</blockquote><pre> type unit = ()
</pre><p><a id="hevea_manual12"></a>
</p><blockquote class="quote">
The type of the unit value.
</blockquote><pre> type exn
</pre><p><a id="hevea_manual13"></a>
</p><blockquote class="quote">
The type of exception values.
</blockquote><pre> type 'a array
</pre><p><a id="hevea_manual14"></a>
</p><blockquote class="quote">
The type of arrays whose elements have type <span class="c003">'a</span>.
</blockquote><pre> type 'a list = [] | :: of 'a * 'a list
</pre><p><a id="hevea_manual15"></a>
</p><blockquote class="quote">
The type of lists whose elements have type <span class="c003">'a</span>.
</blockquote><pre>type 'a option = None | Some of 'a
</pre><p><a id="hevea_manual16"></a>
</p><blockquote class="quote">
The type of optional values of type <span class="c003">'a</span>.
</blockquote><pre>type int32
</pre><p><a id="hevea_manual17"></a>
</p><blockquote class="quote">
The type of signed 32-bit integers.
Literals for 32-bit integers are suffixed by l.
See the <a href="libref/Int32.html"><span class="c003">Int32</span></a> module.
</blockquote><pre>type int64
</pre><p><a id="hevea_manual18"></a>
</p><blockquote class="quote">
The type of signed 64-bit integers.
Literals for 64-bit integers are suffixed by L.
See the <a href="libref/Int64.html"><span class="c003">Int64</span></a> module.
</blockquote><pre>type nativeint
</pre><p><a id="hevea_manual19"></a>
</p><blockquote class="quote">
The type of signed, platform-native integers (32 bits on 32-bit
processors, 64 bits on 64-bit processors).
Literals for native integers are suffixed by n.
See the <a href="libref/Nativeint.html"><span class="c003">Nativeint</span></a> module.
</blockquote><pre>type ('a, 'b, 'c, 'd, 'e, 'f) format6
</pre><p><a id="hevea_manual20"></a>
</p><blockquote class="quote">
The type of format strings. <span class="c003">'a</span> is the type of the parameters of
the format, <span class="c003">'f</span> is the result type for the <span class="c003">printf</span>-style
functions, <span class="c003">'b</span> is the type of the first argument given to <span class="c003">%a</span> and
<span class="c003">%t</span> printing functions (see module <a href="libref/Printf.html"><span class="c003">Printf</span></a>),
<span class="c003">'c</span> is the result type of these functions, and also the type of the
argument transmitted to the first argument of <span class="c003">kprintf</span>-style
functions, <span class="c003">'d</span> is the result type for the <span class="c003">scanf</span>-style functions
(see module <a href="libref/Scanf.html"><span class="c003">Scanf</span></a>), and <span class="c003">'e</span> is the type of the receiver function
for the <span class="c003">scanf</span>-style functions.
</blockquote><pre>type 'a lazy_t
</pre><p><a id="hevea_manual21"></a>
</p><blockquote class="quote">
This type is used to implement the <a href="libref/Lazy.html"><span class="c003">Lazy</span></a> module.
It should not be used directly.
</blockquote><h3 class="subsection" id="ss:predef-exn"><a class="section-anchor" href="#ss:predef-exn" aria-hidden="true"></a>Predefined exceptions</h3>
<pre>exception Match_failure of (string * int * int)
</pre><p><a id="hevea_manual22"></a>
</p><blockquote class="quote">
Exception raised when none of the cases of a pattern-matching
apply. The arguments are the location of the <span class="c003">match</span> keyword
in the source code (file name, line number, column number).
</blockquote><pre>exception Assert_failure of (string * int * int)
</pre><p><a id="hevea_manual23"></a>
</p><blockquote class="quote">
Exception raised when an assertion fails. The arguments are
the location of the <span class="c003">assert</span> keyword in the source code
(file name, line number, column number).
</blockquote><pre>exception Invalid_argument of string
</pre><p><a id="hevea_manual24"></a>
</p><blockquote class="quote">
Exception raised by library functions to signal that the given
arguments do not make sense. The string gives some information
to the programmer. As a general rule, this exception should not
be caught, it denotes a programming error and the code should be
modified not to trigger it.
</blockquote><pre>exception Failure of string
</pre><p><a id="hevea_manual25"></a>
</p><blockquote class="quote">
Exception raised by library functions to signal that they are
undefined on the given arguments. The string is meant to give some
information to the programmer; you must <em>not</em> pattern match on
the string literal because it may change in future versions (use
<code>Failure _</code> instead).
</blockquote><pre>exception Not_found
</pre><p><a id="hevea_manual26"></a>
</p><blockquote class="quote">
Exception raised by search functions when the desired object
could not be found.
</blockquote><pre>exception Out_of_memory
</pre><p><a id="hevea_manual27"></a>
</p><blockquote class="quote">
Exception raised by the garbage collector when there is
insufficient memory to complete the computation. (Not reliable for
allocations on the minor heap.)
</blockquote><pre>exception Stack_overflow
</pre><p><a id="hevea_manual28"></a>
</p><blockquote class="quote">
Exception raised by the bytecode interpreter when the evaluation
stack reaches its maximal size. This often indicates infinite or
excessively deep recursion in the user’s program. Before 4.10, it
was not fully implemented by the native-code compiler.
</blockquote><pre>exception Sys_error of string
</pre><p><a id="hevea_manual29"></a>
</p><blockquote class="quote">
Exception raised by the input/output functions to report an
operating system error. The string is meant to give some
information to the programmer; you must <em>not</em> pattern match on
the string literal because it may change in future versions (use
<code>Sys_error _</code> instead).
</blockquote><pre>exception End_of_file
</pre><p><a id="hevea_manual30"></a>
</p><blockquote class="quote">
Exception raised by input functions to signal that the
end of file has been reached.
</blockquote><pre>exception Division_by_zero
</pre><p><a id="hevea_manual31"></a>
</p><blockquote class="quote">
Exception raised by integer division and remainder operations
when their second argument is zero.
</blockquote><pre>exception Sys_blocked_io
</pre><p><a id="hevea_manual32"></a>
</p><blockquote class="quote">
A special case of <span class="c003">Sys_error</span> raised when no I/O is possible
on a non-blocking I/O channel.
</blockquote><pre>exception Undefined_recursive_module of (string * int * int)
</pre><p><a id="hevea_manual33"></a>
</p><blockquote class="quote">
Exception raised when an ill-founded recursive module definition
is evaluated. (See section <a href="manual024.html#s%3Arecursive-modules">8.2</a>.)
The arguments are the location of the definition in the source code
(file name, line number, column number).
</blockquote>
<h2 class="section" id="s:stdlib-module"><a class="section-anchor" href="#s:stdlib-module" aria-hidden="true"></a>25.2  Module <span class="c003">Stdlib</span>: the initially opened module</h2>
<ul class="ftoc2"><li class="li-links">
<a href="libref/Stdlib.html">Module <span class="c003">Stdlib</span>: the initially opened module</a>
</li><li class="li-links">Module <span class="c003">Pervasives</span>: deprecated alias for Stdlib
</li></ul>
<hr>
<a href="instrumented-runtime.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="stdlib.html"><img src="next_motif.svg" alt="Next"></a>
</body>
</html>