add GHC.HetMet.{hetmet_kappa,hetmet_kappa_app}
[ghc-base.git] / Data / Tuple.hs
1 {-# LANGUAGE CPP, NoImplicitPrelude #-}
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   , swap        -- :: (a,b) -> (b,a)
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.Classes, GHC.Ordering, GHC.Types
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 -- ---------------------------------------------------------------------------
89 -- Standard functions over tuples
90
91 #if !defined(__HUGS__) && !defined(__NHC__)
92 -- | Extract the first component of a pair.
93 fst                     :: (a,b) -> a
94 fst (x,_)               =  x
95
96 -- | Extract the second component of a pair.
97 snd                     :: (a,b) -> b
98 snd (_,y)               =  y
99
100 -- | 'curry' converts an uncurried function to a curried function.
101 curry                   :: ((a, b) -> c) -> a -> b -> c
102 curry f x y             =  f (x, y)
103
104 -- | 'uncurry' converts a curried function to a function on pairs.
105 uncurry                 :: (a -> b -> c) -> ((a, b) -> c)
106 uncurry f p             =  f (fst p) (snd p)
107 #endif  /* neither __HUGS__ nor __NHC__ */
108
109 -- | Swap the components of a pair.
110 swap                    :: (a,b) -> (b,a)
111 swap (a,b)              = (b,a)