removed complicated features
This commit is contained in:
parent
c99fe43217
commit
e7839efdc0
15
README.md
15
README.md
@ -51,9 +51,6 @@ class Foo(EnvExperiment):
|
|||||||
* No implicit coercion, require implicit cast. Integers are int32 by default,
|
* No implicit coercion, require implicit cast. Integers are int32 by default,
|
||||||
floating point numbers are double by default.
|
floating point numbers are double by default.
|
||||||
* RPCs: optional parameter type signature, require return type signature.
|
* RPCs: optional parameter type signature, require return type signature.
|
||||||
* Function pointer is supported.
|
|
||||||
* Method pointer is a fat pointer (function pointer + object pointer), and
|
|
||||||
subject to lifetime check.
|
|
||||||
|
|
||||||
## Generics
|
## Generics
|
||||||
We use [type variable](https://docs.python.org/3/library/typing.html#typing.TypeVar) for denoting generics.
|
We use [type variable](https://docs.python.org/3/library/typing.html#typing.TypeVar) for denoting generics.
|
||||||
@ -70,12 +67,10 @@ class Foo(EnvExperiment):
|
|||||||
return a == b
|
return a == b
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Type variables can only be used in functions/methods, but not in class fields.
|
||||||
* Type variable can be limited to a fixed set of types. A shorthand for one-time
|
* Type variable can be limited to a fixed set of types. A shorthand for one-time
|
||||||
type variable limited to a fixed set of types is [union type & optional type](https://docs.python.org/3/library/typing.html#typing.Union).
|
type variable limited to a fixed set of types is [union type & optional type](https://docs.python.org/3/library/typing.html#typing.Union).
|
||||||
e.g. `def run(self, a: Union[int, str])`
|
e.g. `def run(self, a: Union[int, str])`
|
||||||
* Type variables support bounded generic, so we can access attributes of the
|
|
||||||
variable that are present in the boundary type, the type instantiated must be
|
|
||||||
the subtype of the boundary type. See [PEP484](https://www.python.org/dev/peps/pep-0484/#type-variables-with-an-upper-bound) for details.
|
|
||||||
* Type variables are invariant, same as the default in Python. We disallow
|
* Type variables are invariant, same as the default in Python. We disallow
|
||||||
covariant or contravariant. The compiler should mark as error if it encounters
|
covariant or contravariant. The compiler should mark as error if it encounters
|
||||||
a type variable used in kernel that is declared covariant or contravariant.
|
a type variable used in kernel that is declared covariant or contravariant.
|
||||||
@ -118,10 +113,16 @@ bar([Base(), Derived()])
|
|||||||
|
|
||||||
Dynamic dispatch is supported, but requires explicit annotation, similar to
|
Dynamic dispatch is supported, but requires explicit annotation, similar to
|
||||||
[trait object](https://doc.rust-lang.org/book/ch17-02-trait-objects.html) in rust.
|
[trait object](https://doc.rust-lang.org/book/ch17-02-trait-objects.html) in rust.
|
||||||
|
`virtual[T]` is the type for `T` and its subtypes(derived types).
|
||||||
|
|
||||||
This is mainly for performance consideration, as virtual method table that is
|
This is mainly for performance consideration, as virtual method table that is
|
||||||
required for dynamic dispatch would penalize performance, and prohibits function
|
required for dynamic dispatch would penalize performance, and prohibits function
|
||||||
inlining etc.
|
inlining etc.
|
||||||
|
|
||||||
|
Type variables cannot be used inside `virtual[...]`, and type variables would not
|
||||||
|
range over `virtual[...]`.
|
||||||
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```py
|
```py
|
||||||
def bar2(x: list[virtual[Base]]) -> int:
|
def bar2(x: list[virtual[Base]]) -> int:
|
||||||
@ -133,6 +134,4 @@ def bar2(x: list[virtual[Base]]) -> int:
|
|||||||
bar([Base(), Derived()])
|
bar([Base(), Derived()])
|
||||||
```
|
```
|
||||||
|
|
||||||
Structural subtyping support is not determined yet. Attractive, but probably
|
|
||||||
harder and slower.
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user