In particular, I would like to see concepts like Indexed
included into base
(and ditto Biindexed
for Bifunctor
).
Several commonly-used modules have functions specific to their data structures, such as Map.mapWithKey
and Vector.imap
, and there exists a disparate set of classes in lens
, indexed-traversable
, keys
, mono-traversable-keys
, but they are un-unified, which can be an impediment to their use. If brought into base
, their implementation and use could be made consistent for better integration (eg, the same reason for having Functor be a superclass of Bifunctor), instead of having a scattered set of unrelated modules.
I personally would like to see them implemented in the following manner:
type family Index (f :: * -> *) :: *
class Indexed f where
indexed :: f a -> f (Index f, a)
class (Indexed f, Functor f) => IndexedFunctor f where
imap :: (Index f -> a -> b) -> f a -> f b
class (Indexed f, Foldable f) => IndexedFoldable f where
ifoldMap :: (Monoid m) => (Index f -> a -> m) -> f a -> m
-- NOTE: Or just (Indexed t, Traversable t) => ...
class (IndexedFunctor t, IndexedFoldable t, Traversable t) => IndexedTraversable t where
itraverse :: (Applicative f) => (Index t -> a -> f b) -> t a -> f (t b)
I would also like to see the concepts from recursion-schemes
(and Fix
Free
and Cofree
) pulled into base
as well - I have less justification for this other than that recursion is a really important concept, and I am always annoyed when I remember that they aren’t already in base and so I am forever pulling them in.
However, I also see recursion as an accompaniment to the whole Category, Monoid, Monad
triplet, for reasons that take a bit more explaining so I’ll just gesticulate wildly at how deeply Turing-completeness and computational complexity are related to it in general, and wonder how it could possibly be missing from base
.
I’m biased, because I work with both of these a lot.
Edited to add more context, and then a tad more.