Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quick question about Arrow operators

Tags:

haskell

arrows

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.

like image 256
rampion Avatar asked Mar 04 '11 23:03

rampion


People also ask

What is arrow operator used for?

An Arrow operator in C/C++ allows to access elements in Structures and Unions. It is used with a pointer variable pointing to a structure or union.

What is the arrow operator called?

The (->) arrow operator The -> is called the arrow operator. It is formed by using the minus sign followed by a greater than sign. Simply saying: To access members of a structure, use the dot operator. To access members of a structure through a pointer, use the arrow operator.

Can an arrow function have a name?

Thus they created dynamically. We cannot name an arrow function as we do for the regular functions. However, if you'd like to call or reuse an arrow function, you will need to assign it to a variable. Arrow functions are always anonymous.

Does the arrow operator dereference?

Arrow Operator in C++ In C++ . is the standard member access operator. It has higher precedence than the * dereference operator. Accessing the member of an object through a pointer requires dereferencing to happen first, so the dereferencing operation must be wrapped in parentheses.


Video Answer


1 Answers

(***) :: (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.

like image 200
sclv Avatar answered Oct 21 '22 00:10

sclv