1
1
defmodule Kernel.Typespec do
2
2
@ moduledoc """
3
- Holds macros and functions for working with typespecs.
3
+ Provides macros and functions for working with typespecs.
4
4
5
5
The attributes `@type`, `@opaque`, `@typep`, `@spec` and
6
6
`@callback` available in modules are handled by the equivalent
7
7
macros defined by this module.
8
8
9
9
## Defining a type
10
10
11
- @type type_name :: type
12
- @typep type_name :: type
13
- @opaque type_name :: type
11
+ @type type_name :: type
12
+ @typep type_name :: type
13
+ @opaque type_name :: type
14
14
15
- For more details, see documentation for deftype, deftypep and defopaque in
16
- Kernel.Typespec
15
+ For more details, see documentation for ` deftype`, ` deftypep` and ` defopaque`
16
+ below.
17
17
18
18
## Defining a specification
19
19
20
- @spec function_name(type, type) :: type
21
- @callback function_name(type, type) :: type
20
+ @spec function_name(type, type) :: type
21
+ @callback function_name(type, type) :: type
22
22
23
- For more details, see documentation for defspec and defcallback in
24
- Kernel.Typespec
23
+ For more details, see documentation for `defspec` and `defcallback` below.
25
24
26
25
## Types
27
26
@@ -30,9 +29,10 @@ defmodule Kernel.Typespec do
30
29
31
30
Most of the built-in types provided in Erlang (for example, `pid()`)
32
31
are expressed the same way: `pid()` or simply `pid`. Parametrized types
33
- are also supported: `list(integer())` and so are remote types: `Enum.t`.
32
+ are also supported ( `list(integer())`) and so are remote types ( `Enum.t`) .
34
33
35
- Certain data type shortcuts ([...], <<>> and {...}) are supported as well.
34
+ Certain data type shortcuts (`[...]`, `<<>>` and `{...}`) are supported as
35
+ well.
36
36
37
37
Main differences lie in how bit strings and functions are defined:
38
38
@@ -81,7 +81,7 @@ defmodule Kernel.Typespec do
81
81
82
82
@ doc """
83
83
Defines a type.
84
- This macro is the one responsible to handle the attribute @type.
84
+ This macro is the one responsible for handling the attribute ` @type` .
85
85
86
86
## Examples
87
87
@@ -96,7 +96,7 @@ defmodule Kernel.Typespec do
96
96
97
97
@ doc """
98
98
Defines an opaque type.
99
- This macro is the one responsible to handle the attribute @opaque.
99
+ This macro is the one responsible for handling the attribute ` @opaque` .
100
100
101
101
## Examples
102
102
@@ -111,7 +111,7 @@ defmodule Kernel.Typespec do
111
111
112
112
@ doc """
113
113
Defines a private type.
114
- This macro is the one responsible to handle the attribute @typep.
114
+ This macro is the one responsible for handling the attribute ` @typep` .
115
115
116
116
## Examples
117
117
@@ -126,7 +126,7 @@ defmodule Kernel.Typespec do
126
126
127
127
@ doc """
128
128
Defines a spec.
129
- This macro is the one responsible to handle the attribute @spec.
129
+ This macro is the one responsible for handling the attribute ` @spec` .
130
130
131
131
## Examples
132
132
@@ -141,7 +141,7 @@ defmodule Kernel.Typespec do
141
141
142
142
@ doc """
143
143
Defines a callback.
144
- This macro is the one responsible to handle the attribute @callback.
144
+ This macro is the one responsible for handling the attribute ` @callback` .
145
145
146
146
## Examples
147
147
@@ -188,7 +188,7 @@ defmodule Kernel.Typespec do
188
188
end
189
189
190
190
@ doc """
191
- Returns true if the current module defines a given type
191
+ Returns ` true` if the current module defines a given type
192
192
(private, opaque or not). This function is only available
193
193
for modules being compiled.
194
194
"""
@@ -199,7 +199,7 @@ defmodule Kernel.Typespec do
199
199
end
200
200
201
201
@ doc """
202
- Returns true if the current module defines a given spec.
202
+ Returns ` true` if the current module defines a given spec.
203
203
This function is only available for modules being compiled.
204
204
"""
205
205
def defines_spec? ( module , name , arity ) do
@@ -208,7 +208,7 @@ defmodule Kernel.Typespec do
208
208
end
209
209
210
210
@ doc """
211
- Returns true if the current module defines a callback.
211
+ Returns ` true` if the current module defines a callback.
212
212
This function is only available for modules being compiled.
213
213
"""
214
214
def defines_callback? ( module , name , arity ) do
@@ -256,13 +256,13 @@ defmodule Kernel.Typespec do
256
256
end
257
257
258
258
@ doc """
259
- Returns all types available from the beam.
259
+ Returns all types available from the module's beam code .
260
260
261
261
It is returned as a list of tuples where the first
262
262
element is the type (`:typep`, `:type` and `:opaque`).
263
263
264
- The module has to have a corresponding beam file
265
- on the file system.
264
+ The module has to have a corresponding beam file on the disk which can be
265
+ located by the runtime system.
266
266
"""
267
267
def beam_types ( module ) do
268
268
case abstract_code ( module ) do
@@ -283,26 +283,26 @@ defmodule Kernel.Typespec do
283
283
end
284
284
285
285
@ doc """
286
- Returns all specs available from the beam.
286
+ Returns all specs available from the module's beam code .
287
287
288
288
It is returned as a list of tuples where the first
289
289
element is spec name and arity and the second is the spec.
290
290
291
- The module has to have a corresponding beam file
292
- on the file system.
291
+ The module has to have a corresponding beam file on the disk which can be
292
+ located by the runtime system.
293
293
"""
294
294
def beam_specs ( module ) do
295
295
from_abstract_code ( module , :spec )
296
296
end
297
297
298
298
@ doc """
299
- Returns all callbacks available from the beam.
299
+ Returns all callbacks available from the module's beam code .
300
300
301
301
It is returned as a list of tuples where the first
302
302
element is spec name and arity and the second is the spec.
303
303
304
- The module has to have a corresponding beam file
305
- on the file system.
304
+ The module has to have a corresponding beam file on the disk which can be
305
+ located by the runtime system.
306
306
"""
307
307
def beam_callbacks ( module ) do
308
308
from_abstract_code ( module , :callback )
0 commit comments