-
Notifications
You must be signed in to change notification settings - Fork 42
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
Kind mismatch in derived instances #124
Comments
Fixes ekmett#124 Note that this does add a Functor requirement where none was required before
Hm, this is a tricky one. Before reviewing #125 too closely (thank you for submitting a patch, by the way!), I think it would be worth thinking about what the specification for While I haven't written up exactly how I intend
This criterion gives you a relatively simple way to tell what sort of code One drawback of this criterion is that despite being simple, it is not clever enough to come up with data Baz a b where
Baz :: a -> Baz a True
data Quux b c where
Quux :: Baz c x -> Quux b c
deriveBifunctor ''Quux When mapBaz :: (a -> a') -> Baz a b -> Baz a' b
mapBaz f (Baz x) = Baz (f x)
instance Bifunctor Quux where
bimap _ g (Quux x) = Quux (mapBaz g x) This works, but it requires much more cleverness that the criterion described above, as it requires knowledge about the definition of The question now is: does the change implemented in #125 rise to this level of cleverness? The example in #124 (comment) is rather similar to the example above, as This one feels right on the borderline of cleverness for me. I need to give this one some thought. |
I realized right after submitting my last comment that my argument isn't entirely consistent with how data T a b = MkT a b (M Int) (E Bool Char)
deriveBifunctor ''T Based on the criterion I mention in #124 (comment), you might expect the instance Bifunctor T where
bimap f g (MkT x1 x2 x3 x4) = MkT (f x1) (g x2) x3 x4 Because neither field mentions any of the type parameters, they do not get mapped at all. This is a very useful optimization, as we can avoid unnecessary allocations by avoiding redundant This is all to say: the algorithm that |
Fixes ekmett#124 Note that this does add a Functor requirement where none was required before
The derived instance shouldn't be using
bimap
here but rather justfmap
The text was updated successfully, but these errors were encountered: