Explicitly passing an argument to an arrow

Hello everyone, sorry for the dumb question but I'm wrapping my head around arrow just from this morning. Consider this toy function to swap argument of a tuple: swapA' :: (Arrow a) => a ((b,c), (b,c)) (c,b) swapA' = swapFirst >>> swapSecond where swapFirst = first $ arr snd swapSecond = second $ arr fst It works but requires to pass a tuple of tuple, namely ((b,c), (b,c)). How can I explicitly pass my tuple of tuple to swapFirst so I can simply invoke swapA' (1,2) and get the correct result? ps. I know that swap can be easily and elegantly be written as: swap = snd &&& fst but the point of the exercise was to experiment with first, second and arrow concatenation Thanks in advance, Alfredo

On Wed, Oct 03, 2012 at 10:41:25AM +0200, Alfredo Di Napoli wrote:
Hello everyone,
sorry for the dumb question but I'm wrapping my head around arrow just from this morning. Consider this toy function to swap argument of a tuple:
swapA' :: (Arrow a) => a ((b,c), (b,c)) (c,b) swapA' = swapFirst >>> swapSecond where swapFirst = first $ arr snd swapSecond = second $ arr fst
It works but requires to pass a tuple of tuple, namely ((b,c), (b,c)). How can I explicitly pass my tuple of tuple to swapFirst so I can simply invoke
swapA' (1,2)
and get the correct result?
Like this? swapA' = dup >>> swapFirst >>> swapSecond where dup = id &&& id ... I'm afraid I'm not confident I really understand your question, however, so if that doesn't answer it, try asking again! -Brent

Thanks Brent, this should do the trick, although what I was asking was something more general: For "explicitly pass" I meant passing them without the eta reduce, in other terms: swapA' :: (Arrow a) => a ((b,c), (b,c)) (c,b) swapA' t = (????) swapFirst >>> swapSecond (???) where swapFirst = first $ arr snd swapSecond = second $ arr fst where the question marks indicate that I don't know how to tell swapFirst "hey, even though from the outside I'm passing you a tuple *t*, you have to take as input a (t,t)." Hope this is clearer or it has some sense at all, maybe I'm not getting correctly the way arrows work! bye, A. Like this?
swapA' = dup >>> swapFirst >>> swapSecond where dup = id &&& id ...
I'm afraid I'm not confident I really understand your question, however, so if that doesn't answer it, try asking again!
-Brent
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Alfredo Di Napoli
Thanks Brent, this should do the trick, although what I was asking was something more general:
For "explicitly pass" I meant passing them without the eta reduce, in other terms:
swapA' :: (Arrow a) => a ((b,c), (b,c)) (c,b) swapA' t = (????) swapFirst >>> swapSecond (???) where swapFirst = first $ arr snd swapSecond = second $ arr fst
where the question marks indicate that I don't know how to tell swapFirst "hey, even though from the outside I'm passing you a tuple *t*, you have to take as input a (t,t)."
Hope this is clearer or it has some sense at all, maybe I'm not getting correctly the way arrows work!
Perhaps arrow notation (Arrows extension) is what you want: swapA' :: (Arrow a) => a ((b, c), (b, c)) (c, b) swapA' = proc ((_, x), (y, _)) -> id -< (x, y) But I really don't understand why you're implementing this as an arrow computation. A simple function would do the trick, and should you really want to use it in an arrow you can just lift it by applying 'arr'. Greets, Ertugrul -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad.
participants (3)
-
Alfredo Di Napoli
-
Brent Yorgey
-
Ertugrul Söylemez