- rep_pred = mkClassPred cls (initial_cls_inst_tys ++ [rep_ty])
- -- In our example, rep_pred is (Foo Int (Tree [a]))
- the_coercion = make_coercion cls_tycon initial_cls_inst_tys nt_tycon tc_args
- -- Coercion of kind (Foo Int (Tree [a]) ~ Foo Int (N a)
+ (rep_ty, wrapper)
+ = case coi of
+ IdCo -> (last_ty, idHsWrapper)
+ ACo co -> (snd (coercionKind co'), WpCast (mk_full_coercion co'))
+ where
+ co' = substTyWith inst_tvs (mkTyVarTys inst_tvs') co
+ -- NB: the free variable of coi are bound by the
+ -- universally quantified variables of the dfun_id
+ -- This is weird, and maybe we should make NewTypeDerived
+ -- carry a type-variable list too; but it works fine
+
+ -----------------------
+ -- mk_full_coercion
+ -- The inst_head looks like (C s1 .. sm (T a1 .. ak))
+ -- But we want the coercion (C s1 .. sm (sym (CoT a1 .. ak)))
+ -- with kind (C s1 .. sm (T a1 .. ak) ~ C s1 .. sm <rep_ty>)
+ -- where rep_ty is the (eta-reduced) type rep of T
+ -- So we just replace T with CoT, and insert a 'sym'
+ -- NB: we know that k will be >= arity of CoT, because the latter fully eta-reduced
+
+ mk_full_coercion co = mkTyConApp cls_tycon
+ (initial_cls_inst_tys ++ [mkSymCoercion co])
+ -- Full coercion : (Foo Int (Tree [a]) ~ Foo Int (N a)
+
+ rep_pred = mkClassPred cls (initial_cls_inst_tys ++ [rep_ty])
+ -- In our example, rep_pred is (Foo Int (Tree [a]))