-
Notifications
You must be signed in to change notification settings - Fork 49
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
Functoriality law is a free theorem #140
Comments
Or with GADTs. |
More wordly: The composition |
@phadej Can you show an example of a GADT that violates the law without relying on partiality and laziness? There is a long discussion on a similar topic here: https://stackoverflow.com/a/60384830, and I remain unconvinced that there is a way to break parametricity merely with the use of existential types. |
Yes, |
Sorry, I should asked the following right in the beginning: What is the issue? What one need to do to resolve it?
|
The issue is that the functoriality law is implied by the laws of functors and the type system, so in most situations it is not a law the user needs to worry about when writing an instance, as they do for the other laws. It would be good to distinguish this in the documentation, as is done for example in the documentation for the selective functor library: https://hackage.haskell.org/package/selective-0.4.1/docs/Control-Selective.html. Can you flesh out what you mean regarding |
If I were to guess I think you're pointing to the fact that The statement about parametricity that's relevant to the issue we're discussing is that for any two functors |
Please make a PR. |
Note: I include the naturality law, because in Haskell it (might be often / always is) true. But in more general setting it wouldn't. For |
That's what I'm talking about. If the |
There is no note that the latter composition I argue that there is really no benefit in omitting stating naturality laws. It might make sense to mention that you need to do suspicious things to break them, but they should be in the documentation. I still don't undestand what and how you try to improve. Please make a PR = concrete change proposal. |
The law labeled "functoriality" in the
Semialign
class is a free theorem.Here is the law as written:
Uncurry the arguments:
Eta reduce:
Explicitly write composite functors:
In other words, the law simply demands that
align :: Biff (,) f f a b -> Tannen f These a b
is a natural transformation between the bifunctorsBiff (,) f f
andTannen f These
.This is a free theorem: every parametrically polymorphic function of the type
foo :: forall a b. T a b -> U a b
, whereT
andU
are bifunctors, is a natural transformation between those bifunctors.Like any other free theorem, it can be violated by doing naughty stuff with partiality and laziness in Haskell, but if we ignore those pathological cases the law is inviolable.
The text was updated successfully, but these errors were encountered: