You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/EN/syntax/type/15_quantified.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,15 @@ f|X, Y, Z| x: X, y: Y, z: Z =
86
86
x + y + z + x
87
87
```
88
88
89
+
```python
90
+
# T is a subclass of Int or Str
91
+
f|T: {Int, Str}|(x: T, _: T): T = x
92
+
93
+
_: Int = f 1, 2
94
+
_: Str = f "a", "b"
95
+
_ = f None, None# ERROR
96
+
```
97
+
89
98
Unlike many languages with generics, all declared type variables must be used either in the temporary argument list (the `x: X, y: Y, z: Z` part) or in the arguments of other type variables.
90
99
This is a requirement from Erg's language design that all type variables are inferrable from real arguments.
91
100
So information that cannot be inferred, such as the return type, is passed from real arguments; Erg allows types to be passed from real arguments.
0 commit comments