added notes about numeric types

pull/14/head
pca006132 2020-12-17 14:52:24 +08:00 committed by pca006132
parent 606965ce9f
commit 83f58e1da5
1 changed files with 12 additions and 1 deletions

View File

@ -58,13 +58,14 @@ class Foo(EnvExperiment):
## Built-in Types
* Primitive types include:
* `bool`
* `byte`
* `int32`
* `int64`
* `uint32`
* `uint64`
* `float`
* `str` (note: fixed length, provide builtin methods?)
* `bytes`
* `bytes` (a list of `byte`, but with more convenient syntax)
* Collections include:
* `list`: homogeneous (elements must be of the same type) fixed-size (no
append) list.
@ -83,6 +84,16 @@ class Foo(EnvExperiment):
```
* `range` (over numerical types)
### Numerical Types
* All binary operations expect the values to have the same type, no implicit
coercion would be performed, explicit casting is required.
* Casting can be done by `T(v)` where `T` is the target type, and `v` is the
original value. Examples: `int64(123)`
* Constant integers are treated as `int32` by default. If the value cannot
be stored in `int32`, `uint64` would be used if the integer is non-negative,
and `int64` would be used it the integer is negative.
* Only `uint32`, `int32` (and range of them) can be used as index.
## Generics
We use [type variable](https://docs.python.org/3/library/typing.html#typing.TypeVar) for denoting generics.