type-combinators-0.2.0.0: 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 

Instances

Witness ØC (c a) (Wit1 k c a) Source 
c a => Known k (Wit1 k c) a Source 
type WitnessC ØC (c a) (Wit1 k c a) = ØC 
type KnownC k (Wit1 k c) a = c a Source 

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 

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 ØC ØC (FProd k (Ø (k -> *)) a) Source

An empty FProd is a no-op Witness.

Witness ØC ØC (Prod k f (Ø k)) Source 
(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 (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 ØC (KnownSymbol x) (Sym x) Source 
Witness ØC (c a) (Wit1 k c a) 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 (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 (Prod k f as)) => Witness (p, s) (q, t) (Prod k f ((:<) k a as)) Source 
(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 

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

Convert a Witness to a canonical reified Constraint.

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

Convert a Witness to a canonical reified entailment.

class Fails c where Source

Methods

failC :: c :- Fail Source

absurdC :: Fails a => a :- b Source

class c => Const c d where Source

Methods

constC :: Wit c Source

Instances

c => Const k c d Source 

class f (g a) => (f g) a where infixr 9 Source

Methods

compC :: Wit (f (g a)) Source

Instances

f (g a) => (∘) k k f g a Source 

class (f a, g a) => (f g) a where infixr 7 Source

Methods

conjC :: (Wit (f a), Wit (g a)) Source

Instances

(f a, g a) => (∧) k f g a Source 

class (f g) a where infixr 6 Source

Methods

disjC :: Either (Wit (f a)) (Wit (g a)) Source

eitherC :: forall f g a b. (f a :- b) -> (g a :- b) -> (f g) a :- b Source

pureC :: b => a :- b Source

contraC :: (a :- Fail) -> a :- b Source

class Forall p q where Source

Minimal complete definition

Nothing

Methods

forall :: p a :- q a Source

commute :: (a ~ b) :- (b ~ a) Source

type family Holds b c :: Constraint Source

Equations

Holds True c = c 
Holds False c = ØC 

falso :: (b ~ False) :- Holds b c Source

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

Constraint chaining under Maybe.

witMaybe :: (Witness p q t, p) => Maybe t -> (q => Maybe r) -> Maybe r -> Maybe r Source

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

(=?=) :: TestEquality f => f a -> f b -> Maybe (a :~: b) infix 4 Source

class TestEquality1 f where Source

Methods

testEquality1 :: f a c -> f b c -> Maybe (a :~: b) Source

Instances

TestEquality k1 f => TestEquality1 (k -> k) k ((:.:) k k f) Source 

(=??=) :: TestEquality1 f => f a c -> f b c -> Maybe (a :~: b) infix 4 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

DecEquality k f => DecEquality k ((:&:) k f g) Source 
(DecEquality k f, DecEquality k1 g) => DecEquality ((,) k k) ((:*:) k k f g) Source 

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

absurd :: Arrow p => p Void a Source