haskellarrow-abstraction

Quick question about Arrow operators


Say I've got f :: u -> v -> w and g :: x -> y -> z. What I want is h :: (u,x) -> (v,y) -> (w,z).

So I could go about this manually:

h (u,x) (v,y) = (f u v, g x y)

But where's the fun in that?

Using (***) I can get partway there:

(f *** g) :: (u,x) -> (v -> w, y -> z)

But I can't figure out how to get that final mile.


Solution

  • (***) :: (Arrow a) => a b c -> a b' c' -> a (b, b') (c, c')
    

    So specialize a to -> and we get:

    (***) :: (Arrow a) => (b -> c) -> (b' -> c') -> (b, b') -> (c, c')
    

    And that's great, except we want to, for whatever reason, take the first two arguments as a single pair instead. But that's easy, we just uncurry.

    Prelude Control.Arrow> :t uncurry (***)
    uncurry (***) :: (Arrow a) => (a b c, a b' c') -> a (b, b') (c, c')
    

    And if you specialize the a again, you should see the type signature you were looking for.