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
Add Foldable / Traversable instances for tuples #206
Comments
Although I appreciate the push for greater consistency I am very skeptical about this. The proposed |
I wonder what the potential breakage from removing tuple instances of |
There is nothing wrong with Similarly one can argue that Removing --- a/libraries/base/Data/Traversable.hs
+++ b/libraries/base/Data/Traversable.hs
@@ -314,8 +314,8 @@ instance Traversable (Either a) where
deriving instance Traversable Solo
-- | @since 4.7.0.0
-instance Traversable ((,) a) where
- traverse f (x, y) = (,) x <$> f y
+-- instance Traversable ((,) a) where
+-- traverse f (x, y) = (,) x <$> f y
-- | @since 2.01
instance Ix i => Traversable (Array i) where results in failure to compile GHC:
I actually was expecting the newtype WriterT w m a = WriterT { runWriterT :: m (a, w) }
instance (Traversable f) => Traversable (WriterT w f) where
traverse f = fmap WriterT . traverse f' . runWriterT where
f' (a, b) = fmap (\ c -> (c, b)) (f a) -- strict first @(,) f so they inline |
|
Hello there. I'm working on codebase with high usage of high order functions that do something with monad M. These helpers change some environment for inner computation, catch errors and perform other complicated actions. A lot of them use tuples to return some additional stuff, so they may have such types:
I didn't see more than 3 return values, however I can't say they can't be found in the future. I had to write a wrapper monad under M, let's say
I need to use This helper should treat state carefully and perform some steps to fill
edit: I started to use my helper function in the codebase, and, after hard work, I updated all the subsystem of my interest to my new monad. Updated and found that
Thanks to everyone who participated in the discussion 🙏. |
I guess you mean
I'm not sure if you're saying you're stuck, but if so I see two possible ways to proceed:
|
I understand that there are low-tech workarounds, that doesn't allow me to use one function in all cases, however I want to give you a motivational example about what may happen in the wild. I've never had no desire to use |
Okay. Once again, I think that if users need |
@tomjaguarpaw could you possibly unpack this argument? What's exactly confusing? As we discussed at https://discourse.haskell.org/t/in-retrospect-was-burning-bridges-a-mistake/8188/46, it's not like |
I mean that
But sadly all three do pertain. Let's not make things worse by allowing I disagree that (I agree that |
What about |
There's a difference of degree. |
(This was originially submitted by @Topsii as a part of #93 / !9489, but I think it's worth its own discussion)
At the moment we have
instance Functor (x,y,)
,instance Bifunctor (x,,)
,instance Bifoldable (x,,)
andinstance Bitraversable (x,,)
, but neitherinstance Foldable (x,y,)
norinstance Traversable (x,y,)
. This is extremely inconsistent. Thus the proposal is to add them, and similar for all tuples up to 7 elements.(7 is not an arbitrary number, Haskell Report suggests that standard functions should be implemented for tuples up to 7 elements)
The text was updated successfully, but these errors were encountered: