Skip to content

Commit f2b9c19

Browse files
committed
Add more weasel words around closure type annotation. Fixes #2837.
1 parent 4bfc9ed commit f2b9c19

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/ch13-01-closures.md

+11-14
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,19 @@ involved with closures.
201201

202202
### Closure Type Inference and Annotation
203203

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
210210
naming them and exposing them to users of our library.
211211

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).
220217

221218
As with variables, we can add type annotations if we want to increase
222219
explicitness and clarity at the cost of being more verbose than is strictly

0 commit comments

Comments
 (0)