Fix warnings
[ghc-base.git] / Data / Tuple.hs
1 {-# OPTIONS_GHC -XNoImplicitPrelude #-}
2 {-# OPTIONS_GHC -fno-warn-unused-imports #-}
3 -- XXX -fno-warn-unused-imports needed for the GHC.Tuple import below. Sigh.
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 -- The tuple data types, and associated functions.
15 --
16 -----------------------------------------------------------------------------
17
18 module Data.Tuple
19   ( fst         -- :: (a,b) -> a
20   , snd         -- :: (a,b) -> a
21   , curry       -- :: ((a, b) -> c) -> a -> b -> c
22   , uncurry     -- :: (a -> b -> c) -> ((a, b) -> c)
23 #ifdef __NHC__
24   , (,)(..)
25   , (,,)(..)
26   , (,,,)(..)
27   , (,,,,)(..)
28   , (,,,,,)(..)
29   , (,,,,,,)(..)
30   , (,,,,,,,)(..)
31   , (,,,,,,,,)(..)
32   , (,,,,,,,,,)(..)
33   , (,,,,,,,,,,)(..)
34   , (,,,,,,,,,,,)(..)
35   , (,,,,,,,,,,,,)(..)
36   , (,,,,,,,,,,,,,)(..)
37   , (,,,,,,,,,,,,,,)(..)
38 #endif
39   )
40     where
41
42 #ifdef __GLASGOW_HASKELL__
43 import GHC.Base
44 -- XXX The standalone deriving clauses fail with
45 --     The data constructors of `(,)' are not all in scope
46 --       so you cannot derive an instance for it
47 --     In the stand-alone deriving instance for `Eq (a, b)'
48 -- if we don't import GHC.Tuple
49 import GHC.Tuple
50 #endif  /* __GLASGOW_HASKELL__ */
51
52 #ifdef __NHC__
53 import Prelude
54 import Prelude
55   ( (,)(..)
56   , (,,)(..)
57   , (,,,)(..)
58   , (,,,,)(..)
59   , (,,,,,)(..)
60   , (,,,,,,)(..)
61   , (,,,,,,,)(..)
62   , (,,,,,,,,)(..)
63   , (,,,,,,,,,)(..)
64   , (,,,,,,,,,,)(..)
65   , (,,,,,,,,,,,)(..)
66   , (,,,,,,,,,,,,)(..)
67   , (,,,,,,,,,,,,,)(..)
68   , (,,,,,,,,,,,,,,)(..)
69   -- nhc98's prelude only supplies tuple instances up to size 15
70   , fst, snd
71   , curry, uncurry
72   )
73 #endif
74
75 default ()              -- Double isn't available yet
76
77 #ifdef __GLASGOW_HASKELL__
78 -- XXX Why aren't these derived?
79 instance Eq () where
80     () == () = True
81     () /= () = False
82
83 instance Ord () where
84     () <= () = True
85     () <  () = False
86     () >= () = True
87     () >  () = False
88     max () () = ()
89     min () () = ()
90     compare () () = EQ
91
92 #ifndef __HADDOCK__
93 deriving instance (Eq  a, Eq  b) => Eq  (a, b)
94 deriving instance (Ord a, Ord b) => Ord (a, b)
95 deriving instance (Eq  a, Eq  b, Eq  c) => Eq  (a, b, c)
96 deriving instance (Ord a, Ord b, Ord c) => Ord (a, b, c)
97 deriving instance (Eq  a, Eq  b, Eq  c, Eq  d) => Eq  (a, b, c, d)
98 deriving instance (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d)
99 deriving instance (Eq  a, Eq  b, Eq  c, Eq  d, Eq  e) => Eq  (a, b, c, d, e)
100 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e)
101 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f)
102                => Eq (a, b, c, d, e, f)
103 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f)
104                => Ord (a, b, c, d, e, f)
105 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g)
106                => Eq (a, b, c, d, e, f, g)
107 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g)
108                => Ord (a, b, c, d, e, f, g)
109 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
110                    Eq h)
111                => Eq (a, b, c, d, e, f, g, h)
112 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
113                    Ord h)
114                => Ord (a, b, c, d, e, f, g, h)
115 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
116                    Eq h, Eq i)
117                => Eq (a, b, c, d, e, f, g, h, i)
118 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
119                    Ord h, Ord i)
120                => Ord (a, b, c, d, e, f, g, h, i)
121 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
122                    Eq h, Eq i, Eq j)
123                => Eq (a, b, c, d, e, f, g, h, i, j)
124 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
125                    Ord h, Ord i, Ord j)
126                => Ord (a, b, c, d, e, f, g, h, i, j)
127 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
128                    Eq h, Eq i, Eq j, Eq k)
129                => Eq (a, b, c, d, e, f, g, h, i, j, k)
130 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
131                    Ord h, Ord i, Ord j, Ord k)
132                => Ord (a, b, c, d, e, f, g, h, i, j, k)
133 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
134                    Eq h, Eq i, Eq j, Eq k, Eq l)
135                => Eq (a, b, c, d, e, f, g, h, i, j, k, l)
136 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
137                    Ord h, Ord i, Ord j, Ord k, Ord l)
138                => Ord (a, b, c, d, e, f, g, h, i, j, k, l)
139 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
140                    Eq h, Eq i, Eq j, Eq k, Eq l, Eq m)
141                => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m)
142 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
143                    Ord h, Ord i, Ord j, Ord k, Ord l, Ord m)
144                => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m)
145 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
146                    Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n)
147                => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
148 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
149                    Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n)
150                => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
151 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
152                    Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o)
153                => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
154 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
155                    Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o)
156                => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
157 #endif  /* !__HADDOCK__ */
158 #endif  /* __GLASGOW_HASKELL__ */
159
160 -- ---------------------------------------------------------------------------
161 -- Standard functions over tuples
162
163 #if !defined(__HUGS__) && !defined(__NHC__)
164 -- | Extract the first component of a pair.
165 fst                     :: (a,b) -> a
166 fst (x,_)               =  x
167
168 -- | Extract the second component of a pair.
169 snd                     :: (a,b) -> b
170 snd (_,y)               =  y
171
172 -- | 'curry' converts an uncurried function to a curried function.
173 curry                   :: ((a, b) -> c) -> a -> b -> c
174 curry f x y             =  f (x, y)
175
176 -- | 'uncurry' converts a curried function to a function on pairs.
177 uncurry                 :: (a -> b -> c) -> ((a, b) -> c)
178 uncurry f p             =  f (fst p) (snd p)
179 #endif  /* neither __HUGS__ nor __NHC__ */