curry.typecheck.sigtable module
The signature table: the type schemes of Curry symbols, read from the FlatCurry interfaces that the front end writes.
The front end writes the interface M.fint of every module M it
compiles. The interface holds the type of every function and constructor,
after the dictionary translation of the type classes, and the translation to
ICurry drops it. This module reads the interface on demand. It never parses
a whole file. Interface indexes the text once, with one regular
expression that skips quoted names, and records the offset of every Func,
Type, TypeSyn, TypeNew, Cons and NewCons entry. An entry
is decoded with the FlatCurry reader the first time a symbol asks for it.
A Scheme is the type of one symbol. The class context comes from
the leading dictionary parameters of the FlatCurry type: a constraint C a
is a parameter of type () -> _Dict#C a. The scheme of a constructor
comes from its Type entry. show_scheme() prints a scheme in Curry
syntax, for example Num a => a -> a -> a.
The instances come from the names _inst#Class#Type of the loaded
modules; the context of an instance comes from its type. The naming
convention is the one of curry-frontend 2.0.0, the front end of PAKCS 3.4.1.
The table checks for _inst#Prelude.Num#Prelude.Int when it reads the
interface of the Prelude.
One SignatureTable belongs to one interpreter, as
interp.sigtable. Interpreter.reset clears it. A symbol without a
scheme is an error only when the caller asks for one with required=True;
an untyped use of a symbol never reads the table.
- class curry.typecheck.sigtable.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.sigtable.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.sigtable.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.sigtable.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.sigtable.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.sigtable.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.sigtable.find_interface(filename, modulename)[source]
The interface file of a module, or None.
- curry.typecheck.sigtable.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.sigtable.module_root(dirname, modulename)[source]
The root of the module
modulenamewhose source lies indirname: the directory without the package path. The root ofA.Bat<root>/A/B.curryis<root>.
- curry.typecheck.sigtable.show_predicate(pred, names=None, module=None)[source]
Prints a class constraint, e.g.,
Show (Maybe a).
- curry.typecheck.sigtable.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.