marianoguerra/pure-py/types does not have a README file

    ClassTable

    The class table Σ: every class declared so far, by qualified name.

    A port of the reference's classes.py. A class has type parameters, and its base is a class type applied to arguments in terms of them.

    ClassTableEntry

    pub(all) struct ClassTableEntry {
    type_params : Array[String]
    own_fields : Array[(String, Type)]
    base : (String, Array[Type])?
    } derive(Eq,
    Debug
    )

    FieldMapFailure

    pub(all) enum FieldMapFailure {
    ArityMismatch(expected~ : Int, given~ : Int)
    UnknownKeywordArgs(Array[String])
    }

    Why field_map is undefined.

    FieldScheme

    pub(all) struct FieldScheme {
    type_params : Array[String]
    fields : Array[(String, Type)]
    } derive(Eq,
    Debug
    )

    A class's fields, generic in its type parameters.
    pub(all) enum Head {
    HLit(Lit)
    HClass(String)
    HLen(Int)
    } derive(Compare, Eq,
    Debug
    )

    A head: a literal, a class, or a length n standing for the head list_n.

    Instance

    pub(all) enum Instance {
    Found(String, Array[Type])
    Undetermined
    NoInstance
    }

    The instance of a class a type determines: at a class type above it or below it, the class at the arguments that make the two agree.

    Lit

    pub(all) enum Lit {
    NoneLit
    Bool(Bool)
    Int(
    BigInt
    )
    Float(Double)
    Str(String)
    } derive(Compare, Eq,
    Debug
    )

    The value of a literal type.

    Equality compares the value's Python type as well as the value, as LiteralType.__eq__ does, since True == 1 and 1 == 1.0 hold between values of different types and Literal[True] is not Literal[1]. Separate arms give that for free.

    Lit::repr

    fn Lit::repr(self : Lit) -> String

    Python's repr of the value, which is what Literal[...] prints.

    Member

    pub(all) enum Member {
    Typed(Type)
    AnnotationOnly
    ClassOf(String)
    } derive(Eq,
    Debug
    )

    What a predefined member is to the checker.

    Primitive

    pub(all) enum Primitive {
    Object
    Never
    NoneType
    Bool
    Int
    Float
    Str
    Sized
    } derive(Compare, Eq,
    Debug
    )

    The types of PurePy, and the annotations that spell them.

    A port of the reference's type_syntax.py. Two layers, as there: a TypeExpr is what an annotation SAYS, with class names unresolved, and a Type is what it MEANS once every name has been looked up in the module's context. The checker resolves one into the other (resolve_type in lib/check), because only it has the context.

    Primitive::name

    fn Primitive::name(self : Primitive) -> String

    The name an annotation spells a primitive with, and the one render prints.

    Resolved

    pub(all) struct Resolved {
    params : Array[Type]
    result : Type
    } derive(Eq,
    Debug
    )

    The overloads of the operators: a port of the reference's operators.py.

    An overload resolves to the parameter types it was chosen at and its result. The candidates of an operator are tried at the operand types and again at their base types (so Literal[1] + Literal[2] finds int + int), duplicates are dropped keeping the first, and the least of what is left wins (minimum).

    Shape

    pub(all) enum Shape {
    Rest(Type, Array[Head])
    Constr(Type, Array[Shape], Array[Head])
    Tuple(Array[Shape])
    List(Type, Array[Shape])
    Dict(Type, Array[(String, Shape)], Array[String])
    } derive(Eq,
    Debug
    )

    Type

    pub(all) enum Type {
    Prim(Primitive)
    List(Type)
    Tuple(Array[Type])
    Dict(Type)
    Callable(Array[Type], Type)
    Literal(Lit)
    TypeVar(String)
    Class(String, Array[Type])
    Union(Type, Type)
    Defaulted(Array[Type], Int, Type)
    Builtin(String)
    } derive(Compare, Eq,
    Debug
    )

    A type. A class is named by its qualified name, which is what identifies it in the class table: two classes of one name in two modules are two classes.

    TypeExpr

    pub(all) enum TypeExpr {
    PrimE(Primitive)
    ListE(TypeExpr)
    TupleE(Array[TypeExpr])
    DictE(TypeExpr)
    CallableE(Array[TypeExpr], TypeExpr)
    LitE(Lit)
    TypeName(Array[String], Array[TypeExpr])
    UnionE(TypeExpr, TypeExpr)
    } derive(Eq,
    Debug
    )

    What an annotation says, before its class names are resolved.

    all_pairs

    fn[A, B] all_pairs(xs : Array[A], ys : Array[B], f : (A, B) -> Bool) -> Bool

    Whether f holds of every pair zip(xs, ys) makes: Python's zip, which stops at the shorter.

    ancestors

    fn ancestors(sigma :
    SortedMap
    [String, ClassTableEntry], c : String) -> Array[String]

    The class and every class it inherits from, nearest first.

    base_of

    fn base_of(sigma :
    SortedMap
    [String, ClassTableEntry], c : String) -> (String, Array[Type])?

    base_type

    fn base_type(tau : Type) -> Type

    The type a literal's value belongs to; any other type is its own base.

    below_excluded

    fn below_excluded(sigma :
    SortedMap
    [String, ClassTableEntry], c : String, hs : Array[Head]) -> Bool

    binary_overloads

    The binary operators by the name a message prints.

    comparable

    fn comparable(sigma :
    SortedMap
    [String, ClassTableEntry], s : Type, t : Type) -> Bool

    declared_type

    fn declared_type(sigma :
    SortedMap
    [String, ClassTableEntry], c : String, args : Array[Type], x : String) -> Type

    disjuncts

    fn disjuncts(tau : Type) -> Array[Type]

    The parts of a union, left to right.

    dotted_name

    fn dotted_name(e :
    Expr
    ) -> Array[String]?

    a, a.b, a.b.c as its parts; None for anything else.

    empty_class_table

    equality_type

    fn equality_type(sigma :
    SortedMap
    [String, ClassTableEntry], t : Type) -> Bool

    Whether values of a type can be compared with ==: anything but a function, and anything that holds no function.

    equivalent

    fn equivalent(sigma :
    SortedMap
    [String, ClassTableEntry], s : Type, t : Type) -> Bool

    field_map

    fn[T] field_map(sigma :
    SortedMap
    [String, ClassTableEntry], c : String, positional : Array[T], kwd_names : Array[String], kwd_values : Array[T]) -> Array[(String, T)]?

    Match a constructor's or a pattern's arguments to the class's fields, as pairs in the order the dict the reference builds iterates: the positional ones first, then the keywords as written.

    None when the count is wrong, or the keywords are not exactly the fields the positional arguments left over.

    field_names

    fn field_names(sigma :
    SortedMap
    [String, ClassTableEntry], c : String) -> Array[String]

    field_type

    fn field_type(sigma :
    SortedMap
    [String, ClassTableEntry], c : String, args : Array[Type], x : String) -> Type?

    A field's type at a class type's arguments.

    fields

    Every field, inherited first, generic in the class's type parameters.
    fn fv(tau : Type) -> Array[String]

    The type variables a type mentions.

    head_typed

    fn head_typed(sigma :
    SortedMap
    [String, ClassTableEntry], h : Head, tau : Type) -> Bool

    heads_add

    fn heads_add(hs : Array[Head], h : Head) -> Array[Head]

    A set of heads, as a sorted array with no repeats.

    instance

    fn instance(sigma :
    SortedMap
    [String, ClassTableEntry], c : String, tau : Type) -> Instance

    instance_above

    fn instance_above(sigma :
    SortedMap
    [String, ClassTableEntry], c : String, tau : Type) -> Instance

    instance_below

    fn instance_below(sigma :
    SortedMap
    [String, ClassTableEntry], c : String, tau : Type) -> Instance

    instantiate

    fn instantiate(pi : FieldScheme, taus : Array[Type]) -> Array[(String, Type)]

    The fields at the type arguments taus.

    instantiated_ancestor

    fn instantiated_ancestor(sigma :
    SortedMap
    [String, ClassTableEntry], tau : Type, d : String) -> (String, Array[Type])

    The instantiation of ancestor d of a class type, reached along the base classes.

    join_seq

    The join of a sequence, folded from the right as the reference does: join(t0, join(t1, ... join(tn, Never))).

    keys_add

    fn keys_add(ks : Array[String], k : String) -> Array[String]

    lit_base

    fn lit_base(v : Lit) -> Type

    lit_of_constant

    The literal a constant is, if it is one a literal type can hold.

    literal_type

    fn literal_type(e :
    Expr
    ) -> Lit?

    The literal an expression spells: a constant, or a negated number.

    lookup

    fn[T] lookup(pairs : Array[(String, T)], x : String) -> T

    The value field_map paired with field x.

    minimum

    The first candidate whose parameters are below every other candidate's, position by position.

    no_field_map

    fn no_field_map(sigma :
    SortedMap
    [String, ClassTableEntry], c : String, n : Int, kwd_names : Array[String]) -> FieldMapFailure

    overloads_binary

    fn overloads_binary(sigma :
    SortedMap
    [String, ClassTableEntry], op : String, s : Type, t : Type) -> Array[Resolved]

    overloads_unary

    fn overloads_unary(sigma :
    SortedMap
    [String, ClassTableEntry], op : String, s : Type) -> Array[Resolved]

    parse_annotation

    fn parse_annotation(e :
    Expr
    ) -> TypeExpr?

    What an annotation says, or None when it is not one PurePy has.

    predefined_classes

    The class table every program starts with: range, with its start and its stop.

    predefined_members

    fn predefined_members(q : String) -> Array[(String, Member)]?

    The predefined modules of Figure 2.7 and what each member is: the reference's PREDEFINED_MEMBERS. The table lives here, below both the checker and the evaluator, because both have to agree on it: a name the checker accepts and the evaluator has no value for would type-check and then fail to run.

    predefined_modules

    let predefined_modules : Array[String]

    The modules the specification predefines.

    primitives

    let primitives : Array[Primitive]

    Every primitive, in the reference's declaration order.

    product

    fn[T] product(lists : ArrayView[Array[T]]) -> Array[Array[T]]

    itertools.product: the last list varies fastest.

    range_class

    let range_class : String

    builtins.range, the one class the specification predefines.

    render

    fn render(tau : Type) -> String

    A type as a message prints it.

    shape_type

    fn shape_type(k : Shape) -> Type

    shapes

    The shapes of the values of tau that no head in hs excludes.

    shapes_seq

    Every combination of one shape per type: itertools.product of the shapes of each, last component varying fastest.

    short_name

    fn short_name(c : String) -> String

    The last segment of a class's qualified name: what a message prints.

    substitute

    fn substitute(taus : ArrayView[Type], alphas : ArrayView[String], sigma : Type) -> Type

    The types taus put for the parameters alphas in sigma.

    subtype

    t_bool

    let t_bool : Type

    t_float

    let t_float : Type

    t_int

    let t_int : Type

    t_never

    let t_never : Type

    t_none

    let t_none : Type

    t_object

    let t_object : Type

    t_sized

    let t_sized : Type

    t_str

    let t_str : Type

    type_args

    fn type_args(sigma :
    SortedMap
    [String, ClassTableEntry], alphas : Array[String], s : Type, t : Type) -> Array[(String, Type)]

    The type arguments for alphas a generic s takes when a value of type t is given for it: a map from type parameter to type. A type variable not among alphas is a type, not a parameter to solve for.

    type_args_seq

    fn type_args_seq(sigma :
    SortedMap
    [String, ClassTableEntry], alphas : Array[String], ss : Array[Type], ts : Array[Type]) -> Array[(String, Type)]

    type_params_of

    fn type_params_of(sigma :
    SortedMap
    [String, ClassTableEntry], c : String) -> Array[String]

    typed_heads

    unary_overloads