base-4.10.1.0: Basic libraries

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

Data.Type.Coercion

Description

Definition of representational equality (`Coercion`).

Since: 4.7.0.0

Synopsis

- data Coercion a b where
  - Coercion :: Coercible a b => Coercion a b
- coerceWith :: Coercion a b -> a -> b
- gcoerceWith :: Coercion a b -> (Coercible a b => r) -> r
- sym :: Coercion a b -> Coercion b a
- trans :: Coercion a b -> Coercion b c -> Coercion a c
- repr :: (a :~: b) -> Coercion a b
- class TestCoercion f where

# Documentation

data Coercion a b where #

Representational equality. If `Coercion a b` is inhabited by some terminating value, then the type `a` has the same underlying representation as the type `b`.

To use this equality in practice, pattern-match on the `Coercion a b` to get out the `Coercible a b` instance, and then use `coerce` to apply it.

Since: 4.7.0.0

Constructors

Coercion :: Coercible a b => Coercion a b |

Instances

Category k (Coercion k) # | Since: 4.7.0.0
Methods id :: cat a a # (.) :: cat b c -> cat a b -> cat a c #
TestCoercion k (Coercion k a) # | Since: 4.7.0.0
Methods testCoercion :: f a -> f b -> Maybe (Coercion (Coercion k a) a b) #
Coercible k a b => Bounded (Coercion k a b) # | Since: 4.7.0.0
Methods minBound :: Coercion k a b # maxBound :: Coercion k a b #
Coercible k a b => Enum (Coercion k a b) # | Since: 4.7.0.0

Methods

succ :: Coercion k a b -> Coercion k a b #

pred :: Coercion k a b -> Coercion k a b #

toEnum :: Int -> Coercion k a b #

fromEnum :: Coercion k a b -> Int #

enumFrom :: Coercion k a b -> [Coercion k a b] #

enumFromThen :: Coercion k a b -> Coercion k a b -> [Coercion k a b] #

enumFromTo :: Coercion k a b -> Coercion k a b -> [Coercion k a b] #

enumFromThenTo :: Coercion k a b -> Coercion k a b -> Coercion k a b -> [Coercion k a b] #

Eq (Coercion k a b) # |
Methods (==) :: Coercion k a b -> Coercion k a b -> Bool Source # (/=) :: Coercion k a b -> Coercion k a b -> Bool Source #
(Coercible * a b, Data a, Data b) => Data (Coercion * a b) # | Since: 4.7.0.0

Methods

gfoldl :: (forall d c. Data d => c (d -> c) -> d -> c c) -> (forall g. g -> c g) -> Coercion * a b -> c (Coercion * a b) #

gunfold :: (forall c r. Data c => c (c -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Coercion * a b) #

toConstr :: Coercion * a b -> Constr #

dataTypeOf :: Coercion * a b -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Coercion * a b)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Coercion * a b)) #

gmapT :: (forall c. Data c => c -> c) -> Coercion * a b -> Coercion * a b #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Coercion * a b -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Coercion * a b -> r #

gmapQ :: (forall d. Data d => d -> u) -> Coercion * a b -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Coercion * a b -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Coercion * a b -> m (Coercion * a b) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Coercion * a b -> m (Coercion * a b) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Coercion * a b -> m (Coercion * a b) #

Ord (Coercion k a b) # |

Methods

compare :: Coercion k a b -> Coercion k a b -> Ordering Source #

(<) :: Coercion k a b -> Coercion k a b -> Bool Source #

(<=) :: Coercion k a b -> Coercion k a b -> Bool Source #

(>) :: Coercion k a b -> Coercion k a b -> Bool Source #

(>=) :: Coercion k a b -> Coercion k a b -> Bool Source #

max :: Coercion k a b -> Coercion k a b -> Coercion k a b Source #

min :: Coercion k a b -> Coercion k a b -> Coercion k a b Source #

Coercible k a b => Read (Coercion k a b) # | Since: 4.7.0.0
Methods readsPrec :: Int -> ReadS (Coercion k a b) # readList :: ReadS [Coercion k a b] # readPrec :: ReadPrec (Coercion k a b) # readListPrec :: ReadPrec [Coercion k a b] #
Show (Coercion k a b) # |
Methods showsPrec :: Int -> Coercion k a b -> ShowS # show :: Coercion k a b -> String # showList :: [Coercion k a b] -> ShowS #

coerceWith :: Coercion a b -> a -> b #

Type-safe cast, using representational equality

gcoerceWith :: Coercion a b -> (Coercible a b => r) -> r #

Generalized form of type-safe cast using representational equality

Since: 4.10.0.0

sym :: Coercion a b -> Coercion b a #

Symmetry of representational equality

trans :: Coercion a b -> Coercion b c -> Coercion a c #

Transitivity of representational equality

repr :: (a :~: b) -> Coercion a b #

Convert propositional (nominal) equality to representational equality

class TestCoercion f where #

This class contains types where you can learn the equality of two types from information contained in terms. Typically, only singleton types should inhabit this class.

Minimal complete definition

testCoercion

Methods

testCoercion :: f a -> f b -> Maybe (Coercion a b) #

Conditionally prove the representational equality of `a` and `b`.

Instances

TestCoercion k (Coercion k a) # | Since: 4.7.0.0
Methods testCoercion :: f a -> f b -> Maybe (Coercion (Coercion k a) a b) #
TestCoercion k ((:~:) k a) # | Since: 4.7.0.0
Methods testCoercion :: f a -> f b -> Maybe (Coercion (k :~: a) a b) #
TestCoercion k ((:~~:) k1 k a) # | Since: 4.10.0.0
Methods testCoercion :: f a -> f b -> Maybe (Coercion ((k1 :~~: k) a) a b) #