-
Notifications
You must be signed in to change notification settings - Fork 3
/
dk_bool.dk
57 lines (46 loc) · 1.03 KB
/
dk_bool.dk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#NAME dk_bool.
(; Bool ;)
(; Declaration ;)
bool : cc.uT.
def Bool : Type := cc.eT bool.
(; Constructors ;)
true : Bool.
false : Bool.
(; Pattern-matching ;)
def match :
P : (Bool -> cc.uT) ->
cc.eT (P true) ->
cc.eT (P false) ->
b : Bool ->
cc.eT (P b).
[Ht] match _ Ht _ true --> Ht
[Hf] match _ _ Hf false --> Hf.
(; Operations ;)
(; polymorphic if .. then .. else .. ;)
def ite :
A : cc.uT ->
Bool ->
cc.eT A ->
cc.eT A ->
cc.eT A.
[A,x,y,b]
ite A b x y
-->
match (b : Bool => A) x y b.
(; boolean if .. then .. else .. ;)
def iteb : Bool -> Bool -> Bool -> Bool
:= ite bool.
(; negation ;)
def not : Bool -> Bool.
[b] not b --> iteb b false true.
(; binary operators ;)
def and : Bool -> Bool -> Bool.
[x,y] and x y --> iteb x y false.
def or : Bool -> Bool -> Bool.
[x,y] or x y --> iteb x true y.
def xor : Bool -> Bool -> Bool.
[x,y] xor x y --> iteb x (not y) y.
def imp : Bool -> Bool -> Bool.
[x,y] imp x y --> iteb x y true.
def eqv : Bool -> Bool -> Bool.
[x,y] eqv x y --> iteb x y (not y).