Fix some bugs in the handling of "non-simple" type class constraints

Estimated hours taken: 12

Fix some bugs in the handling of "non-simple" type class constraints
(ones for which the types being constrained are not just type variables).

compiler/prog_io_typeclass.m:
	Ensure that constraints on type class declarations must be "simple".
	This is needed the ensure termination of type checking.
	(We already did this for instance declarations, but not for
	superclass constraints on type class declarations.)

compiler/prog_data.m:
	Document the invariant that the types in a type class constraint
	must not contain any information in their term__context fields.

compiler/type_util.m:
compiler/equiv_type.m:
compiler/polymorphism.m:
compiler/prog_io_typeclass.m:
	Enforce the above-mentioned invariant.

compiler/typecheck.m:
	Allow the declared constraints to be a superset of the
	inferred constraints.
	When performing context reduction, eliminate declared
	constraints at each step rather than only at the end.
	Remove declared constraints and apply superclass rules
	before applying instance rules.
	When applying instance rules, make sure that it is a type
	error if there is no matching instance rule for a ground
	constraint.
	If context reduction results in an error, restore the
	original type assign set, to avoid repeating the same
	error message at every subsequent call to perform_context_reduction.

compiler/check_typeclass.m:
	Change the way we superclass conformance for instance declarations
	to take advantage of the new "DeclaredConstraints" argument to
	typecheck__reduce_context_by_rule_application.
This commit is contained in:
Fergus Henderson
1998-04-08 15:23:35 +00:00
parent b09da35e8e
commit 5e86fb5715
7 changed files with 237 additions and 125 deletions

View File

@@ -223,7 +223,19 @@
; share
; automatic.
:- type class_constraint ---> constraint(class_name, list(type)).
% A class constraint represents a constraint that a given
% list of types is a member of the specified type class.
% It is an invariant of this data structure that
% the types in a class constraint do not contain any
% information in their term__context fields.
% This invariant is needed to ensure that we can do
% unifications, map__lookups, etc., and get the
% expected semantics.
% Any code that creates new class constraints must
% ensure that this invariant is preserved,
% probably by using strip_term_contexts/2 in type_util.m.
:- type class_constraint
---> constraint(class_name, list(type)).
:- type class_name == sym_name.