Typo
[packages/base.git] / Data / Proxy.hs
1 {-# LANGUAGE NoImplicitPrelude, Trustworthy #-}
2 {-# LANGUAGE PolyKinds #-}
3
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module : Data.Proxy
7 -- License : BSD-style (see the LICENSE file in the distribution)
8 --
9 -- Maintainer : libraries@haskell.org
10 -- Stability : experimental
11 -- Portability : portable
12 --
13 -- Definition of a Proxy type (poly-kinded in GHC)
14 --
15 -- /Since: 4.7.0.0/
16 -----------------------------------------------------------------------------
17
18 module Data.Proxy
19 (
20 Proxy(..), asProxyTypeOf
21 , KProxy(..)
22 ) where
23
24 import GHC.Base
25 import GHC.Show
26 import GHC.Read
27 import GHC.Enum
28 import GHC.Arr
29
30 -- | A concrete, poly-kinded proxy type
31 data Proxy t = Proxy
32
33 -- | A concrete, promotable proxy type, for use at the kind level
34 -- There are no instances for this because it is intended at the kind level only
35 data KProxy (t :: *) = KProxy
36
37 instance Eq (Proxy s) where
38 _ == _ = True
39
40 instance Ord (Proxy s) where
41 compare _ _ = EQ
42
43 instance Show (Proxy s) where
44 showsPrec _ _ = showString "Proxy"
45
46 instance Read (Proxy s) where
47 readsPrec d = readParen (d > 10) (\r -> [(Proxy, s) | ("Proxy",s) <- lex r ])
48
49 instance Enum (Proxy s) where
50 succ _ = error "Proxy.succ"
51 pred _ = error "Proxy.pred"
52 fromEnum _ = 0
53 toEnum 0 = Proxy
54 toEnum _ = error "Proxy.toEnum: 0 expected"
55 enumFrom _ = [Proxy]
56 enumFromThen _ _ = [Proxy]
57 enumFromThenTo _ _ _ = [Proxy]
58 enumFromTo _ _ = [Proxy]
59
60 instance Ix (Proxy s) where
61 range _ = [Proxy]
62 index _ _ = 0
63 inRange _ _ = True
64 rangeSize _ = 1
65 unsafeIndex _ _ = 0
66 unsafeRangeSize _ = 1
67
68 instance Bounded (Proxy s) where
69 minBound = Proxy
70 maxBound = Proxy
71
72 instance Functor Proxy where
73 fmap _ _ = Proxy
74 {-# INLINE fmap #-}
75
76 instance Monad Proxy where
77 return _ = Proxy
78 {-# INLINE return #-}
79 _ >>= _ = Proxy
80 {-# INLINE (>>=) #-}
81
82 -- | 'asProxyTypeOf' is a type-restricted version of 'const'.
83 -- It is usually used as an infix operator, and its typing forces its first
84 -- argument (which is usually overloaded) to have the same type as the tag
85 -- of the second.
86 asProxyTypeOf :: a -> Proxy a -> a
87 asProxyTypeOf = const
88 {-# INLINE asProxyTypeOf #-}