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