
Does anybody know if there are any functions like these in the Haskell libray? updateSnd f (x,y) -> (x, f y) updateFst f (x,y) -> (f x, y) Thanks, ovidiu

first ofc also being known as fmap. Bob if (*ra4 != 0xffc78948) { return false; } On 9 Mar 2012, at 19:09, Brent Yorgey wrote:
On Fri, Mar 09, 2012 at 09:07:24PM +0200, Ovidiu Deac wrote:
Does anybody know if there are any functions like these in the Haskell libray?
updateSnd f (x,y) -> (x, f y)
updateFst f (x,y) -> (f x, y)
Yes: 'first' and 'second' from Control.Arrow.
-Brent
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

@Bert first& second are exactly what I was looking for. Thanks. @Thomas: I'm not sure what you mean by fmap What I wanted is to do this:
let f = map $ first (*2) f [(1,1),(2,2),(3,3),(4,4)] [(2,1),(4,2),(6,3),(8,4)]
On Fri, Mar 9, 2012 at 9:23 PM, Thomas Davie
first ofc also being known as fmap.
Bob
if (*ra4 != 0xffc78948) { return false; }
On 9 Mar 2012, at 19:09, Brent Yorgey wrote:
On Fri, Mar 09, 2012 at 09:07:24PM +0200, Ovidiu Deac wrote:
Does anybody know if there are any functions like these in the Haskell
libray?
updateSnd f (x,y) -> (x, f y)
updateFst f (x,y) -> (f x, y)
Yes: 'first' and 'second' from Control.Arrow.
-Brent
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Actually it's second that is fmap. Prelude> :m +Control.Monad.Instances Control.Arrow Prelude Control.Monad.Instances Control.Arrow> fmap (*2) (1,3) (1,6) Prelude Control.Monad.Instances Control.Arrow> second (*2) (1,3) (1,6) -Brent On Fri, Mar 09, 2012 at 07:23:50PM +0000, Thomas Davie wrote:
first ofc also being known as fmap.
Bob if (*ra4 != 0xffc78948) { return false; }
On 9 Mar 2012, at 19:09, Brent Yorgey wrote:
On Fri, Mar 09, 2012 at 09:07:24PM +0200, Ovidiu Deac wrote:
Does anybody know if there are any functions like these in the Haskell libray?
updateSnd f (x,y) -> (x, f y)
updateFst f (x,y) -> (f x, y)
Yes: 'first' and 'second' from Control.Arrow.
-Brent
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Ovidiu Deac
Does anybody know if there are any functions like these in the Haskell libray?
updateSnd f (x,y) -> (x, f y)
updateFst f (x,y) -> (f x, y)
While the function arrow mentioned by Brent is enough for many purposes, I just want to have mentioned Edward Kmett's amazing data-lens library, which provides prefab lenses for tuples: (3, 5) ^. fstLens = 3 (3, 5) ^. sndLens = 5 (fstLens ^= 4) (3, 5) = (4, 5) (sndLens ^= 4) (3, 5) = (3, 4) (fstLens ^%= f) (3, 5) = (f 3, 5) This is especially useful when your tuple is part of the implicit argument of a state monad (data-lens-fd package): access fstLens :: State (a, b) a -- starting state (3, 5) fstLens ~= 10 -- (10, 5) fstLens += 1 -- (11, 5) fstLens %= negate -- (-11, 5) focus fstLens $ do -- Do something with only the fst value here. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/
participants (4)
-
Brent Yorgey
-
Ertugrul Söylemez
-
Ovidiu Deac
-
Thomas Davie