notes/pl/hs/haskell-fun-pairs-curry.txt
Ihar Hancharenka 5dff80e88e first
2023-03-27 16:52:17 +03:00

28 строки
778 B
Plaintext

1. fst, snd, swap
-- | Extract the first component of a pair.
fst :: (a,b) -> a
fst (x,_) = x
-- | Extract the second component of a pair.
snd :: (a,b) -> b
snd (_,y) = y
-- | Swap the components of a pair.
swap :: (a,b) -> (b,a)
swap (a,b) = (b,a)
2. curry, uncurry
-- | 'curry' converts an uncurried function to a curried function.
curry :: ((a, b) -> c) -> a -> b -> c
curry f x y = f (x, y)
-- | 'uncurry' converts a curried function to a function on pairs.
uncurry :: (a -> b -> c) -> ((a, b) -> c)
uncurry f p = f (fst p) (snd p)
3. Uncurry
http://ro-che.info//articles/2013-01-29-generic-uncurry.html