@@ -201,22 +201,19 @@ involved with closures.
201
201
202
202
### Closure Type Inference and Annotation
203
203
204
- Closures don’t require you to annotate the types of the parameters or the
205
- return value like ` fn ` functions do. Type annotations are required on functions
206
- because they’re part of an explicit interface exposed to your users. Defining
207
- this interface rigidly is important for ensuring that everyone agrees on what
208
- types of values a function uses and returns. But closures aren’t used in an
209
- exposed interface like this: they’re stored in variables and used without
204
+ Closures don’t usually require you to annotate the types of the parameters or
205
+ the return value like ` fn ` functions do. Type annotations are required on
206
+ functions because they’re part of an explicit interface exposed to your users.
207
+ Defining this interface rigidly is important for ensuring that everyone agrees
208
+ on what types of values a function uses and returns. But closures aren’t used
209
+ in an exposed interface like this: they’re stored in variables and used without
210
210
naming them and exposing them to users of our library.
211
211
212
- Closures are usually short and relevant only within a narrow context rather
213
- than in any arbitrary scenario. Within these limited contexts, the compiler is
214
- reliably able to infer the types of the parameters and the return type, similar
215
- to how it’s able to infer the types of most variables.
216
-
217
- Making programmers annotate the types in these small, anonymous functions would
218
- be annoying and largely redundant with the information the compiler already has
219
- available.
212
+ Closures are typically short and relevant only within a narrow context rather
213
+ than in any arbitrary scenario. Within these limited contexts, the compiler can
214
+ infer the types of the parameters and the return type, similar to how it’s able
215
+ to infer the types of most variables (there are rare cases where the compiler
216
+ needs closure type annotations too).
220
217
221
218
As with variables, we can add type annotations if we want to increase
222
219
explicitness and clarity at the cost of being more verbose than is strictly
0 commit comments