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 | Trustworthy
Language | Haskell2010

Data.Type.Equality

Contents

- The equality types
- Working with equality
- Inferring equality from other types
- Boolean type-level equality

Description

Definition of propositional equality `(:~:)`. Pattern-matching on a variable of type `(a :~: b)` produces a proof that `a ~ b`.

Since: 4.7.0.0

Synopsis

- data a :~: b where
  - Refl :: a :~: a
- class (~#) k0 k1 a b => (k0 ~~ k1) (a :: k0) (b :: k1)
- data (a :: k1) :~~: (b :: k2) where
  - HRefl :: a :~~: a
- sym :: (a :~: b) -> b :~: a
- trans :: (a :~: b) -> (b :~: c) -> a :~: c
- castWith :: (a :~: b) -> a -> b
- gcastWith :: (a :~: b) -> (a ~ b => r) -> r
- apply :: (f :~: g) -> (a :~: b) -> f a :~: g b
- inner :: (f a :~: g b) -> a :~: b
- outer :: (f a :~: g b) -> f :~: g
- class TestEquality f where
- type family (a :: k) == (b :: k) :: Bool

# The equality types

data a :~: b where infix 4 #

Propositional equality. If `a :~: b` is inhabited by some terminating value, then the type `a` is the same as the type `b`. To use this equality in practice, pattern-match on the `a :~: b` to get out the `Refl` constructor; in the body of the pattern-match, the compiler knows that `a ~ b`.

Since: 4.7.0.0

Constructors

Refl :: a :~: a |

Instances

Category k ((:~:) k) # | Since: 4.7.0.0
Methods id :: cat a a # (.) :: cat b c -> cat a b -> cat a c #
TestEquality k ((:~:) k a) # | Since: 4.7.0.0
Methods testEquality :: f a -> f b -> Maybe (((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) #
(~) k a b => Bounded ((:~:) k a b) # | Since: 4.7.0.0
Methods minBound :: (k :~: a) b # maxBound :: (k :~: a) b #
(~) k a b => Enum ((:~:) k a b) # | Since: 4.7.0.0
Methods succ :: (k :~: a) b -> (k :~: a) b # pred :: (k :~: a) b -> (k :~: a) b # toEnum :: Int -> (k :~: a) b # fromEnum :: (k :~: a) b -> Int # enumFrom :: (k :~: a) b -> [(k :~: a) b] # enumFromThen :: (k :~: a) b -> (k :~: a) b -> [(k :~: a) b] # enumFromTo :: (k :~: a) b -> (k :~: a) b -> [(k :~: a) b] # enumFromThenTo :: (k :~: a) b -> (k :~: a) b -> (k :~: a) b -> [(k :~: a) b] #
Eq ((:~:) k a b) # |
Methods (==) :: (k :~: a) b -> (k :~: a) b -> Bool Source # (/=) :: (k :~: a) b -> (k :~: a) b -> Bool Source #
((~) * a b, Data a) => Data ((:~:) * 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) -> (* :~: a) b -> c ((* :~: a) b) #

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

toConstr :: (* :~: a) b -> Constr #

dataTypeOf :: (* :~: a) b -> DataType #

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

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

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

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

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

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

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

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

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

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

Ord ((:~:) k a b) # |
Methods compare :: (k :~: a) b -> (k :~: a) b -> Ordering Source # (<) :: (k :~: a) b -> (k :~: a) b -> Bool Source # (<=) :: (k :~: a) b -> (k :~: a) b -> Bool Source # (>) :: (k :~: a) b -> (k :~: a) b -> Bool Source # (>=) :: (k :~: a) b -> (k :~: a) b -> Bool Source # max :: (k :~: a) b -> (k :~: a) b -> (k :~: a) b Source # min :: (k :~: a) b -> (k :~: a) b -> (k :~: a) b Source #
(~) k a b => Read ((:~:) k a b) # | Since: 4.7.0.0
Methods readsPrec :: Int -> ReadS ((k :~: a) b) # readList :: ReadS [(k :~: a) b] # readPrec :: ReadPrec ((k :~: a) b) # readListPrec :: ReadPrec [(k :~: a) b] #
Show ((:~:) k a b) # |
Methods showsPrec :: Int -> (k :~: a) b -> ShowS # show :: (k :~: a) b -> String # showList :: [(k :~: a) b] -> ShowS #

class (~#) k0 k1 a b => (k0 ~~ k1) (a :: k0) (b :: k1) Source #

Lifted, heterogeneous equality. By lifted, we mean that it can be bogus (deferred type error). By heterogeneous, the two types `a` and `b` might have different kinds. Because `~~` can appear unexpectedly in error messages to users who do not care about the difference between heterogeneous equality `~~` and homogeneous equality `~`, this is printed as `~` unless `-fprint-equality-relations` is set.

data (a :: k1) :~~: (b :: k2) where infix 4 #

Kind heterogeneous propositional equality. Like '(:~:)', `a :~~: b` is inhabited by a terminating value if and only if `a` is the same type as `b`.

Since: 4.10.0.0

Constructors

HRefl :: a :~~: a |

Instances

Category k ((:~~:) k k) # | Since: 4.10.0.0
Methods id :: cat a a # (.) :: cat b c -> cat a b -> cat a c #
TestEquality k ((:~~:) k1 k a) # | Since: 4.10.0.0
Methods testEquality :: f a -> f b -> Maybe (((k1 :~~: 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) #
(~~) k1 k2 a b => Bounded ((:~~:) k1 k2 a b) # | Since: 4.10.0.0
Methods minBound :: (k1 :~~: k2) a b # maxBound :: (k1 :~~: k2) a b #
(~~) k1 k2 a b => Enum ((:~~:) k1 k2 a b) # | Since: 4.10.0.0

Methods

succ :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b #

pred :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b #

toEnum :: Int -> (k1 :~~: k2) a b #

fromEnum :: (k1 :~~: k2) a b -> Int #

enumFrom :: (k1 :~~: k2) a b -> [(k1 :~~: k2) a b] #

enumFromThen :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> [(k1 :~~: k2) a b] #

enumFromTo :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> [(k1 :~~: k2) a b] #

enumFromThenTo :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> [(k1 :~~: k2) a b] #

Eq ((:~~:) k1 k2 a b) # | Since: 4.10.0.0
Methods (==) :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> Bool Source # (/=) :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> Bool Source #
(Typeable * i2, Typeable * j2, Typeable i2 a, Typeable j2 b, (~~) i2 j2 a b) => Data ((:~~:) i2 j2 a b) # | Since: 4.10.0.0

Methods

gfoldl :: (forall d c. Data d => c (d -> c) -> d -> c c) -> (forall g. g -> c g) -> (i2 :~~: j2) a b -> c ((i2 :~~: j2) a b) #

gunfold :: (forall c r. Data c => c (c -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ((i2 :~~: j2) a b) #

toConstr :: (i2 :~~: j2) a b -> Constr #

dataTypeOf :: (i2 :~~: j2) a b -> DataType #

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

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

gmapT :: (forall c. Data c => c -> c) -> (i2 :~~: j2) a b -> (i2 :~~: j2) a b #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> (i2 :~~: j2) a b -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> (i2 :~~: j2) a b -> r #

gmapQ :: (forall d. Data d => d -> u) -> (i2 :~~: j2) a b -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> (i2 :~~: j2) a b -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> (i2 :~~: j2) a b -> m ((i2 :~~: j2) a b) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> (i2 :~~: j2) a b -> m ((i2 :~~: j2) a b) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> (i2 :~~: j2) a b -> m ((i2 :~~: j2) a b) #

Ord ((:~~:) k1 k2 a b) # | Since: 4.10.0.0

Methods

compare :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> Ordering Source #

(<) :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> Bool Source #

(<=) :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> Bool Source #

(>) :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> Bool Source #

(>=) :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> Bool Source #

max :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> (k1 :~~: k2) a b Source #

min :: (k1 :~~: k2) a b -> (k1 :~~: k2) a b -> (k1 :~~: k2) a b Source #

(~~) k1 k2 a b => Read ((:~~:) k1 k2 a b) # | Since: 4.10.0.0
Methods readsPrec :: Int -> ReadS ((k1 :~~: k2) a b) # readList :: ReadS [(k1 :~~: k2) a b] # readPrec :: ReadPrec ((k1 :~~: k2) a b) # readListPrec :: ReadPrec [(k1 :~~: k2) a b] #
Show ((:~~:) k1 k2 a b) # | Since: 4.10.0.0
Methods showsPrec :: Int -> (k1 :~~: k2) a b -> ShowS # show :: (k1 :~~: k2) a b -> String # showList :: [(k1 :~~: k2) a b] -> ShowS #

# Working with equality

sym :: (a :~: b) -> b :~: a #

Symmetry of equality

trans :: (a :~: b) -> (b :~: c) -> a :~: c #

Transitivity of equality

castWith :: (a :~: b) -> a -> b #

Type-safe cast, using propositional equality

gcastWith :: (a :~: b) -> (a ~ b => r) -> r #

Generalized form of type-safe cast using propositional equality

apply :: (f :~: g) -> (a :~: b) -> f a :~: g b #

Apply one equality to another, respectively

inner :: (f a :~: g b) -> a :~: b #

Extract equality of the arguments from an equality of applied types

outer :: (f a :~: g b) -> f :~: g #

Extract equality of type constructors from an equality of applied types

# Inferring equality from other types

class TestEquality 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

testEquality

Methods

testEquality :: f a -> f b -> Maybe (a :~: b) #

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

Instances

TestEquality k (TypeRep k) # |
Methods testEquality :: f a -> f b -> Maybe ((TypeRep k :~: a) b) #
TestEquality k ((:~:) k a) # | Since: 4.7.0.0
Methods testEquality :: f a -> f b -> Maybe (((k :~: a) :~: a) b) #
TestEquality k ((:~~:) k1 k a) # | Since: 4.10.0.0
Methods testEquality :: f a -> f b -> Maybe (((k1 :~~: k) a :~: a) b) #

# Boolean type-level equality

type family (a :: k) == (b :: k) :: Bool infix 4 #

A type family to compute Boolean equality. Instances are provided only for open kinds, such as `*` and function kinds. Instances are also provided for datatypes exported from base. A poly-kinded instance is not provided, as a recursive definition for algebraic kinds is generally more useful.

Instances

type (==) Bool a b # |
type (==) Bool a b
type (==) Ordering a b # |
type (==) Ordering a b
type (==) * a b # |
type (==) * a b
type (==) Nat a b # |
type (==) Nat a b
type (==) Symbol a b # |
type (==) Symbol a b
type (==) () a b # |
type (==) () a b
type (==) [k] a b # |
type (==) [k] a b
type (==) (Maybe k) a b # |
type (==) (Maybe k) a b
type (==) (k1 -> k2) a b # |
type (==) (k1 -> k2) a b
type (==) (Either k1 k2) a b # |
type (==) (Either k1 k2) a b
type (==) (k1, k2) a b # |
type (==) (k1, k2) a b
type (==) (k1, k2, k3) a b # |
type (==) (k1, k2, k3) a b
type (==) (k1, k2, k3, k4) a b # |
type (==) (k1, k2, k3, k4) a b
type (==) (k1, k2, k3, k4, k5) a b # |
type (==) (k1, k2, k3, k4, k5) a b
type (==) (k1, k2, k3, k4, k5, k6) a b # |
type (==) (k1, k2, k3, k4, k5, k6) a b
type (==) (k1, k2, k3, k4, k5, k6, k7) a b # |
type (==) (k1, k2, k3, k4, k5, k6, k7) a b
type (==) (k1, k2, k3, k4, k5, k6, k7, k8) a b # |
type (==) (k1, k2, k3, k4, k5, k6, k7, k8) a b
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9) a b # |
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9) a b
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10) a b # |
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10) a b
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11) a b # |
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11) a b
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12) a b # |
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12) a b
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13) a b # |
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13) a b
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14) a b # |
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14) a b
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14, k15) a b # |
type (==) (k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14, k15) a b