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