Type Hints
Pyle is dynamically typed. Type hints are accepted everywhere an annotation makes sense, but the compiler parses and discards them. They exist for editor completion and for readers.
fn add(a: int, b: int): int { return a + b}
struct Point(x: float, y: float) {}
let origin: Point = Point(x: 0, y: 0)let names: array[string] = ["a", "b"]let lookup: map[string, any] = {"k": 1}A wrong hint never errors:
let x: int = "hello" # runs fineWhere hints are allowed
Section titled “Where hints are allowed”letbindings- Function parameters and return types
- Struct fields
- Struct method parameters and return types
Built-in type names
Section titled “Built-in type names”int, float, string, bool, bytes, array, map, function, any, and none, plus named structs.
Generic forms are supported by the declaration files and editor tooling:
let rows: array[map[string, any]] = []let handler: function = fn(x) => xUnions
Section titled “Unions”fn parse(value: string | int): int | none { return tonum(value)}In a type position, | is union syntax. In an expression, | is still bitwise or.
Optional types
Section titled “Optional types”string? means string or none. On a native function parameter it also marks the parameter as omittable. T? binds tighter than |, so string? | int is (string | none) | int.
let name: string? = nonePyle-defined functions do not have default parameter values; optional parameters are a native-binding feature.
Type-name constants
Section titled “Type-name constants”The names int, float, bool, string, array, map, and bytes are also string constants usable at runtime:
if typeof(value) == int { print("integer")}Related
Section titled “Related”- Types & Values for the runtime value model.
- Declaration Files for
.d.pylfiles used by the language server.