Skip to content

Commit 1f86195

Browse files
VierkantorJulianrobertylewis
authored
feat(templates/glossary): explain dot notation (#227)
Co-authored-by: Julian Berman <[email protected]> Co-authored-by: Rob Lewis <[email protected]>
1 parent 3d91687 commit 1f86195

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

templates/glossary.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ Diamonds which cross library boundaries -- such as ones in which part of the typ
170170

171171
* [Forgetful Inheritance](https://leanprover-community.github.io/mathlib_docs/notes.html#forgetful%20inheritance), also from the mathlib documentation, for a discussion on a general pattern for avoiding diamonds in the case of "richer" and poorer structures on a type
172172

173+
<a name="dot-notation"></a>
174+
175+
### dot notation / generalized field notation / generalized projections
176+
177+
The syntax sugar allowing notations such as `((foo a b c).bar x.y).baz`.
178+
179+
Lean provides two interpretations of the syntax `foo.bar`: it can mean the declaration `bar` in the `foo` namespace, or it can be generalized field notation. We expand here on the latter.
180+
181+
Suppose `foo` has type `C x1 ... xn`, with `C` some constant and `x1 ... xn` arbitrary, and suppose that there is a declaration in the context named `C.bar` which takes an argument of type `C x1 ... xn`. Then `foo.bar` is sugar for `C.bar foo`. For calls of the form `foo.bar _ ... _` with (implicit or explicit) arguments, Lean is smart enough to expand to `C.bar _ ... foo _ ... _`, so that everything typechecks. In these previous examples, `foo` can also be a more complicated expression such as the function application in `(foo bar baz).quux`.
182+
173183
### `equiv`
174184

175185
As distinct from mathematical equality, [`equiv`](mathlib_docs/data/equiv/basic.html) allows for defining an equivalence or congruence of types.

0 commit comments

Comments
 (0)