-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imap
requires that f.andThen(g) == identity
#4200
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, can we also be explicit: we require that f.andThen(g) == identity
.
imap
requires an isomorphismimap
requires that f.andThen(g) == identity
I would keep in mind that there are more lenient cases where Specifically on imap-on-semigroup-hom : {A B : Type} (x : Semigroup A) (f : A → B) (g : B → A)
→ (fSemigroupHom : ∀ {a b : A} → (imap f g x).combine (f a) (f b) ≡ f (x.combine a b))
→ (gSemigroupHom : ∀ {a b : B} → x.combine (g a) (g b) ≡ g ((imap f g x).combine a b))
→ ∀ {a b c : B} (imap f g x).combine ((imap f g x).combine a b) c ≡ (imap f g x).combine a ((imap f g x).combine b c)
imap-on-semigroup-hom =
f (x.combine (g (f (x.combine (g a) (g b)))) (g c)) ≡⟨ ap (λ l → f (x.combine l (g c))) (sym gSemigroupHom) ⟩
f (x.combine (x.combine (g a) (g b)) (g c)) ≡⟨ ap f x.combine-assoc ⟩
f (x.combine (g a) (x.combine (g b) (g c))) ≡⟨ ap (λ r → f (x.combine (g a) r)) gSemigroupHom ⟩
f (x.combine (g a) (g (f (x.combine (g b) (g c))))) ∎ |
Cats also has cats/core/src/main/scala/cats/Invariant.scala Line 125 in 5a3e175
I'm not sure what the minimum requirement on |
I would expect Monoid and Group Homomorphisms likewise. |
Actually, It is not true that |
Right, it's sort of a balancing act :) the question here is for Of course, if you know you are |
@@ -37,7 +37,7 @@ import scala.util.control.TailCalls.TailRec | |||
|
|||
/** | |||
* Transform an `F[A]` into an `F[B]` by providing a transformation from `A` | |||
* to `B` and one from `B` to `A`. | |||
* to `B` and its inverse from `B` to `A` i.e. `f.andThen(g) == identity`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmgimeno informs me that the category-theoretic term here is "retraction".
https://en.wikipedia.org/wiki/Section_(category_theory)
Any more thoughts on this one? :) |
The comment isn't correct as it is now. I bet there are some instances that require the I actually don't know if we know very much. I would like to see some tests that fail to help us learn more. E.g. we know we can make some of the tests fail with semigroup + poor choices. Are there are implementations of Invariant other than the algebra cases? |
Personally, my vote is for
Although, with (2), isn't the standard to put instances like that in alleycats? |
Absolutely, any
If we look at the instances of I stumbled on this question because I wanted to implement an
Do we have any lawful instances then, that don't also implement |
Relevant Twitter thread, h/t @s5bug |
(Archive) |
One possible fix for #4199. It seems that at least some of our implementations of
Invariant
have been relying on this precondition anyway, so this is a way forward without retracting those instances.