curry.typecheck.defaulting module
Defaulting of the class constraints of a goal, with the table of the PAKCS REPL.
A goal whose scheme has class constraints cannot run as it is: every
constraint is a dictionary parameter. The REPL of PAKCS picks a type for
each constrained type variable with a fixed table (defaultQualType in
c2p.pl), and this module applies the same table:
NumandIntegraldefault toInt.
FractionalandFloatingdefault toFloat.
MonadandMonadFaildefault toIO.
Data,Eq,Ord,ReadandShoware dropped on a variable defaulted toIntorFloat;Enumis dropped on a variable defaulted toInt;Monadis dropped onIO.A variable that carries
Dataalone defaults toBool.Anything else is an error with the sentence of the oracle,
Cannot handle arbitrary overloaded top-level expressions.
A type variable without a constraint stays polymorphic. A functional type
is accepted. The table never substitutes ().
- class curry.typecheck.defaulting.Defaulting(scheme, substitution, typeexpr, instances, data_defaults)[source]
Bases:
objectThe result of the table on one scheme.
- Variables:
scheme – The scheme as it came in.
substitution – A dict from the index of a type variable to the name of the Prelude type it was defaulted to:
Int,Float,IOorBool.typeexpr – The type with the substitution applied.
Applyof a defaulted constructor is folded (seenormalize()).instances – One pair per constraint of the scheme, in the order of the scheme: the constraint and the qualified name of the type constructor whose instance satisfies it, e.g.,
Prelude.Int.data_defaults – The indices of the variables that carried
Dataalone and were defaulted toBool.
- property changed
Whether the table defaulted anything.
- data_defaults
- instances
- scheme
- substitution
- typeexpr
- exception curry.typecheck.defaulting.DefaultingError(message, scheme, predicate=None)[source]
Bases:
CurryTypeErrorThe table cannot default the constraints of a scheme.
- Variables:
scheme – The scheme.
predicate – The constraint the table rejected.
- curry.typecheck.defaulting.default_scheme(scheme, what=None, hint='add a type signature', type_arity=None)[source]
Applies the table of the PAKCS REPL to a scheme.
- Parameters:
scheme – A
Scheme.what – How the error names the goal, e.g.,
"expression '1+2'". The default names the symbol of the scheme.hint – The last line of the error.
type_arity – A function from the qualified name of a type constructor to its declared arity, or None;
normalize()uses it to foldApply.
- Returns:
A
Defaulting.- Raises:
DefaultingError – A constraint the table cannot handle.
- curry.typecheck.defaulting.normalize(typeexpr, type_arity=None)[source]
Folds
Apply (T a1 .. an-1) anintoT a1 .. anwhere the head is a type constructor. A substitution can put a constructor at the head of anApply:return 5has the typem aand the table bindsmtoIO, so the type isIO Int, notApply IO Int. Withtype_arity, a function from the qualified name of a constructor to its declared arity, an application that would exceed the arity stays anApply; without it every such application is folded.