| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Util.Pred
Description
Self-explaining boolean predicates
These can be used to provide detailed counterexamples or witnesses for
boolean predicates that evaluate to False or True, respectively.
NOTE: to keep this as simple as possible, we do not perform any boolean simplifications (e.g., double negations, or De Morgan's laws) on the predicates while evauating them. This can be added later if needed.
Synopsis
- data Pred tag where
- (:=) ∷ ∀ tag. !tag → !(Pred tag) → Pred tag
- Bool ∷ ∀ tag. !Bool → Pred tag
- Not ∷ ∀ tag. !(Pred tag) → Pred tag
- (:>:) ∷ ∀ a tag. (Typeable a, Ord a, Show a) ⇒ !a → !a → Pred tag
- (:<=:) ∷ ∀ a tag. (Typeable a, Ord a, Show a) ⇒ !a → !a → Pred tag
- (:==:) ∷ ∀ a tag. (Typeable a, Eq a, Show a) ⇒ !a → !a → Pred tag
- (:/\:) ∷ ∀ tag. !(Pred tag) → !(Pred tag) → Pred tag
- (:\/:) ∷ ∀ tag. !(Pred tag) → !(Pred tag) → Pred tag
- data Evidence (res ∷ Bool) a where
- forgetEvidence ∷ ∀ (res ∷ Bool) a. Evidence res a → Bool
- evalPred ∷ Pred tag → (∀ (res ∷ Bool). Evidence res tag → r) → r
- class Explainable a where
- explain ∷ ExplanationMode → a → String
- explainPrec ∷ Int → ExplanationMode → a → String
- data ExplanationMode
- newtype ShowExplain a = ShowExplain a
- explainShallow ∷ Explainable a ⇒ a → String
- explainDeep ∷ Explainable a ⇒ a → String
Documentation
Constructors
| (:=) ∷ ∀ tag. !tag → !(Pred tag) → Pred tag infixr 2 | Tag a predicate with some metadata |
| Bool ∷ ∀ tag. !Bool → Pred tag | A concrete boolean value |
| Not ∷ ∀ tag. !(Pred tag) → Pred tag infixr 5 | Boolean negation |
| (:>:) ∷ ∀ a tag. (Typeable a, Ord a, Show a) ⇒ !a → !a → Pred tag infix 5 | Greater-than comparison |
| (:<=:) ∷ ∀ a tag. (Typeable a, Ord a, Show a) ⇒ !a → !a → Pred tag infix 5 | Less-than-or-equal comparison |
| (:==:) ∷ ∀ a tag. (Typeable a, Eq a, Show a) ⇒ !a → !a → Pred tag infix 5 | Equality comparison |
| (:/\:) ∷ ∀ tag. !(Pred tag) → !(Pred tag) → Pred tag infixr 4 | Conjunction |
| (:\/:) ∷ ∀ tag. !(Pred tag) → !(Pred tag) → Pred tag infixr 3 | Disjunction |
Instances
| Show tag ⇒ Show (Pred tag) Source # | |
| Eq tag ⇒ Eq (Pred tag) Source # | |
| Explainable a ⇒ Explainable (Pred a) Source # | |
Defined in Ouroboros.Consensus.Util.Pred Methods explain ∷ ExplanationMode → Pred a → String Source # explainPrec ∷ Int → ExplanationMode → Pred a → String Source # | |
data Evidence (res ∷ Bool) a where Source #
Sufficient evidence to show that a predicate is either true or false
forgetEvidence ∷ ∀ (res ∷ Bool) a. Evidence res a → Bool Source #
Forget the evidence payload, yielding just its corresponding boolean value
evalPred ∷ Pred tag → (∀ (res ∷ Bool). Evidence res tag → r) → r Source #
Evaluate a predicate, yielding either a counterexample or a witness.
The returned value contains the minimum (modulo conjunction/disjunction short circuiting) evidence needed to explain the outcome.
Some examples:
>>>data P = A | B | C deriving Show>>>a = A := Bool True -- a ~ True>>>b = B := 2+2 :==: 5 -- b ~ False>>>c = C := 10 :>: 5 -- c ~ True
>>>evalPred (a :/\: c) show -- success because both a~True and c~True"ETrue ((A := Bool True) :/\\: (C := 10 :>: 5))"
>>>evalPred (a :\/: b) show -- success because a~True, short-circuits"ETrue (A := Bool True)"
>>>evalPred (a :/\: b :/\: c) show -- failure because b~False, short-circuits"EFalse (B := 4 :==: 5)"
>>>evalPred ((b :\/: a) :/\: (b :\/: c)) show -- success because of a~True and c~True"ETrue ((A := Bool True) :/\\: (C := 10 :>: 5))"
>>>evalPred (b :\/: (Not c)) show -- failure because both b~False and c~True"EFalse ((B := 4 :==: 5) :\\/: Not (C := 10 :>: 5))"
>>>evalPred (Not (a :/\: b)) show -- success because b~False"ETrue (Not (B := 4 :==: 5))"
>>>evalPred (Not (a :/\: c)) show -- failure because both a~True and c~True"EFalse (Not ((A := Bool True) :/\\: (C := 10 :>: 5)))"
class Explainable a where Source #
Provides a human-readable explanation for a value
Minimal complete definition
(explain | explainPrec)
Methods
explain ∷ ExplanationMode → a → String Source #
explainPrec ∷ Int → ExplanationMode → a → String Source #
Instances
data ExplanationMode Source #
Explanation mode
Used to control whether we want to continue explaining terms beyond tags * Shallow: only explain tags * Deep: explain full predicates
Instances
| Show ExplanationMode Source # | |
Defined in Ouroboros.Consensus.Util.Pred Methods showsPrec ∷ Int → ExplanationMode → ShowS # show ∷ ExplanationMode → String # showList ∷ [ExplanationMode] → ShowS # | |
| Eq ExplanationMode Source # | |
Defined in Ouroboros.Consensus.Util.Pred Methods (==) ∷ ExplanationMode → ExplanationMode → Bool # (/=) ∷ ExplanationMode → ExplanationMode → Bool # | |
newtype ShowExplain a Source #
Default Explainable instance via Show to be used with 'deriving via'
Constructors
| ShowExplain a |
Instances
| Show a ⇒ Show (ShowExplain a) Source # | |
Defined in Ouroboros.Consensus.Util.Pred Methods showsPrec ∷ Int → ShowExplain a → ShowS # show ∷ ShowExplain a → String # showList ∷ [ShowExplain a] → ShowS # | |
| Show a ⇒ Explainable (ShowExplain a) Source # | |
Defined in Ouroboros.Consensus.Util.Pred Methods explain ∷ ExplanationMode → ShowExplain a → String Source # explainPrec ∷ Int → ExplanationMode → ShowExplain a → String Source # | |
explainShallow ∷ Explainable a ⇒ a → String Source #
Shallow explanation
explainDeep ∷ Explainable a ⇒ a → String Source #
Deep explanation