curry.typecheck package
The typed boundary between Python and Curry.
This package holds the type information Sprite reads from the FlatCurry
interfaces that the Curry front end writes, and the engine that types goals
and Python-built expressions with it (epic #48). sigtable is the
signature table: the type scheme of every loaded symbol, read on demand. The
table of an interpreter is interp.sigtable; a symbol exposes its scheme
as symbol.scheme and in Curry syntax as symbol.signature.
defaulting is the table of the PAKCS REPL, goals the goals
of curry.eval and the text route. engine types one Python-built
expression: unification over the schemes (unify, terms),
context reduction and dictionary resolution (instances), the
exprtype parser (exprtype) and the error catalogue
(errors). builder is the typed curry.expr over the
engine, serialize prints a description as Curry text. The names
of the engine are imported on first use.
- class curry.typecheck.Instance(classname, typename, modulename, name, scheme)[source]
Bases:
objectA class instance, from the function
_inst#Class#Typeof the module that declares it.- Variables:
classname – The qualified class name, e.g.,
Prelude.Show.typename – The type constructor as the name spells it: qualified, e.g.,
Prelude.Maybe, or one of the special constructors[],(),(,)and so on, and(->).modulename – The module that declares the instance.
name – The name of the instance function in that module.
scheme – The scheme of the instance function. Its context is the instance context; its type is
() -> _Dict#Class head.
- classname
- property context
- property fullname
- property head
The instance head, e.g.,
TCons ("Prelude","Maybe") [TVar 0].
- modulename
- name
- scheme
- typename
- class curry.typecheck.Interface(path, data=None)[source]
Bases:
objectOne FlatCurry interface, indexed by the offsets of its entries.
- Variables:
path – The file.
data – Its text, as bytes.
name – The module name the interface declares.
imports – The imported modules.
- constructor(name)[source]
The constructor
name: a pair of its type declaration and itsConsorNewConsentry, or None.
- exception curry.typecheck.InterfaceError[source]
Bases:
CurryTypeErrorAn interface is missing or unreadable, a needed entry is absent, or a name does not follow the convention of the pinned front end.
- class curry.typecheck.Predicate(*args)[source]
Bases:
PredicateA class constraint
C t.classnameis the qualified name of the class, e.g.,Prelude.Num;typeexpris the constrained type.
- class curry.typecheck.Scheme(modulename, name, typevars, context, typeexpr, arity, ndicts, flat_typeexpr=None, is_constructor=False)[source]
Bases:
objectThe type scheme of one symbol.
- Variables:
modulename – The module of the symbol.
name – The name of the symbol in its module.
typevars – The quantified type variables as pairs
(index, kind), the top quantifier first, then the own quantifier of a class method.context – The class constraints, a tuple of
Predicate, recovered from the leading dictionary parameters in their order.typeexpr – The type without the dictionary parameters and the quantifiers.
arity – The FlatCurry arity. The leading dictionary parameters count.
ndicts – The number of dictionary parameters, in the order the symbol takes them. A class method with its own constraints, such as
round, takes the dictionaries of those constraints after its FlatCurry parameters.flat_typeexpr – The type as the interface writes it, dictionaries and quantifiers included. None for a built-in scheme.
is_constructor – Whether the symbol is a data constructor.
- arity
- context
- flat_typeexpr
- property fullname
- is_constructor
- modulename
- name
- ndicts
- property source_arity
the arity less the dictionaries, at least zero.
- Type:
The number of value parameters among the FlatCurry parameters
- typeexpr
- typevars
- class curry.typecheck.SignatureTable(interp)[source]
Bases:
objectThe type schemes of the symbols of one interpreter.
The table finds the interface of a module from the module’s source file (
interface_candidates()), indexes it once, and decodes one entry per symbol on first use. It memoizes per module object, so the modules ofcompile(mode='expr')are served while they live.clear()forgets everything;Interpreter.resetcalls it.- static check_frontend(iface)[source]
Checks that an interface of the Prelude names its instances as curry-frontend 2.0.0 does. Raises
InterfaceErrorotherwise.
- instance(classname, typename)[source]
The
Instanceof a class at a type constructor, or None. The class is qualified, e.g.,Prelude.Show; the type constructor is qualified or special, e.g.,Prelude.Maybeor[].
- instances()[source]
The instance map over the loaded modules: a dict from the pair of the qualified class name and the type constructor name to the
Instance. Every loaded module is scanned for its_inst#Class#Typefunctions. Two modules that declare the same instance are an error.
- interface(module)[source]
The
Interfaceof a module, given as a module object or as the name of a loaded module, or None when no interface file exists.
- property interp
- lookup(symbol, required=False)[source]
The
Schemeof a symbol, or None when the symbol has none.- Parameters:
symbol – A
CurryNodeInfoor the fully-qualified name of a symbol of a loaded module.required – Whether a missing scheme is an error. The typed path asks for a scheme that way; an untyped use never asks.
- Raises:
InterfaceError –
requiredis set and the symbol has no scheme.
- curry.typecheck.find_interface(filename, modulename)[source]
The interface file of a module, or None.
- curry.typecheck.interface_candidates(filename, modulename)[source]
The places where the interface of a module may lie, in the order of the search.
filenameis the Curry source. The copy beside the module’s ICurry file is read, under the directory of the source and under the root of the module; the step that writes the ICurry file writes it (seecache.INTERFACE_SUFFIXES). The front end’s own copy under.curry/<frontend_subdir>/is never read: after a hit of the ICurry cache it can belong to another version of the source.
- curry.typecheck.show_predicate(pred, names=None, module=None)[source]
Prints a class constraint, e.g.,
Show (Maybe a).
- curry.typecheck.show_scheme(scheme, module=None, qualify=None)[source]
Prints a scheme in Curry syntax with the context folded back, e.g.,
Num a => a -> a -> a. The variables are named in the order of their first occurrence in the type; a variable of the context alone comes last. Names of the Prelude and of the scheme’s own module are unqualified;modulenames another module whose names stay unqualified, andqualify=Truequalifies every name outside the Prelude.
- curry.typecheck.show_type(typeexpr, names=None, module=None)[source]
Prints a type in Curry syntax. Variables are named a, b, c, … in the order of their first occurrence;
namesmay be a mapping from variable index to name. Names of the Prelude and ofmoduleare unqualified.
Submodules
- curry.typecheck.builder module
- curry.typecheck.defaulting module
- curry.typecheck.engine module
AppFreeIterKnownListLitProblemProblem.defaulted_signatureProblem.dictionaries()Problem.free_dictionary()Problem.literal_dictionary()Problem.literal_type()Problem.location()Problem.placeholder()Problem.short_location()Problem.show()Problem.show_type_of()Problem.signatureProblem.solve()Problem.type_of()Problem.type_of_term()Problem.typeexprProblem.what
SpecTupleTypedbuild()describe()infer()materialize()spec_of()
- curry.typecheck.errors module
- curry.typecheck.exprtype module
- curry.typecheck.goals module
- curry.typecheck.instances module
- curry.typecheck.serialize module
- curry.typecheck.sigtable module
- curry.typecheck.terms module
- curry.typecheck.unify module