Test proxy-polymorphic sameNat and sameSymbol
[ghc.git] / libraries / base / Data / Tuple.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE NoImplicitPrelude #-}
3
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module : Data.Tuple
7 -- Copyright : (c) The University of Glasgow 2001
8 -- License : BSD-style (see the file libraries/base/LICENSE)
9 --
10 -- Maintainer : libraries@haskell.org
11 -- Stability : experimental
12 -- Portability : portable
13 --
14 -- Functions associated with the tuple data types.
15 --
16 -----------------------------------------------------------------------------
17
18 module Data.Tuple
19 ( fst
20 , snd
21 , curry
22 , uncurry
23 , swap
24 ) where
25
26 import GHC.Base () -- Note [Depend on GHC.Tuple]
27
28 default () -- Double isn't available yet
29
30 -- ---------------------------------------------------------------------------
31 -- Standard functions over tuples
32
33 -- | Extract the first component of a pair.
34 fst :: (a,b) -> a
35 fst (x,_) = x
36
37 -- | Extract the second component of a pair.
38 snd :: (a,b) -> b
39 snd (_,y) = y
40
41 -- | 'curry' converts an uncurried function to a curried function.
42 --
43 -- ==== __Examples__
44 --
45 -- >>> curry fst 1 2
46 -- 1
47 curry :: ((a, b) -> c) -> a -> b -> c
48 curry f x y = f (x, y)
49
50 -- | 'uncurry' converts a curried function to a function on pairs.
51 --
52 -- ==== __Examples__
53 --
54 -- >>> uncurry (+) (1,2)
55 -- 3
56 --
57 -- >>> uncurry ($) (show, 1)
58 -- "1"
59 --
60 -- >>> map (uncurry max) [(1,2), (3,4), (6,8)]
61 -- [2,4,8]
62 uncurry :: (a -> b -> c) -> ((a, b) -> c)
63 uncurry f p = f (fst p) (snd p)
64
65 -- | Swap the components of a pair.
66 swap :: (a,b) -> (b,a)
67 swap (a,b) = (b,a)
68
69 -- $setup
70 -- >>> import Prelude hiding (curry, uncurry, fst, snd)