Created
March 6, 2018 04:17
-
-
Save ninegrid/bf7cf54fd263edeb116a97f5aa68e954 to your computer and use it in GitHub Desktop.
some agda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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