Copyright | (C) 2011-2012 Edward Kmett, |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Data.Constraint
Description
- data Constraint :: BOX
- data Dict :: Constraint -> * where
- newtype a :- b = Sub (a => Dict b)
- (\\) :: a => (b => r) -> (a :- b) -> r
- weaken1 :: (a, b) :- a
- weaken2 :: (a, b) :- b
- contract :: a :- (a, a)
- (&&&) :: (a :- b) -> (a :- c) -> a :- (b, c)
- (***) :: (a :- b) -> (c :- d) -> (a, c) :- (b, d)
- trans :: (b :- c) -> (a :- b) -> a :- c
- refl :: a :- a
- top :: a :- ()
- class Class b h | h -> b where
- class b :=> h | h -> b where
Constraints
data Constraint :: BOX
Dictionary
data Dict :: Constraint -> * where
Capture a dictionary for a given constraint
Entailment
newtype a :- b infixr 9
(\\) :: a => (b => r) -> (a :- b) -> r infixl 1
Given that a :- b
, derive something that needs a context b
, using the context a
(&&&) :: (a :- b) -> (a :- c) -> a :- (b, c)
Constraint product
trans weaken1 (f &&& g) = f trans weaken2 (f &&& g) = g
(***) :: (a :- b) -> (c :- d) -> (a, c) :- (b, d)
due to the hack for the kind of (,) in the current version of GHC we can't actually make instances for (,) :: Constraint -> Constraint -> Constraint
trans :: (b :- c) -> (a :- b) -> a :- c
Transitivity of entailment
If we view '(:-)' as a Constraint-indexed category, then this is '(.)'
Reflexivity of entailment
If we view '(:-)' as a Constraint-indexed category, then this is id
Every constraint implies truth
These are the terminal arrows of the category, and () is the terminal object.
Reflection
class Class b h | h -> b where
Reify the relationship between a class and its superclass constraints as a class
Instances
Class () () | |
Class () (Bounded a) | |
Class () (Enum a) | |
Class () (Eq a) | |
Class () (Monad f) | |
Class () (Functor f) | |
Class () (Num a) | |
Class () (Read a) | |
Class () (Show a) | |
Class () (Monoid a) | |
Class b a => () :=> (Class b a) | |
Class () ((:=>) b a) | |
Class () (Class b a) | |
Class (Eq a) (Ord a) | |
Class (Fractional a) (Floating a) | |
Class (Monad f) (MonadPlus f) | |
Class (Functor f) (Applicative f) | |
Class (Num a) (Fractional a) | |
Class (Applicative f) (Alternative f) | |
Class (Num a, Ord a) (Real a) | |
Class (Real a, Fractional a) (RealFrac a) | |
Class (Real a, Enum a) (Integral a) | |
Class (RealFrac a, Floating a) (RealFloat a) |
class b :=> h | h -> b where infixr 9
Reify the relationship between an instance head and its body as a class
Instances