зеркало из
https://github.com/iharh/notes.git
synced 2025-10-29 20:56:06 +02:00
28 строки
778 B
Plaintext
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
|
|
|