Zulip Chat Archive
Stream: general
Topic: Option mess
Yaël Dillies (Mar 04 2024 at 09:08):
We have docs#Option.elim, docs#Option.elim', docs#Option.casesOn' which are all basically the same function. My understanding of the naming convention around recursors was that
∀ o : Option α, motive none → (∀ a : α, motive (some a)) → motive o
isOption.rec
(correct :check:)motive none → (∀ a : α, motive (some a)) → ∀ o : Option α, motive o
isOption.recOn
(correct :check:)Option α → β → (α → β) → β
isOption.casesOn
(wrong :cross_mark:, currently it's calledOption.casesOn'
and alsoOption.elim
)β → (α → β) → Option α → β
isOption.elim
(wrong :cross_mark:, currently it's calledOption.elim'
)
Yaël Dillies (Mar 04 2024 at 09:10):
.. the general pattern being that
- the suffix
On
indicates that the inductive type argument comes first rec
indicates a dependent recursorelim
/cases
indicate a non-dependent recursor
Yaël Dillies (Mar 04 2024 at 09:11):
Is there any opposition to cleaning up the current mess? @Mario Carneiro, I will need your approval since docs#Option.elim is now in Std (but not the other two, somehow)
Yaël Dillies (Mar 04 2024 at 09:31):
Also, why is docs#Option.elim simp?
Mario Carneiro (Mar 04 2024 at 17:27):
As far as I know, T.elim
has always been used conventionally for the non-dependent version of T.recOn
. There is no T.elimOn
Eric Wieser (Mar 04 2024 at 17:28):
docs#Sum.elim and docs3#option.elim contradict that claim
Eric Wieser (Mar 04 2024 at 17:29):
docs#Option.elim matches docs#Sum.elim, so I think Option.elim'
should probably go (which is a porting artefact)
Mario Carneiro (Mar 04 2024 at 17:33):
No I think your first claim was correct and existing functions are inconsistent:
Option.elim
is nondependentOption.recOn
Option.elim'
is nondependentOption.rec
Sum.elim
is nondependentSum.rec
Mario Carneiro (Mar 04 2024 at 17:34):
Can someone do a census of all T.elim
functions?
Eric Wieser (Mar 04 2024 at 17:38):
My claim is that Sum.elim
is pretty heavily used as a definition for building vectors, where the argument order has to be this way around, and so must be the "right" one
Eric Wieser (Mar 04 2024 at 17:38):
Option.elim'
is what option.elim
got renamed to in the port
Eric Wieser (Mar 04 2024 at 17:39):
Mario Carneiro (Mar 04 2024 at 17:42):
The example with option.cons
from that thread shows that similar reasoning also applies to Option
Mario Carneiro (Mar 04 2024 at 17:43):
I definitely agree that when you want to partially apply the function putting the major premise last is always the right answer
Mario Carneiro (Mar 04 2024 at 17:43):
and moreover that nondependent eliminators are particularly good for partial application
Mario Carneiro (Mar 04 2024 at 17:44):
the main reason to want the major premise to come first is when using it as a poor-man's match
statement you want to specify the scrutinee before the branches
Mario Carneiro (Mar 04 2024 at 17:46):
You can avoid this issue when using dot-notation since in that case it doesn't matter, but if you want to specify the full name of the function or use @
then dot-notation is not available
Mario Carneiro (Mar 04 2024 at 17:47):
Using named arguments also allows you to manually reorder arguments (I do this so much for Array.foldl
, I want the init
argument first), but it means we should probably also be sure to name the major premise and name it consistently (currently neither Option.elim
nor Sum.elim
names the major premise)
Mario Carneiro (Mar 04 2024 at 17:49):
you also want to name the minor premises if you want it to be usable with induction
/cases
, although TBH I've never tried this with nondependent recursors and I'm not sure if it works
Yaël Dillies (Aug 19 2024 at 17:32):
I have now opened lean#5096
Last updated: May 02 2025 at 03:31 UTC