Zulip Chat Archive
Stream: Is there code for X?
Topic: Functoriality of finset
Yaël Dillies (Dec 22 2021 at 14:37):
For #10955, I need the fact that finset
is docs#alternative. It seems like the only ingredients we have in that direction are docs#finset.is_lawful_functor and file#src/data/multiset/functor.lean. Am I right?
Eric Wieser (Dec 22 2021 at 14:47):
I'm thinking this might end up being noncomputable, because the obvious choice for or_else
is insert
(using the list version for reference) and that requires decidability, for which there's no way to accept a decidable
instance
Eric Wieser (Dec 22 2021 at 14:48):
That is: probably worth having anyway, but not necessarily worth using in your PR
Yaël Dillies (Dec 22 2021 at 14:52):
That's what I'm thinking too. It will be noncomputable for sure. Similarly, #2997 provides a computable |equiv_functor.map instead of the noncomputable one coming from finset.is_lawful_functor
Eric Wieser (Dec 22 2021 at 14:55):
Given that one of the main uses of the monadic stuff seems to be for actually writing executable meta code, it seems awfully unfortunate that the typeclass design doesn't allow a computable instance here
Anne Baanen (Dec 22 2021 at 14:57):
Indeed, it would be an amazing function if we could somehow restrict the quantification of classes. Here, we have that finset
is (computably) applicative, but only if there's decidable_eq
on the parameter to finset
. Similarly, I would love to just write instance : monoid_hom_class ring_hom
but this only holds under the assumption that the domain and codomain are rings. And I think a lot of the category theory library could do without bundling.
Eric Wieser (Dec 22 2021 at 15:16):
One way to fix this monadic stuff (both in terms of extra assumptions, and in terms of universe polymorphism) might be to change the classes to:
class functor' (α β : out_param Type*) (fα fβ : Type*) :=
(map : (α → β) → fα → fβ)
(map_const : β → fα → fβ := map ∘ function.const α)
instance {α β : Type*} : functor' α β (list α) (list β) :=
{ map := list.map }
It wasn't immediately obvious whether this would work for the full heirarchy of classes
Eric Wieser (Dec 22 2021 at 15:19):
Or even using out_param
to avoid some verbosity:
-- this name is lousy!
class is_monadic (α : out_param Type*) (fα : Type*) : Prop
instance {α : Type*} : is_monadic α (list α) := is_monadic.mk
class functor' {α β : out_param Type*} (fα fβ : Type*) [is_monadic α fα] [is_monadic β fβ] :=
(map : (α → β) → fα → fβ)
(map_const : β → fα → fβ := map ∘ function.const α)
instance {α β : Type*} : functor' (list α) (list β) :=
{ map := list.map }
Anne Baanen (Dec 22 2021 at 15:21):
Hmm, is_monadic
reminds me of implementing docs#category_theory.bundled but in the class-sublanguage
Eric Wieser (Dec 22 2021 at 15:54):
I explored this a little more in branch#eric-wieser/monad-universes, all the way up to applicative
Yaël Dillies (Dec 22 2021 at 16:09):
Just for reference, I have now proved is_lawful_applicative finset
.
Yaël Dillies (Dec 22 2021 at 16:09):
Attacking is_lawful_alternative finset
now.
Yaël Dillies (Dec 22 2021 at 16:10):
However, I have no clue about traverse
and stuff. What should the definition of traverse
be?
Eric Wieser (Dec 22 2021 at 16:12):
docs#traverse? docs#traversable?
Anne Baanen (Dec 22 2021 at 16:13):
Yaël Dillies (Dec 22 2021 at 16:13):
Sorry what! When did this linkification come into existence?
Yaël Dillies (Dec 22 2021 at 16:13):
Both, Eric
Anne Baanen (Dec 22 2021 at 16:14):
Yaël Dillies said:
Sorry what! When did this linkification come into existence?
This linkification actually uses a highly-trained neural network (i.e. me)
Eric Wieser (Dec 22 2021 at 16:16):
Probably not both since the first doesn't exist!
Eric Wieser (Dec 22 2021 at 16:16):
docs#list.traverse might help
Yaël Dillies (Dec 22 2021 at 16:16):
I mean traversable.traverse
!
Yaël Dillies (Dec 22 2021 at 16:16):
Yaël Dillies (Dec 22 2021 at 16:17):
The traverse
that goes in the traversable
instance.
Yaël Dillies (Dec 22 2021 at 17:57):
alternative
done. Doing is_comm_applicative
. However, is there no is_lawful_alternative
?
Eric Wieser (Dec 23 2021 at 22:35):
(I moved the discussion about changing the functor typeclasses to #general)
Last updated: Dec 20 2023 at 11:08 UTC