-
Notifications
You must be signed in to change notification settings - Fork 41
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
Change order of Data.Bifunctor.Fix #61
Comments
@ekmett deliberately chose the current design, see #8 (comment). That being said, perhaps there's room for this incarnation as well (under a different name). |
I respect unifying the kind structure and I hope that given data family Fix :: (k -> *) -> k
data instance Fix f = In (f (Fix f))
data instance Fix f a = In1 (f (Fix f) a)
data instance Fix f a b = In2 (f (Fix f) a b) Maybe the underlying representation doesn't have to change, and we can inline instance Bifoldable p => Foldable (Fix p) where
foldMap f (In p) = getDual (bifoldMap (Dual . foldMap f) (Dual . f) p)
instance Bitraversable p => Traversable (Fix p) where
traverse :: Applicative f => (a -> f a') -> (Fix p a -> f (Fix p a'))
traverse f (In p) = In <$> forwards (bitraverse (Backwards . traverse f) (Backwards . f) p)
instance Biapplicative p => Applicative (Fix p) where
pure a = In (bipure (pure a) a)
In p <*> In q = In (biliftA2 (<**>) (&) q p) This restores the correct ordering >>> traverse (\a -> Const [a]) (1:::2:::3:::4:::Nil)
Const [1,2,3,4]
>>> toList (1:::2:::3:::4:::Nil)
[1,2,3,4] |
( |
Great! FWIW, I doubt we are going to be seeing any return-kind-polymorphic data families put into this package any time soon due to |
I don't generally have a particular problem with enabling new features conditional on the new version, and providing definitions that just don't get exposed on old compilers. |
In any case, I'm not sure what exactly is being proposed here anymore. There seem to be any number of possible changes that @Icelandjack is hinting at:
@Icelandjack, do one of those points accurately characterize what you're proposing? |
Sure. It's just a general principle. The best way to apply it here has to be hammered out. It may not belong here in bifunctors simply because bifunctor isn't the base case. |
The order of
Fix
is unfortunate, it means that given a standard base functorwe get an unexpected order of elements
I had the same problems with defining
newtype ZipList a = ZL (Fix (Tannen Maybe (,))
from #57 where I need to wrap it inReverse
to get theFoldable
I want.if it were the other way round like The Essence of the Iterator Pattern
we would get the right ordering and the argument of
fold
fits the shape of an algebraThe text was updated successfully, but these errors were encountered: