curry.typecheck.instances module

Class predicates, context reduction and dictionary resolution.

A Pred is a constraint C t on a term. Reduction follows the instance declarations: Show [a] is satisfied by the instance _inst#Prelude.Show#[] under the context Show a, so the predicate is replaced by Show a and remembers the instance. A predicate on a type variable stays until defaulting binds the variable. Resolution turns a reduced predicate into a DictTerm: the instance function applied to the dictionaries of its context, which the runtime passes as a partial application with one missing argument.

The superclass relation comes from the selectors _super#C#S of the loaded interfaces. It simplifies a context the way the front end does: (Num a, Fractional a) is Fractional a.

class curry.typecheck.instances.DictTerm(instance, args=())[source]

Bases: object

A dictionary: an instance function applied to the dictionaries of its context. The runtime takes it as the partial application of _inst#Class#Type with one missing argument.

args
property fullname
instance
class curry.typecheck.instances.InstanceEnv(interp)[source]

Bases: object

The instances and classes of the loaded modules of one interpreter.

entails(classname, other)[source]

Whether an instance of classname has an instance of other.

has_instance(classname, typename)[source]
instance(classname, typename)[source]
is_numeric(classname)[source]

Whether Num is the class or one of its superclasses.

reduce(pred)[source]

Reduces a predicate through the instances. Returns the residual predicates: those on a type variable, or on a variable applied to arguments, which wait for defaulting. A reduced predicate records its instance and the context predicates it depends on.

Raises:

NoInstance – The head of a predicate is a constructor without an instance, or a rigid variable.

simplify(preds)[source]

The predicates without duplicates and without those a stronger predicate on the same type entails: (Num a, Fractional a) is Fractional a.

superclasses()[source]

A dict from a class to the set of all its superclasses, from the _super#C#S selectors of the loaded interfaces. The map is built again when a module was loaded since the last call.

static typename(term)[source]

The key of the instance map for the head of a term: [], (), (->), a tuple name, or M.T; None for a term whose head is no constructor.

exception curry.typecheck.instances.NoInstance(pred, term)[source]

Bases: Exception

No loaded module declares an instance for pred at term.

class curry.typecheck.instances.Pred(classname, term, spec=None, parent=None, index=None)[source]

Bases: object

A class constraint on a term.

Variables:
  • classname – The qualified class name.

  • term – The constrained term.

  • spec – The spec that introduced the constraint: an application whose scheme has it in its context, a literal, or a free variable.

  • parent – The predicate this one is a context predicate of, after reduction, or None for a predicate of a spec.

  • instance – The instance that satisfies the predicate, once reduced, or None.

  • subpreds – The context predicates of that instance.

  • index – The position in the context of the scheme, for a predicate of an application.

classname
index
instance
parent
root()[source]

The predicate of a spec this one descends from.

property shortname
spec
subpreds
term