De-orphan tuple Eq/Ord instances
[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
44 import GHC.Base
45 -- We need to depend on GHC.Base so that
46 -- a) so that we get GHC.Bool, GHC.Classes, GHC.Ordering
47
48 -- b) so that GHC.Base.inline is available, which is used
49 --    when expanding instance declarations
50
51 import GHC.Tuple
52 -- We must import GHC.Tuple, to ensure sure that the 
53 -- data constructors of `(,)' are in scope when we do
54 -- the standalone deriving instance for Eq (a,b) etc
55
56 #endif  /* __GLASGOW_HASKELL__ */
57
58 #ifdef __NHC__
59 import Prelude
60 import Prelude
61   ( (,)(..)
62   , (,,)(..)
63   , (,,,)(..)
64   , (,,,,)(..)
65   , (,,,,,)(..)
66   , (,,,,,,)(..)
67   , (,,,,,,,)(..)
68   , (,,,,,,,,)(..)
69   , (,,,,,,,,,)(..)
70   , (,,,,,,,,,,)(..)
71   , (,,,,,,,,,,,)(..)
72   , (,,,,,,,,,,,,)(..)
73   , (,,,,,,,,,,,,,)(..)
74   , (,,,,,,,,,,,,,,)(..)
75   -- nhc98's prelude only supplies tuple instances up to size 15
76   , fst, snd
77   , curry, uncurry
78   )
79 #endif
80
81 #ifdef __GLASGOW_HASKELL__
82 import GHC.Unit ()
83 #endif
84
85 default ()              -- Double isn't available yet
86
87 -- ---------------------------------------------------------------------------
88 -- Standard functions over tuples
89
90 #if !defined(__HUGS__) && !defined(__NHC__)
91 -- | Extract the first component of a pair.
92 fst                     :: (a,b) -> a
93 fst (x,_)               =  x
94
95 -- | Extract the second component of a pair.
96 snd                     :: (a,b) -> b
97 snd (_,y)               =  y
98
99 -- | 'curry' converts an uncurried function to a curried function.
100 curry                   :: ((a, b) -> c) -> a -> b -> c
101 curry f x y             =  f (x, y)
102
103 -- | 'uncurry' converts a curried function to a function on pairs.
104 uncurry                 :: (a -> b -> c) -> ((a, b) -> c)
105 uncurry f p             =  f (fst p) (snd p)
106 #endif  /* neither __HUGS__ nor __NHC__ */