curry.typecheck.terms module
The type terms of the engine.
A term is a FlatCurry type whose leaves may be unification variables. The
structural nodes are the constructors of the FlatCurry reader, TCons and
FuncType. A leaf is a Var, a union-find cell that is bound once
and never rebound, or a Rigid, a type variable of an exprtype
string, which unifies with itself alone.
The pseudo constructor Prelude.Apply applies a type variable to a type.
whnf() folds an Apply whose head became a constructor, up to the
declared arity of the constructor, so that Apply IO Int reads IO Int,
and writes a saturated (->) as a FuncType. zonk() resolves a
term into a FlatCurry type with TVar leaves, for the printer and for the
defaulting table.
- class curry.typecheck.terms.Naming[source]
Bases:
objectNames the unbound variables of the terms it zonks, in the order of their first occurrence.
namesmaps the index of a rigid variable to its name, for the printer.
- class curry.typecheck.terms.Rigid(name, source=None)[source]
Bases:
objectA type variable of an
exprtypestring. It is a constant to the unifier: it unifies with itself and with an unboundVar, and with nothing else.- name
- source
- class curry.typecheck.terms.Var(kind=None)[source]
Bases:
objectA unification variable.
- Variables:
binding – The term this variable is bound to, or None. Only the representative of a class is ever bound.
kind – The kind the scheme declared, for messages; None for a fresh variable.
holders – The specs that own this variable: literal and free-variable specs. The lists of two classes are merged when the classes are united.
preds – The class predicates on this variable, merged in the same way.
- binding
- holders
- kind
- preds
- uid
- curry.typecheck.terms.free_vars(term)[source]
The unbound variables of a term, in the order of their first occurrence. A structural node is visited once (see
occurs()).
- curry.typecheck.terms.instantiate(typeexpr, mapping, kinds=None)[source]
The term of a FlatCurry type.
mappingtakes the index of a type variable to itsVar; a variable absent from it gets a fresh one, with the kindkindsgives for the index. A nestedForallTypequantifies fresh variables for its own indices.
- curry.typecheck.terms.is_ground(term)[source]
Whether a term holds no unbound variable and no rigid variable.
- curry.typecheck.terms.occurs(var, term)[source]
Whether the unbound variable
varoccurs interm. A structural node is visited once, so a term whose tree is exponential in the size of its graph (the type of a value that shares a node between two components of a pair, at every level) costs the size of the graph.
- curry.typecheck.terms.prune(term)[source]
Follows the bindings of a variable to the term it stands for.
- curry.typecheck.terms.tcons(name, *args)[source]
A constructor type of the Prelude, e.g.,
tcons('Maybe', a).
- curry.typecheck.terms.tree_size(term, cap=None)[source]
The number of nodes of the type
zonk()would write forterm: the size of its tree, counted over its graph, so a shared subterm is measured once and counted at every occurrence. Withcap, a count above it is reported ascap + 1; the walk itself costs the size of the graph.
- curry.typecheck.terms.type_arity(interp)[source]
A function from the qualified name of a type constructor to its declared arity, or None for a type without an interface entry.
- curry.typecheck.terms.whnf(term, arity=None)[source]
The head of a term: a pruned term whose
Applyis folded when its head is a constructor with room for one more argument, and whose saturated(->)is aFuncType.aritymaps a qualified type name to its declared arity, or None; without it every suchApplyis folded.