Tidy up and comment imports
[ghc-base.git] / Data / Tuple.hs
1 {-# OPTIONS_GHC -XNoImplicitPrelude #-}
2 {-# OPTIONS_GHC -fno-warn-unused-imports #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 -- XXX -fno-warn-unused-imports needed for the GHC.Tuple import below. Sigh.
5 -----------------------------------------------------------------------------
6 -- |
7 -- Module      :  Data.Tuple
8 -- Copyright   :  (c) The University of Glasgow 2001
9 -- License     :  BSD-style (see the file libraries/base/LICENSE)
10 -- 
11 -- Maintainer  :  libraries@haskell.org
12 -- Stability   :  experimental
13 -- Portability :  portable
14 --
15 -- The tuple data types, and associated functions.
16 --
17 -----------------------------------------------------------------------------
18
19 module Data.Tuple
20   ( fst         -- :: (a,b) -> a
21   , snd         -- :: (a,b) -> a
22   , curry       -- :: ((a, b) -> c) -> a -> b -> c
23   , uncurry     -- :: (a -> b -> c) -> ((a, b) -> c)
24 #ifdef __NHC__
25   , (,)(..)
26   , (,,)(..)
27   , (,,,)(..)
28   , (,,,,)(..)
29   , (,,,,,)(..)
30   , (,,,,,,)(..)
31   , (,,,,,,,)(..)
32   , (,,,,,,,,)(..)
33   , (,,,,,,,,,)(..)
34   , (,,,,,,,,,,)(..)
35   , (,,,,,,,,,,,)(..)
36   , (,,,,,,,,,,,,)(..)
37   , (,,,,,,,,,,,,,)(..)
38   , (,,,,,,,,,,,,,,)(..)
39 #endif
40   )
41     where
42
43 #ifdef __GLASGOW_HASKELL__
44
45 import GHC.Base
46 -- We need to depend on GHC.Base so that
47 -- a) so that we get GHC.Bool, GHC.Classes, GHC.Ordering
48
49 -- b) so that GHC.Base.inline is available, which is used
50 --    when expanding instance declarations
51
52 import GHC.Tuple
53 -- We must import GHC.Tuple, to ensure sure that the 
54 -- data constructors of `(,)' are in scope when we do
55 -- the standalone deriving instance for Eq (a,b) etc
56
57 #endif  /* __GLASGOW_HASKELL__ */
58
59 #ifdef __NHC__
60 import Prelude
61 import Prelude
62   ( (,)(..)
63   , (,,)(..)
64   , (,,,)(..)
65   , (,,,,)(..)
66   , (,,,,,)(..)
67   , (,,,,,,)(..)
68   , (,,,,,,,)(..)
69   , (,,,,,,,,)(..)
70   , (,,,,,,,,,)(..)
71   , (,,,,,,,,,,)(..)
72   , (,,,,,,,,,,,)(..)
73   , (,,,,,,,,,,,,)(..)
74   , (,,,,,,,,,,,,,)(..)
75   , (,,,,,,,,,,,,,,)(..)
76   -- nhc98's prelude only supplies tuple instances up to size 15
77   , fst, snd
78   , curry, uncurry
79   )
80 #endif
81
82 #ifdef __GLASGOW_HASKELL__
83 import GHC.Unit ()
84 #endif
85
86 default ()              -- Double isn't available yet
87
88 #ifdef __GLASGOW_HASKELL__
89 -- XXX Why aren't these derived?
90 instance Eq () where
91     () == () = True
92     () /= () = False
93
94 instance Ord () where
95     () <= () = True
96     () <  () = False
97     () >= () = True
98     () >  () = False
99     max () () = ()
100     min () () = ()
101     compare () () = EQ
102
103 #ifndef __HADDOCK__
104 deriving instance (Eq  a, Eq  b) => Eq  (a, b)
105 deriving instance (Ord a, Ord b) => Ord (a, b)
106 deriving instance (Eq  a, Eq  b, Eq  c) => Eq  (a, b, c)
107 deriving instance (Ord a, Ord b, Ord c) => Ord (a, b, c)
108 deriving instance (Eq  a, Eq  b, Eq  c, Eq  d) => Eq  (a, b, c, d)
109 deriving instance (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d)
110 deriving instance (Eq  a, Eq  b, Eq  c, Eq  d, Eq  e) => Eq  (a, b, c, d, e)
111 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e)
112 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f)
113                => Eq (a, b, c, d, e, f)
114 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f)
115                => Ord (a, b, c, d, e, f)
116 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g)
117                => Eq (a, b, c, d, e, f, g)
118 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g)
119                => Ord (a, b, c, d, e, f, g)
120 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
121                    Eq h)
122                => Eq (a, b, c, d, e, f, g, h)
123 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
124                    Ord h)
125                => Ord (a, b, c, d, e, f, g, h)
126 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
127                    Eq h, Eq i)
128                => Eq (a, b, c, d, e, f, g, h, i)
129 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
130                    Ord h, Ord i)
131                => Ord (a, b, c, d, e, f, g, h, i)
132 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
133                    Eq h, Eq i, Eq j)
134                => Eq (a, b, c, d, e, f, g, h, i, j)
135 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
136                    Ord h, Ord i, Ord j)
137                => Ord (a, b, c, d, e, f, g, h, i, j)
138 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
139                    Eq h, Eq i, Eq j, Eq k)
140                => Eq (a, b, c, d, e, f, g, h, i, j, k)
141 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
142                    Ord h, Ord i, Ord j, Ord k)
143                => Ord (a, b, c, d, e, f, g, h, i, j, k)
144 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
145                    Eq h, Eq i, Eq j, Eq k, Eq l)
146                => Eq (a, b, c, d, e, f, g, h, i, j, k, l)
147 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
148                    Ord h, Ord i, Ord j, Ord k, Ord l)
149                => Ord (a, b, c, d, e, f, g, h, i, j, k, l)
150 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
151                    Eq h, Eq i, Eq j, Eq k, Eq l, Eq m)
152                => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m)
153 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
154                    Ord h, Ord i, Ord j, Ord k, Ord l, Ord m)
155                => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m)
156 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
157                    Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n)
158                => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
159 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
160                    Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n)
161                => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
162 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
163                    Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o)
164                => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
165 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
166                    Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o)
167                => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
168 #endif  /* !__HADDOCK__ */
169 #endif  /* __GLASGOW_HASKELL__ */
170
171 -- ---------------------------------------------------------------------------
172 -- Standard functions over tuples
173
174 #if !defined(__HUGS__) && !defined(__NHC__)
175 -- | Extract the first component of a pair.
176 fst                     :: (a,b) -> a
177 fst (x,_)               =  x
178
179 -- | Extract the second component of a pair.
180 snd                     :: (a,b) -> b
181 snd (_,y)               =  y
182
183 -- | 'curry' converts an uncurried function to a curried function.
184 curry                   :: ((a, b) -> c) -> a -> b -> c
185 curry f x y             =  f (x, y)
186
187 -- | 'uncurry' converts a curried function to a function on pairs.
188 uncurry                 :: (a -> b -> c) -> ((a, b) -> c)
189 uncurry f p             =  f (fst p) (snd p)
190 #endif  /* neither __HUGS__ nor __NHC__ */