Zulip Chat Archive

Stream: mathlib4

Topic: CoeTC typeclass


Oliver Nash (Mar 06 2023 at 10:04):

I am still building up my understanding of coercions in Lean 4. Looking at the source in core here I note that the guidance is not to use CoeTC directly. However if I search Mathlib4 for instances I find lots. Even this basic search shows we have many.

Oliver Nash (Mar 06 2023 at 10:05):

Can someone who understands this properly comment on this? In particular is it correct that we have these instances. See also this comment for my motivation.

Anne Baanen (Mar 06 2023 at 10:11):

I suspect it's caused by #align has_coe_t CoeTC here. docs#has_coe_t and docs4#CoeTC do behave the same in terms of composition of docs#has_coe / docs4#Coe so it makes some level of sense that the automated port matches them.

Anne Baanen (Mar 06 2023 at 10:13):

As for manual porting, I believe it's best to replace new instances of CoeTC with docs4#CoeTail, which should have the same semantics as the Lean 3 usages of has_coe_t.

Oliver Nash (Mar 06 2023 at 10:27):

I see, so these CoeTC instances in Mathlib4 are generated by mathport when it sees has_coe_t instances in Mathlib3. (Indeed looking here I confirmed this is the case for the one that I encountered.) But you're saying that it might be better if instead mathport generated instances of CoeTail?

Anne Baanen (Mar 06 2023 at 10:46):

I'm not sure if that is possible because we don't want to have instances like docs#coe_trans returning a CoeTail. Although the exceptions to aligning has_coe_t to CoeTail should be easily enumerable, and in fact probably consist of the set { docs#coe_base, docs#coe_trans }

Oliver Nash (Mar 06 2023 at 10:56):

OK thanks. Perhaps there is some small improvement to be made but it doesn't seem like a priority.

Oliver Nash (Mar 06 2023 at 10:56):

I'm grateful for the explanations.


Last updated: Dec 20 2023 at 11:08 UTC