type-combinators-0.1.2.1: A collection of data types for type-level programming

CopyrightCopyright (C) 2015 Kyle Carter
LicenseBSD3
MaintainerKyle Carter <kylcarte@indiana.edu>
Stabilityexperimental
PortabilityRankNTypes
Safe HaskellNone
LanguageHaskell2010

Type.Class.Witness

Description

A type t that is a Witness p q t provides a Constraint entailment of q, given that p holds.

The Witness class uses an associated Constraint WitnessC to maintain backwards inference of Witness instances with respect to type refinement. See the Known class for more information.

Heavily inspired by ekmett's constraints library: http://hackage.haskell.org/package/constraints

The code provided here does not quite subsume the constraints library, as we do not give classes and instances for representing the standard library's class heirarchy and instance definitions.

Synopsis

Documentation

data Wit :: Constraint -> * where Source

A reified Constraint.

Constructors

Wit :: c => Wit c 

Instances

c => Known Constraint Wit c Source

If the constraint c holds, there is a canonical construction for a term of type Wit c, viz. the constructor Wit.

Witness ØC c (Wit c) Source 
type KnownC Constraint Wit c = c Source 
type WitnessC ØC c (Wit c) = ØC 

data Wit1 :: (k -> Constraint) -> k -> * where Source

Constructors

Wit1 :: c a => Wit1 c a 

data (:-) :: Constraint -> Constraint -> * where infixr 4 Source

Reified evidence of Constraint entailment.

Given a term of p :- q, the Constraint q holds if p holds.

Entailment of Constraints form a Category:

>>> id  :: p :- p
>>> (.) :: (q :- r) -> (p :-> q) -> (p :- r)

Constructors

Sub :: (p => Wit q) -> p :- q 

Fields

getSub :: p => Wit q
 

Instances

Category Constraint (:-) Source 
Witness p q ((:-) p q) Source

An entailment p :- q is a Witness of q, given p.

type WitnessC p q ((:-) p q) = ØC 

type (:-:) = Bij (:-) infixr 4 Source

class WitnessC p q t => Witness p q t | t -> p q where Source

A general eliminator for entailment.

Given a term of type t with an instance Witness p q t and a term of type r that depends on Constraint q, we can reduce the Constraint to p.

If p is ØC, i.e. the empty Constraint (), then a Witness t can completely discharge the Constraint q.

Associated Types

type WitnessC p q t :: Constraint Source

Methods

(\\) :: p => (q => r) -> t -> r infixl 1 Source

Instances

Witness p q a => Witness p q (I a) Source 
Witness ØC c (Wit c) Source 
Witness p q ((:-) p q) Source

An entailment p :- q is a Witness of q, given p.

(Witness p q (f a), (~) (Maybe k) x (Just k a)) => Witness p q (Option k f x) Source 
(Witness p q (f a), Witness p q (Sum k f ((:<) k b as))) => Witness p q (Sum k f ((:<) k a ((:<) k b as))) Source 
Witness p q (f a) => Witness p q (Sum k f ((:) k a ([] k))) Source 
Witness p q (f a a) => Witness p q (Join k f a) Source 
Witness p q r => Witness p q (C k r a) Source 
Witness p q (f a) => Witness p q (IT k f a) Source 
Witness ØC ØC (Prod k f (Ø k)) Source 
Witness ØC ØC (FProd k (Ø (k -> *)) a) Source

An empty FProd is a no-op Witness.

(Witness p q (f a), Witness p q (g a)) => Witness p q ((:+:) k f g a) Source 
(Witness r s (p a b), (~) ((,) k k1) q ((#) k k1 a b)) => Witness r s (Uncur k k p q) Source 
Witness p q (g b) => Witness p q ((:|:) k k f g (Right k k b)) Source 
Witness p q (f a) => Witness p q ((:|:) k k f g (Left k k a)) Source 
(Witness r s (p a b c), (~) ((,,) k k1 k2) q ((,,) k k1 k2 a b c)) => Witness r s (Uncur3 k k k p q) Source 
Witness q r (p ((#) k k1 a b)) => Witness q r (Cur k k p a b) Source 
Witness p q (f a b) => Witness p q (Flip k k f b a) Source 
Witness p q r => Witness p q (CT k k r f a) Source 
Witness p q (f a (g a)) => Witness p q (SS k k f g a) Source 
Witness p q (f (g a)) => Witness p q (RR k k g f a) Source 
Witness p q (f (g a)) => Witness p q (LL k k a f g) Source 
Witness p q (f (g a)) => Witness p q ((:.:) k k f g a) Source 
Witness q r (p ((,,) k k1 k2 a b c)) => Witness q r (Cur3 k k k p a b c) Source 
Witness p q (f (g a b)) => Witness p q ((:..:) k k k f g a b) Source 
(~) N n' (Pred n) => Witness ØC ((~) N (S n') n) (Fin n) Source

A Fin n is a Witness that n >= 1.

That is, Pred n is well defined.

Witness ØC (Known N Nat n) (Nat n) Source

A Nat n is a Witness that there is a canonical construction for Nat n.

Witness ØC ((~) k a b) ((:~:) k a b) Source

A type equality a :~: b is a Witness that (a ~ b).

Witness ØC (Known N Nat n) (VT k n f a) Source 
(Witness p q (f a), Witness s t (Prod k f as)) => Witness (p, s) (q, t) (Prod k f ((:<) k a as)) Source 
(Witness p q (f a), Witness s t (FProd k fs a)) => Witness (p, s) (q, t) (FProd k ((:<) (k -> *) f fs) a) Source

A non-empty FProd is a Witness if both its head and tail are Witnesses.

(Witness p q (f a), Witness s t (g a)) => Witness (p, s) (q, t) ((:&:) k f g a) Source 
(Witness p q (f a), Witness s t (g b), (~) ((,) k k1) x ((#) k k1 a b)) => Witness (p, s) (q, t) ((:*:) k k f g x) Source 

entailed :: Witness p q t => t -> p :- q Source

Convert a Witness to a canonical reified entailment.

witnessed :: Witness ØC q t => t -> Wit q Source

Convert a Witness to a canonical reified Constraint.

(/?) :: (Witness p q t, p) => Maybe t -> (q => Maybe r) -> Maybe r infixr 0 Source

Constraint chaining under Maybe.

qed :: Maybe (a :~: a) Source

data Dec a Source

Constructors

Proven a 
Refuted (a -> Void) 

class DecEquality f where Source

Methods

decideEquality :: f a -> f b -> Dec (a :~: b) Source

Instances

decCase :: Dec a -> (a -> r) -> ((a -> Void) -> r) -> r Source

data Bij p a b Source

Constructors

Bij 

Fields

fwd :: p a b
 
bwd :: p b a
 

Instances

Category k p => Category k (Bij k p) Source 

($->) :: Bij p a b -> p a b infixr 1 Source

(<-$) :: Bij p a b -> p b a infixr 1 Source

type (<->) = Bij (->) infixr 5 Source

(<->) :: p a b -> p b a -> Bij p a b infixr 5 Source

(<?>) :: (r <-> s) -> Dec r -> Dec s infix 3 Source