Skip to content

Instantly share code, notes, and snippets.

@ninegrid
Created March 6, 2018 04:17
Show Gist options
  • Save ninegrid/bf7cf54fd263edeb116a97f5aa68e954 to your computer and use it in GitHub Desktop.
Save ninegrid/bf7cf54fd263edeb116a97f5aa68e954 to your computer and use it in GitHub Desktop.
some agda
{-# OPTIONS --universe-polymorphism #-}
module mybool where
-- http://www.cse.chalmers.se/~ulfn/code/tphols09/ ⟡ ../tphols09/
--------------------------------------------------------------------------------
-- data types
--------------------------------------------------------------------------------
data 𝔹 : Set where
tt : 𝔹
ff : 𝔹
{-# BUILTIN BOOL 𝔹 #-}
{-# BUILTIN TRUE tt #-}
{-# BUILTIN FALSE ff #-}
{-# COMPILE GHC 𝔹 = data Bool (True | False) #-}
--------------------------------------------------------------------------------
-- syntax
--------------------------------------------------------------------------------
infix 7 ~_ Β¬_
infix 6 _nand_ _⊼_
infix 6 _&&_ _∧_
infix 6 _nor_ _⊽_
infix 6 _xor_ _βŠ•_
infix 5 _||_ _∨_
infix 4 if_then_else_
infix 4 if*_then_else_
infix 4 _β‡’_
--------------------------------------------------------------------------------
-- operations
--------------------------------------------------------------------------------
-- not
Β¬_ : 𝔹 β†’ 𝔹
Β¬ tt = ff
Β¬ ff = tt
~_ = Β¬_
-- nand
_⊼_ : 𝔹 β†’ 𝔹 β†’ 𝔹
tt ⊼ tt = ff
tt ⊼ ff = tt
ff ⊼ tt = tt
ff ⊼ ff = tt
_nand_ = _⊼_
-- and
_∧_ : 𝔹 β†’ 𝔹 β†’ 𝔹
tt ∧ b = b
ff ∧ b = ff
_&&_ = _∧_
-- xor
_βŠ•_ : 𝔹 β†’ 𝔹 β†’ 𝔹
tt βŠ• tt = ff
tt βŠ• ff = tt
ff βŠ• tt = tt
ff βŠ• ff = ff
_xor_ = _βŠ•_
-- or
_∨_ : 𝔹 β†’ 𝔹 β†’ 𝔹
tt ∨ b = tt
ff ∨ b = b
_||_ = _∨_
-- nor
_⊽_ : 𝔹 β†’ 𝔹 β†’ 𝔹
x ⊽ y = ¬ (x ∨ y)
_nor_ = _⊽_
-- if_then_else_
if_then_else_ : βˆ€ {β„“} {A : Set β„“} β†’ 𝔹 β†’ A β†’ A β†’ A
if tt then y else z = y
if ff then y else z = z
-- if*_then_else_
if*_then_else_ : βˆ€ {β„“} {A B : Set β„“} β†’ (b : 𝔹) β†’ A β†’ B β†’ if b then A else B
if* tt then a else b = a
if* ff then a else b = b
-- implies
_β‡’_ : 𝔹 β†’ 𝔹 β†’ 𝔹
tt β‡’ b = b -- b2?
ff β‡’ b = tt
_imp_ = _β‡’_
-- type inference: SPC m d
-- normalize expression: SPC m n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment