[Haskell-cafe] Explicitly passing an argument to an arrow

Brent Yorgey byorgey at seas.upenn.edu
Wed Oct 3 12:55:34 CEST 2012


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



More information about the Haskell-Cafe mailing list