Skip to content

Instantly share code, notes, and snippets.

@sivawashere
Created December 6, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivawashere/dabeff9fed2ac8b68cc2 to your computer and use it in GitHub Desktop.
Save sivawashere/dabeff9fed2ac8b68cc2 to your computer and use it in GitHub Desktop.
Partially implements a natural deduction system in Haskell
{-# LANGUAGE TypeOperators #-}
module NaturalDeduction where
data (⊥) -- no inhabitants
type (¬)p = p -> (⊥)
type (∧) = (,)
type (∨) = Either
type (→) = (->)
modusTollens :: (p → q) ∧ (¬)q → (¬)p
modusTollens (φ, ψ) = ψ . φ
true :: truth
true = true
exclMid :: p ∧ (¬)p
exclMid = true
type p ↔ q = (p → q) ∧ (q → p)
dblNeg :: p ↔ (¬)((¬) p)
dblNeg = (flip ($), true)
transposition :: (p → q) ↔ ((¬)q → (¬)p)
transposition =
(curry modusTollens, \c p -> -- c = contrapositive
undoDblNegate $ curry modusTollens c $ dblNegate p)
where (dblNegate, undoDblNegate) = dblNeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment