sequenceA
is a well-known function:
sequenceA :: (Traversable t, Applicative f) => t (f a) -> f (t a)
I wonder whether we can write down something similar for Arrows. Unfortunately, I did not manage to implement the following:
sequenceArr :: (Traversable t, Arrow a) => t (a b c) -> a b (t c)
As far as I understand, Applicative
generalizes Arrow
, thus, we should be able to write this down. I did it for lists:
sequenceArrLst :: Arrow a => [a b c] -> a b [c]
sequenceArrLst t = let t' = (>>> arr (: [])) <$> t
in foldr1 (\f g -> f &&& g >>> arr (uncurry (++))) t'
Yet as one can notice, we are not getting rid of the a b
layer in the list but wrapping the results into a new list. So, how can we actually get rid of the a b
layer? I should note that in the comments under this question, duplode pointed out:
...between
(.)
,id
,arr
andfirst
, there isn't anything that allows collapsing twoa r
layers into one.
If they are right, would we need ArrowApply
for this? Frankly, I wrote this down, still not being able to get rid of the arrow inside t
:
sequenceArrApp :: (Functor f, ArrowApply a) => f (a b c) -> a b (f (a () c))
sequenceArrApp t = arr $ \ b -> (\ f -> arr (\ () -> (f, b)) >>> app) <$> t
Could this snippet be tweaked to lack the a ()
layer?
So, my questions are:
sequenceArr :: (Traversable t, Arrow a) => t (a b c) -> a b (t c)
- can we write this down? If so, how?- Are there any ways to get rid of the
a b
layer (Arrow a
). If so, why do they not work when we writejoin
forArrow
down (if they actually do not)? - Do we need
ArrowApply
for this? If so, how? Could my variant be tweaked to get this result:sequenceArr :: (Traversable t, ArrowApply a) => t (a b c) -> a b (t c)
?
traverseArr :: (Arrow a, Traversable t) => a x y -> a (t x) (t y)
? I think that would be a reasonable thing to try to get (whether possible or not, I don't know off the top of my head), but you haven't asked it directly. – dfeuerTraversing
class suggests thattraverseArr
likely isn't available for arbitrary arrows. – dfeuerTraversing
class as I have never heard of it before - thank you. What if we speak not an arbitrary arrow, but anArrowApply
instance? As far as I can remember,sequence
s used to be fed lists only not so long ago, yet they got generalized. All I am trying to do is to keep up :). – Zhiltsoff IgorsequenceArr
likely is possible, with some hackery. See my implementation oftraverseBia
for inspiration. Something like the sneakyMag
Applicative
might prove necessary. – dfeuersequenceArr
you propose at first what you get by specilaisingsequenceA
to the applicatives we can squeeze out of arrows? Or, in terms ofWrappedArrow
,unwrapArrow . sequenceA . fmap WrapArrow
? – duplode