haskell - Employing arrows to fold a list of tuples -


sometimes want fold list of tuples 1 tuple using different folding functions. instance, in order glue list of runstate results, getting (in sense) combined state , combined result.

consider following implementation:

wish :: (a -> a' -> a) -> (b -> b' -> b) -> (a,b) -> [(a', b')] -> (a,b) wish lfn rfn x xs = foldl (\(a,b) -> (lfn a) *** (rfn b)) x xs 

although works, feel uncomfortable lambda. lfn *** rfn has type of (a,b) -> (a -> a', b -> b'), can't find way apply tuple without ever resorting pattern matching. there clear , elegant way i'm missing? library function of type (a,a') -> (a -> a, a' -> a') -> (a, a') or whole different approach, maybe.

control.arrow not pay attention higher-arity functions. want function foo :: (a -> a' -> a'') -> (b -> b' -> b'') -> (a,b) -> (a',b') -> (a'',b''), analogue of (***) functions of arity 2. there such function in data.biapplicative (from package bifunctor), has more general signature bilifta2 :: biapplicative w => (a -> b -> c) -> (d -> e -> f) -> w d -> w b e -> w c f. since there biapplicative instance two-element tuples, need.

the complaint can see against code stands currying of lambda non-obvious; might prefer more explicit \(a,b) (a',b') -> (lfn a', rfn b b').

edit notes: had concluded needed function did not exist, , suggested defining it; spurred carl's comment, found 1 in biapplicative (the more general type signature had prevented hoogle finding under suggested signature).


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -