[m-dev.] for review: change typecheck.m to handle type class inference
David Glen JEFFERY
dgj at cs.mu.OZ.AU
Tue Mar 31 10:47:52 AEST 1998
On 30-Mar-1998, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Hi,
>
> DJ, can you please review this one?
>
> Estimated hours taken: 2
>
> compiler/typecheck.m:
> Get type inference working for type classes.
>
> tests/hard_coded/typeclasses/Mmakefile:
> tests/hard_coded/typeclasses/inference_test.m:
> tests/hard_coded/typeclasses/inference_test.exp:
> Add a simple test case for type class inference.
>
> Index: compiler/typecheck.m
> ===================================================================
> + % if the argument types and the type
> + % constraints are identical up to renaming,
> + % then nothing has changed
> + % (the call to same_length is just an
> + % optimization -- catch the easy cases first)
> + list__same_length(OldTypeConstraints,
> + InferredTypeConstraints),
> + same_structure(OldTypeConstraints,
> + InferredTypeConstraints,
> + ConstrainedTypes0, ConstrainedTypes),
> + list__append(ConstrainedTypes0, ArgTypes0,
> + TypesList0),
> + list__append(ConstrainedTypes, ArgTypes,
> + TypesList),
> + identical_up_to_renaming(TypesList0, TypesList)
Could you avoid these two appends by just calling identical_up_to_renaming
twice?
> +:- pred rename_class_constraint(map(tvar, tvar), class_constraint,
> + class_constraint).
> +:- mode rename_class_constraint(in, in, out) is det.
> +
> +% apply a type variable renaming to a class constraint
> +
> +rename_class_constraint(TSubst, constraint(ClassName, ArgTypes0),
> + constraint(ClassName, ArgTypes)) :-
> + term__apply_variable_renaming_to_list(ArgTypes0, TSubst, ArgTypes).
> +
> +:- pred rename_constraint_proof(map(tvar, tvar), constraint_proof,
> + constraint_proof).
> +:- mode rename_constraint_proof(in, in, out) is det.
> +
> +% apply a type variable renaming to a class constraint proof
> +
> +rename_constraint_proof(_TSubst, apply_instance(Instance, Num),
> + apply_instance(Instance, Num)).
> +rename_constraint_proof(TSubst, superclass(ClassConstraint0),
> + superclass(ClassConstraint)) :-
> + rename_class_constraint(TSubst, ClassConstraint0, ClassConstraint).
> +
These should go in type_util.m, next to apply_subst_to_constraint and its
cousins.
Apart from that, this diff looks fine. Thanks.
love and cuddles,
dgj
--
David Jeffery (dgj at cs.mu.oz.au) | Marge: Did you just call everyone "chicken"?
MEngSc student, | Homer: Noooo. I swear on this Bible!
Department of Computer Science | Marge: That's not a Bible; that's a book of
University of Melbourne | carpet samples!
Australia | Homer: Ooooh... Fuzzy.
More information about the developers
mailing list