gdp-0.0.3.0: Reason about invariants and preconditions with ghosts of departed proofs.

Safe HaskellNone
LanguageHaskell2010

Logic.Implicit

Synopsis

Documentation

class Fact p Source #

A Fact p is an implicit proof of p, propagated by Haskell's constraint solver. Facts can be used to implicitly introduce or propagate proofs. However, there is a small run-time cost associated with using Facts: typeclass dictionaries for Facts are still passed around. In many cases they will be optimized away, but this is not guaranteed.

known :: Fact p => Proof p Source #

Recall a known Fact from the implicit context.

note :: forall p t. Proof p -> (Fact p => t) -> t Source #

Add a proof to the implicit context.

on :: Fact (p n) => (Proof (p n) -> Proof q) -> (a ~~ n) -> Proof q Source #

Apply an implication to a predicate in the implicit context. The (a ~~ n) parameter is not actually used; it's type is used to help select a specific fact from the context.

@ -- A safe head function, using an implicitly-passed safety proof. head :: Fact (IsCons xs) => ([a] ~~ xs) -> a head xs = Prelude.head (the xs)

  • - Reverse, and a lemma. reverse :: ([a] ~~ xs) -> ([a] ~~ Reverse xs) revConsLemma :: Proof (IsCons xs) -> Proof (IsCons (Reverse xs))
  • - Implement a safe last function. last :: Fact (IsCons xs) => ([a] ~~ xs) -> a last xs = note (revConsLemma on xs) $ head (reverse xs)