Implement "TypeLevelReasoning" proposal at wiki:TypeLevelReasoning
[packages/base.git] / Data / Tuple.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE CPP, NoImplicitPrelude #-}
3 {-# OPTIONS_GHC -fno-warn-unused-imports #-}
4 -- XXX -fno-warn-unused-imports needed for the GHC.Tuple import below. Sigh.
5
6 -----------------------------------------------------------------------------
7 -- |
8 -- Module : Data.Tuple
9 -- Copyright : (c) The University of Glasgow 2001
10 -- License : BSD-style (see the file libraries/base/LICENSE)
11 --
12 -- Maintainer : libraries@haskell.org
13 -- Stability : experimental
14 -- Portability : portable
15 --
16 -- The tuple data types, and associated functions.
17 --
18 -----------------------------------------------------------------------------
19
20 module Data.Tuple
21 ( fst
22 , snd
23 , curry
24 , uncurry
25 , swap
26 )
27 where
28
29 #ifdef __GLASGOW_HASKELL__
30
31 import GHC.Base
32 -- We need to depend on GHC.Base so that
33 -- a) so that we get GHC.Classes, GHC.Types
34
35 -- b) so that GHC.Base.inline is available, which is used
36 -- when expanding instance declarations
37
38 import GHC.Tuple
39 -- We must import GHC.Tuple, to ensure sure that the
40 -- data constructors of `(,)' are in scope when we do
41 -- the standalone deriving instance for Eq (a,b) etc
42
43 #endif /* __GLASGOW_HASKELL__ */
44
45 default () -- Double isn't available yet
46
47 -- ---------------------------------------------------------------------------
48 -- Standard functions over tuples
49
50 #if !defined(__HUGS__)
51 -- | Extract the first component of a pair.
52 fst :: (a,b) -> a
53 fst (x,_) = x
54
55 -- | Extract the second component of a pair.
56 snd :: (a,b) -> b
57 snd (_,y) = y
58
59 -- | 'curry' converts an uncurried function to a curried function.
60 curry :: ((a, b) -> c) -> a -> b -> c
61 curry f x y = f (x, y)
62
63 -- | 'uncurry' converts a curried function to a function on pairs.
64 uncurry :: (a -> b -> c) -> ((a, b) -> c)
65 uncurry f p = f (fst p) (snd p)
66 #endif
67
68 -- | Swap the components of a pair.
69 swap :: (a,b) -> (b,a)
70 swap (a,b) = (b,a)