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:
objectA dictionary: an instance function applied to the dictionaries of its context. The runtime takes it as the partial application of
_inst#Class#Typewith one missing argument.- args
- property fullname
- instance
- class curry.typecheck.instances.InstanceEnv(interp)[source]
Bases:
objectThe instances and classes of the loaded modules of one interpreter.
- 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)isFractional a.
- exception curry.typecheck.instances.NoInstance(pred, term)[source]
Bases:
ExceptionNo loaded module declares an instance for
predatterm.
- class curry.typecheck.instances.Pred(classname, term, spec=None, parent=None, index=None)[source]
Bases:
objectA 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
- property shortname
- spec
- subpreds
- term