|
1 | 1 | module Data.BooleanAlgebra
|
2 |
| - ( class BooleanAlgebra, conj, disj, not |
3 |
| - , (&&), (||) |
| 2 | + ( class BooleanAlgebra |
| 3 | + , module Data.HeytingAlgebra |
4 | 4 | ) where
|
5 | 5 |
|
6 |
| -import Data.Bounded (class Bounded) |
7 |
| -import Data.Unit (Unit, unit) |
| 6 | +import Data.HeytingAlgebra (class HeytingAlgebra, ff, tt, implies, conj, disj, not) |
| 7 | +import Data.Unit (Unit) |
8 | 8 |
|
9 | 9 | -- | The `BooleanAlgebra` type class represents types that behave like boolean
|
10 | 10 | -- | values.
|
11 | 11 | -- |
|
12 |
| --- | Instances should satisfy the following laws in addition to the `Bounded` |
13 |
| --- | laws: |
| 12 | +-- | Instances should satisfy the following laws in addition to the |
| 13 | +-- | `HeytingAlgebra` law: |
14 | 14 | -- |
|
15 |
| --- | - Associativity: |
16 |
| --- | - `a || (b || c) = (a || b) || c` |
17 |
| --- | - `a && (b && c) = (a && b) && c` |
18 |
| --- | - Commutativity: |
19 |
| --- | - `a || b = b || a` |
20 |
| --- | - `a && b = b && a` |
21 |
| --- | - Distributivity: |
22 |
| --- | - `a && (b || c) = (a && b) || (a && c)` |
23 |
| --- | - `a || (b && c) = (a || b) && (a || c)` |
24 |
| --- | - Identity: |
25 |
| --- | - `a || bottom = a` |
26 |
| --- | - `a && top = a` |
27 |
| --- | - Idempotent: |
28 |
| --- | - `a || a = a` |
29 |
| --- | - `a && a = a` |
30 |
| --- | - Absorption: |
31 |
| --- | - `a || (a && b) = a` |
32 |
| --- | - `a && (a || b) = a` |
33 |
| --- | - Annhiliation: |
34 |
| --- | - `a || top = top` |
35 |
| --- | - Complementation: |
36 |
| --- | - `a && not a = bottom` |
37 |
| --- | - `a || not a = top` |
38 |
| -class Bounded a <= BooleanAlgebra a where |
39 |
| - conj :: a -> a -> a |
40 |
| - disj :: a -> a -> a |
41 |
| - not :: a -> a |
| 15 | +-- | - Excluded middle: |
| 16 | +-- | - `a || not a = tt` |
| 17 | +class HeytingAlgebra a <= BooleanAlgebra a |
42 | 18 |
|
43 |
| -infixr 3 conj as && |
44 |
| -infixr 2 disj as || |
45 |
| - |
46 |
| -instance booleanAlgebraBoolean :: BooleanAlgebra Boolean where |
47 |
| - conj = boolConj |
48 |
| - disj = boolDisj |
49 |
| - not = boolNot |
50 |
| - |
51 |
| -instance booleanAlgebraUnit :: BooleanAlgebra Unit where |
52 |
| - conj _ _ = unit |
53 |
| - disj _ _ = unit |
54 |
| - not _ = unit |
55 |
| - |
56 |
| -instance booleanAlgebraFn :: BooleanAlgebra b => BooleanAlgebra (a -> b) where |
57 |
| - conj fx fy a = fx a `conj` fy a |
58 |
| - disj fx fy a = fx a `disj` fy a |
59 |
| - not fx a = not (fx a) |
60 |
| - |
61 |
| -foreign import boolConj :: Boolean -> Boolean -> Boolean |
62 |
| -foreign import boolDisj :: Boolean -> Boolean -> Boolean |
63 |
| -foreign import boolNot :: Boolean -> Boolean |
| 19 | +instance booleanAlgebraBoolean :: BooleanAlgebra Boolean |
| 20 | +instance booleanAlgebraUnit :: BooleanAlgebra Unit |
0 commit comments