Remove some cruft from Data.HashTable
[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 import GHC.Bool
45 import GHC.Classes
46 import GHC.Ordering
47 -- XXX The standalone deriving clauses fail with
48 --     The data constructors of `(,)' are not all in scope
49 --       so you cannot derive an instance for it
50 --     In the stand-alone deriving instance for `Eq (a, b)'
51 -- if we don't import GHC.Tuple
52 import GHC.Tuple
53 #endif  /* __GLASGOW_HASKELL__ */
54
55 #ifdef __NHC__
56 import Prelude
57 import Prelude
58   ( (,)(..)
59   , (,,)(..)
60   , (,,,)(..)
61   , (,,,,)(..)
62   , (,,,,,)(..)
63   , (,,,,,,)(..)
64   , (,,,,,,,)(..)
65   , (,,,,,,,,)(..)
66   , (,,,,,,,,,)(..)
67   , (,,,,,,,,,,)(..)
68   , (,,,,,,,,,,,)(..)
69   , (,,,,,,,,,,,,)(..)
70   , (,,,,,,,,,,,,,)(..)
71   , (,,,,,,,,,,,,,,)(..)
72   -- nhc98's prelude only supplies tuple instances up to size 15
73   , fst, snd
74   , curry, uncurry
75   )
76 #endif
77
78 #ifdef __GLASGOW_HASKELL__
79 import GHC.Unit ()
80 #endif
81
82 default ()              -- Double isn't available yet
83
84 #ifdef __GLASGOW_HASKELL__
85 -- XXX Why aren't these derived?
86 instance Eq () where
87     () == () = True
88     () /= () = False
89
90 instance Ord () where
91     () <= () = True
92     () <  () = False
93     () >= () = True
94     () >  () = False
95     max () () = ()
96     min () () = ()
97     compare () () = EQ
98
99 #ifndef __HADDOCK__
100 deriving instance (Eq  a, Eq  b) => Eq  (a, b)
101 deriving instance (Ord a, Ord b) => Ord (a, b)
102 deriving instance (Eq  a, Eq  b, Eq  c) => Eq  (a, b, c)
103 deriving instance (Ord a, Ord b, Ord c) => Ord (a, b, c)
104 deriving instance (Eq  a, Eq  b, Eq  c, Eq  d) => Eq  (a, b, c, d)
105 deriving instance (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d)
106 deriving instance (Eq  a, Eq  b, Eq  c, Eq  d, Eq  e) => Eq  (a, b, c, d, e)
107 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e)
108 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f)
109                => Eq (a, b, c, d, e, f)
110 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f)
111                => Ord (a, b, c, d, e, f)
112 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g)
113                => Eq (a, b, c, d, e, f, g)
114 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g)
115                => Ord (a, b, c, d, e, f, g)
116 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
117                    Eq h)
118                => Eq (a, b, c, d, e, f, g, h)
119 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
120                    Ord h)
121                => Ord (a, b, c, d, e, f, g, h)
122 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
123                    Eq h, Eq i)
124                => Eq (a, b, c, d, e, f, g, h, i)
125 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
126                    Ord h, Ord i)
127                => Ord (a, b, c, d, e, f, g, h, i)
128 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
129                    Eq h, Eq i, Eq j)
130                => Eq (a, b, c, d, e, f, g, h, i, j)
131 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
132                    Ord h, Ord i, Ord j)
133                => Ord (a, b, c, d, e, f, g, h, i, j)
134 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
135                    Eq h, Eq i, Eq j, Eq k)
136                => Eq (a, b, c, d, e, f, g, h, i, j, k)
137 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
138                    Ord h, Ord i, Ord j, Ord k)
139                => Ord (a, b, c, d, e, f, g, h, i, j, k)
140 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
141                    Eq h, Eq i, Eq j, Eq k, Eq l)
142                => Eq (a, b, c, d, e, f, g, h, i, j, k, l)
143 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
144                    Ord h, Ord i, Ord j, Ord k, Ord l)
145                => Ord (a, b, c, d, e, f, g, h, i, j, k, l)
146 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
147                    Eq h, Eq i, Eq j, Eq k, Eq l, Eq m)
148                => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m)
149 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
150                    Ord h, Ord i, Ord j, Ord k, Ord l, Ord m)
151                => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m)
152 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
153                    Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n)
154                => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
155 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
156                    Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n)
157                => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
158 deriving instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g,
159                    Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o)
160                => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
161 deriving instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g,
162                    Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o)
163                => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
164 #endif  /* !__HADDOCK__ */
165 #endif  /* __GLASGOW_HASKELL__ */
166
167 -- ---------------------------------------------------------------------------
168 -- Standard functions over tuples
169
170 #if !defined(__HUGS__) && !defined(__NHC__)
171 -- | Extract the first component of a pair.
172 fst                     :: (a,b) -> a
173 fst (x,_)               =  x
174
175 -- | Extract the second component of a pair.
176 snd                     :: (a,b) -> b
177 snd (_,y)               =  y
178
179 -- | 'curry' converts an uncurried function to a curried function.
180 curry                   :: ((a, b) -> c) -> a -> b -> c
181 curry f x y             =  f (x, y)
182
183 -- | 'uncurry' converts a curried function to a function on pairs.
184 uncurry                 :: (a -> b -> c) -> ((a, b) -> c)
185 uncurry f p             =  f (fst p) (snd p)
186 #endif  /* neither __HUGS__ nor __NHC__ */