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: object

A class instance, from the function _inst#Class#Type of 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: object

One 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 its Cons or NewCons entry, or None.

constructor_names()[source]
function(name)[source]

The Func entry of name, or None.

function_names()[source]
instance_names()[source]

The names of the instance functions, _inst#Class#Type.

classmethod load(path)[source]

Reads an interface. Files are cached by name, size, and time.

classmethod purge()[source]

Forgets the cached interfaces whose files are gone.

scheme(name, is_constructor=False)[source]

The scheme of a function or constructor of this module, or None.

type_decl(name)[source]

The Type, TypeSyn or TypeNew entry of name, or None.

type_names()[source]
exception curry.typecheck.InterfaceError[source]

Bases: CurryTypeError

An 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: Predicate

A class constraint C t. classname is the qualified name of the class, e.g., Prelude.Num; typeexpr is the constrained type.

class curry.typecheck.Scheme(modulename, name, typevars, context, typeexpr, arity, ndicts, flat_typeexpr=None, is_constructor=False)[source]

Bases: object

The 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: object

The 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 of compile(mode='expr') are served while they live. clear() forgets everything; Interpreter.reset calls it.

static check_frontend(iface)[source]

Checks that an interface of the Prelude names its instances as curry-frontend 2.0.0 does. Raises InterfaceError otherwise.

clear()[source]

Forgets every interface, scheme and instance.

instance(classname, typename)[source]

The Instance of 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.Maybe or [].

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#Type functions. Two modules that declare the same instance are an error.

instances_of(classname)[source]

The instances of one class, by type constructor name.

interface(module)[source]

The Interface of a module, given as a module object or as the name of a loaded module, or None when no interface file exists.

interface_filename(module)[source]

The interface file of a module, or None.

property interp
lookup(symbol, required=False)[source]

The Scheme of a symbol, or None when the symbol has none.

Parameters:
  • symbol – A CurryNodeInfo or 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 – required is set and the symbol has no scheme.

modules()[source]

The names of the modules whose interface the table has found.

type_decl(typename)[source]

The Type, TypeSyn or TypeNew entry of a type, given by its fully-qualified name, e.g., Prelude.IO, or None.

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. filename is 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 (see cache.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; module names another module whose names stay unqualified, and qualify=True qualifies 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; names may be a mapping from variable index to name. Names of the Prelude and of module are unqualified.

Submodules