Update base for latest Safe Haskell.
[packages/base.git] / Data / Tuple.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE CPP, NoImplicitPrelude #-}
3 {-# OPTIONS_GHC -fno-warn-unused-imports #-}
4 -- XXX -fno-warn-unused-imports needed for the GHC.Tuple import below. Sigh.
5
6 -----------------------------------------------------------------------------
7 -- |
8 -- Module : Data.Tuple
9 -- Copyright : (c) The University of Glasgow 2001
10 -- License : BSD-style (see the file libraries/base/LICENSE)
11 --
12 -- Maintainer : libraries@haskell.org
13 -- Stability : experimental
14 -- Portability : portable
15 --
16 -- The tuple data types, and associated functions.
17 --
18 -----------------------------------------------------------------------------
19
20 module Data.Tuple
21 ( fst -- :: (a,b) -> a
22 , snd -- :: (a,b) -> a
23 , curry -- :: ((a, b) -> c) -> a -> b -> c
24 , uncurry -- :: (a -> b -> c) -> ((a, b) -> c)
25 , swap -- :: (a,b) -> (b,a)
26 #ifdef __NHC__
27 , (,)(..)
28 , (,,)(..)
29 , (,,,)(..)
30 , (,,,,)(..)
31 , (,,,,,)(..)
32 , (,,,,,,)(..)
33 , (,,,,,,,)(..)
34 , (,,,,,,,,)(..)
35 , (,,,,,,,,,)(..)
36 , (,,,,,,,,,,)(..)
37 , (,,,,,,,,,,,)(..)
38 , (,,,,,,,,,,,,)(..)
39 , (,,,,,,,,,,,,,)(..)
40 , (,,,,,,,,,,,,,,)(..)
41 #endif
42 )
43 where
44
45 #ifdef __GLASGOW_HASKELL__
46
47 import GHC.Base
48 -- We need to depend on GHC.Base so that
49 -- a) so that we get GHC.Classes, GHC.Types
50
51 -- b) so that GHC.Base.inline is available, which is used
52 -- when expanding instance declarations
53
54 import GHC.Tuple
55 -- We must import GHC.Tuple, to ensure sure that the
56 -- data constructors of `(,)' are in scope when we do
57 -- the standalone deriving instance for Eq (a,b) etc
58
59 #endif /* __GLASGOW_HASKELL__ */
60
61 #ifdef __NHC__
62 import Prelude
63 import Prelude
64 ( (,)(..)
65 , (,,)(..)
66 , (,,,)(..)
67 , (,,,,)(..)
68 , (,,,,,)(..)
69 , (,,,,,,)(..)
70 , (,,,,,,,)(..)
71 , (,,,,,,,,)(..)
72 , (,,,,,,,,,)(..)
73 , (,,,,,,,,,,)(..)
74 , (,,,,,,,,,,,)(..)
75 , (,,,,,,,,,,,,)(..)
76 , (,,,,,,,,,,,,,)(..)
77 , (,,,,,,,,,,,,,,)(..)
78 -- nhc98's prelude only supplies tuple instances up to size 15
79 , fst, snd
80 , curry, uncurry
81 )
82 #endif
83
84 default () -- Double isn't available yet
85
86 -- ---------------------------------------------------------------------------
87 -- Standard functions over tuples
88
89 #if !defined(__HUGS__) && !defined(__NHC__)
90 -- | Extract the first component of a pair.
91 fst :: (a,b) -> a
92 fst (x,_) = x
93
94 -- | Extract the second component of a pair.
95 snd :: (a,b) -> b
96 snd (_,y) = y
97
98 -- | 'curry' converts an uncurried function to a curried function.
99 curry :: ((a, b) -> c) -> a -> b -> c
100 curry f x y = f (x, y)
101
102 -- | 'uncurry' converts a curried function to a function on pairs.
103 uncurry :: (a -> b -> c) -> ((a, b) -> c)
104 uncurry f p = f (fst p) (snd p)
105 #endif /* neither __HUGS__ nor __NHC__ */
106
107 -- | Swap the components of a pair.
108 swap :: (a,b) -> (b,a)
109 swap (a,b) = (b,a)