Data.Proxy

base-4.12.0.0: Basic libraries

License | BSD-style (see the LICENSE file in the distribution)
Maintainer | libraries@haskell.org
Stability | experimental
Portability | portable
Safe Haskell | Trustworthy
Language | Haskell2010

Data.Proxy

Description

Definition of a Proxy type (poly-kinded in GHC)

Since: base-4.7.0.0

Synopsis

- data Proxy t = Proxy
- asProxyTypeOf :: a -> proxy a -> a
- data KProxy (t :: Type) = KProxy

# Documentation

data Proxy t #

`Proxy` is a type that holds no data, but has a phantom parameter of arbitrary type (or even kind). Its use is to provide type information, even though there is no value available of that type (or it may be too costly to create one).

Historically, ``Proxy` :: `Proxy` a` is a safer alternative to the `'undefined :: a'` idiom.

    >>> Proxy :: Proxy (Void, Int -> Int)
    Proxy

Proxy can even hold types of higher kinds,

    >>> Proxy :: Proxy Either
    Proxy

    >>> Proxy :: Proxy Functor
    Proxy

    >>> Proxy :: Proxy complicatedStructure
    Proxy

Constructors

Proxy |

Instances

Generic1 (Proxy :: k -> Type) # |
Instance details Defined in GHC.Generics Associated Types type Rep1 Proxy :: k -> Type # Methods from1 :: Proxy a -> Rep1 Proxy a # to1 :: Rep1 Proxy a -> Proxy a #
Monad (Proxy :: Type -> Type) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods (>>=) :: Proxy a -> (a -> Proxy b) -> Proxy b # (>>) :: Proxy a -> Proxy b -> Proxy b # return :: a -> Proxy a # fail :: String -> Proxy a #
Functor (Proxy :: Type -> Type) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods fmap :: (a -> b) -> Proxy a -> Proxy b # (<$) :: a -> Proxy b -> Proxy a #
Applicative (Proxy :: Type -> Type) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods pure :: a -> Proxy a # (<*>) :: Proxy (a -> b) -> Proxy a -> Proxy b # liftA2 :: (a -> b -> c) -> Proxy a -> Proxy b -> Proxy c # (*>) :: Proxy a -> Proxy b -> Proxy b # (<*) :: Proxy a -> Proxy b -> Proxy a #
Foldable (Proxy :: Type -> Type) # | Since: base-4.7.0.0
Instance details Defined in Data.Foldable Methods fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # toList :: Proxy a -> [a] # null :: Proxy a -> Bool # length :: Proxy a -> Int # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # sum :: Num a => Proxy a -> a # product :: Num a => Proxy a -> a #
Traversable (Proxy :: Type -> Type) # | Since: base-4.7.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Proxy a -> f (Proxy b) # sequenceA :: Applicative f => Proxy (f a) -> f (Proxy a) # mapM :: Monad m => (a -> m b) -> Proxy a -> m (Proxy b) # sequence :: Monad m => Proxy (m a) -> m (Proxy a) #
MonadPlus (Proxy :: Type -> Type) # | Since: base-4.9.0.0
Instance details Defined in Data.Proxy Methods mzero :: Proxy a # mplus :: Proxy a -> Proxy a -> Proxy a #
Alternative (Proxy :: Type -> Type) # | Since: base-4.9.0.0
Instance details Defined in Data.Proxy Methods empty :: Proxy a # (<|>) :: Proxy a -> Proxy a -> Proxy a # some :: Proxy a -> Proxy [a] # many :: Proxy a -> Proxy [a] #
MonadZip (Proxy :: Type -> Type) # | Since: base-4.9.0.0
Instance details Defined in Control.Monad.Zip Methods mzip :: Proxy a -> Proxy b -> Proxy (a, b) # mzipWith :: (a -> b -> c) -> Proxy a -> Proxy b -> Proxy c # munzip :: Proxy (a, b) -> (Proxy a, Proxy b) #
Show1 (Proxy :: Type -> Type) # | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Classes Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Proxy a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Proxy a] -> ShowS #
Read1 (Proxy :: Type -> Type) # | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Proxy a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Proxy a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Proxy a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Proxy a] #
Ord1 (Proxy :: Type -> Type) # | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Classes Methods liftCompare :: (a -> b -> Ordering) -> Proxy a -> Proxy b -> Ordering #
Eq1 (Proxy :: Type -> Type) # | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Classes Methods liftEq :: (a -> b -> Bool) -> Proxy a -> Proxy b -> Bool #
Contravariant (Proxy :: Type -> Type) # |
Instance details Defined in Data.Functor.Contravariant Methods contramap :: (a -> b) -> Proxy b -> Proxy a # (>$) :: b -> Proxy b -> Proxy a #
Bounded (Proxy t) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods minBound :: Proxy t # maxBound :: Proxy t #
Enum (Proxy s) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods succ :: Proxy s -> Proxy s # pred :: Proxy s -> Proxy s # toEnum :: Int -> Proxy s # fromEnum :: Proxy s -> Int # enumFrom :: Proxy s -> [Proxy s] # enumFromThen :: Proxy s -> Proxy s -> [Proxy s] # enumFromTo :: Proxy s -> Proxy s -> [Proxy s] # enumFromThenTo :: Proxy s -> Proxy s -> Proxy s -> [Proxy s] #
Eq (Proxy s) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods (==) :: Proxy s -> Proxy s -> Bool Source # (/=) :: Proxy s -> Proxy s -> Bool Source #
Data t => Data (Proxy t) # | Since: base-4.7.0.0
Instance details Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Proxy t -> c (Proxy t) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Proxy t) # toConstr :: Proxy t -> Constr # dataTypeOf :: Proxy t -> DataType # dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Proxy t)) # dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Proxy t)) # gmapT :: (forall b. Data b => b -> b) -> Proxy t -> Proxy t # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Proxy t -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Proxy t -> r # gmapQ :: (forall d. Data d => d -> u) -> Proxy t -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Proxy t -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Proxy t -> m (Proxy t) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Proxy t -> m (Proxy t) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Proxy t -> m (Proxy t) #
Ord (Proxy s) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods compare :: Proxy s -> Proxy s -> Ordering Source # (<) :: Proxy s -> Proxy s -> Bool Source # (<=) :: Proxy s -> Proxy s -> Bool Source # (>) :: Proxy s -> Proxy s -> Bool Source # (>=) :: Proxy s -> Proxy s -> Bool Source # max :: Proxy s -> Proxy s -> Proxy s Source # min :: Proxy s -> Proxy s -> Proxy s Source #
Read (Proxy t) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods readsPrec :: Int -> ReadS (Proxy t) # readList :: ReadS [Proxy t] # readPrec :: ReadPrec (Proxy t) # readListPrec :: ReadPrec [Proxy t] #
Show (Proxy s) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods showsPrec :: Int -> Proxy s -> ShowS # show :: Proxy s -> String # showList :: [Proxy s] -> ShowS #
Ix (Proxy s) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods range :: (Proxy s, Proxy s) -> [Proxy s] # index :: (Proxy s, Proxy s) -> Proxy s -> Int # unsafeIndex :: (Proxy s, Proxy s) -> Proxy s -> Int inRange :: (Proxy s, Proxy s) -> Proxy s -> Bool # rangeSize :: (Proxy s, Proxy s) -> Int # unsafeRangeSize :: (Proxy s, Proxy s) -> Int
Generic (Proxy t) # |
Instance details Defined in GHC.Generics Associated Types type Rep (Proxy t) :: Type -> Type # Methods from :: Proxy t -> Rep (Proxy t) x # to :: Rep (Proxy t) x -> Proxy t #
Semigroup (Proxy s) # | Since: base-4.9.0.0
Instance details Defined in Data.Proxy Methods (<>) :: Proxy s -> Proxy s -> Proxy s # sconcat :: NonEmpty (Proxy s) -> Proxy s # stimes :: Integral b => b -> Proxy s -> Proxy s #
Monoid (Proxy s) # | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods mempty :: Proxy s # mappend :: Proxy s -> Proxy s -> Proxy s # mconcat :: [Proxy s] -> Proxy s #
type Rep1 (Proxy :: k -> Type) # | Since: base-4.6.0.0
Instance details Defined in GHC.Generics type Rep1 (Proxy :: k -> Type) = D1 (MetaData "Proxy" "Data.Proxy" "base" False) (C1 (MetaCons "Proxy" PrefixI False) (U1 :: k -> Type))
type Rep (Proxy t) # | Since: base-4.6.0.0
Instance details Defined in GHC.Generics type Rep (Proxy t) = D1 (MetaData "Proxy" "Data.Proxy" "base" False) (C1 (MetaCons "Proxy" PrefixI False) (U1 :: Type -> Type))

asProxyTypeOf :: a -> proxy a -> a #

`asProxyTypeOf` is a type-restricted version of `const`. It is usually used as an infix operator, and its typing forces its first argument (which is usually overloaded) to have the same type as the tag of the second.

    >>> import Data.Word
    >>> :type asProxyTypeOf 123 (Proxy :: Proxy Word8)
    asProxyTypeOf 123 (Proxy :: Proxy Word8) :: Word8

Note the lower-case `proxy` in the definition. This allows any type constructor with just one argument to be passed to the function, for example we could also write

    >>> import Data.Word
    >>> :type asProxyTypeOf 123 (Just (undefined :: Word8))
    asProxyTypeOf 123 (Just (undefined :: Word8)) :: Word8

data KProxy (t :: Type) #

A concrete, promotable proxy type, for use at the kind level There are no instances for this because it is intended at the kind level only

Constructors

KProxy |