std:Bool

lib/Bool.omg

lib/Bool.omg39 lines
1{-  Booleans.
2
3    `Bool` is a builtin type with the literals `True` and `False`, the
4    operators `&&`, `||`, `==` and `!=`, and `if ... then ... else ...`.
5    Its dependent eliminator is the builtin `Bool/elim`.
6-}
7
8let not : Bool -> Bool = \b -> if b then False else True
9
10let and : Bool -> Bool -> Bool = \a b -> a && b
11
12let or : Bool -> Bool -> Bool = \a b -> a || b
13
14let xor : Bool -> Bool -> Bool = \a b -> a != b
15
16-- fold b t f = if b then t else f
17let fold
18    : forall {l : Level} {a : Type l} -> Bool -> a -> a -> a
19    = \b t f -> if b then t else f
20
21let show : Bool -> Text = \b -> if b then "True" else "False"
22
23-- Are all the elements of the list `True`?
24let all
25    : List Bool -> Bool
26    = List/elim
27        (\(_ : List Bool) -> Bool)
28        True
29        (\(b : Bool) (_ : List Bool) (rest : Bool) -> b && rest)
30
31-- Is at least one element of the list `True`?
32let any
33    : List Bool -> Bool
34    = List/elim
35        (\(_ : List Bool) -> Bool)
36        False
37        (\(b : Bool) (_ : List Bool) (rest : Bool) -> b || rest)
38
39in  { not, and, or, xor, fold, show, all, any }
Your result
Complete file: lib/Bool.omg · with imports