|
1 | 1 | module Data.HeytingAlgebra |
2 | | - ( class HeytingAlgebra |
3 | | - |
4 | | - , tt |
5 | | - , ff |
6 | | - , implies |
7 | | - , conj |
8 | | - , disj |
9 | | - , not |
10 | | - , (&&) |
11 | | - , (||) |
12 | | - |
13 | | - , class HeytingAlgebraRow |
14 | | - , ffRecordImpl |
15 | | - , ttRecordImpl |
16 | | - , impliesRecordImpl |
17 | | - , conjRecordImpl |
18 | | - , disjRecordImpl |
19 | | - , notRecordImpl |
| 2 | + ( class HeytingAlgebra, tt, ff, implies, conj, disj, not, (&&), (||) |
| 3 | + , class HeytingAlgebraRecord, ffRecord, ttRecord, impliesRecord, conjRecord, disjRecord, notRecord |
20 | 4 | ) where |
21 | 5 |
|
22 | | -import Data.Internal.Record (unsafeGet, unsafeInsert) |
23 | 6 | import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol) |
24 | 7 | import Data.Unit (Unit, unit) |
25 | 8 | import Prim.Row as Row |
26 | 9 | import Prim.RowList as RL |
| 10 | +import Record.Unsafe (unsafeGet, unsafeSet) |
27 | 11 | import Type.Data.Row (RProxy(..)) |
28 | 12 | import Type.Data.RowList (RLProxy(..)) |
29 | 13 |
|
@@ -87,82 +71,80 @@ instance heytingAlgebraFunction :: HeytingAlgebra b => HeytingAlgebra (a -> b) w |
87 | 71 | disj f g a = f a || g a |
88 | 72 | not f a = not (f a) |
89 | 73 |
|
| 74 | +instance heytingAlgebraRecord :: (RL.RowToList row list, HeytingAlgebraRecord list row row) => HeytingAlgebra (Record row) where |
| 75 | + ff = ffRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row) |
| 76 | + tt = ttRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row) |
| 77 | + conj = conjRecord (RLProxy :: RLProxy list) |
| 78 | + disj = disjRecord (RLProxy :: RLProxy list) |
| 79 | + implies = impliesRecord (RLProxy :: RLProxy list) |
| 80 | + not = notRecord (RLProxy :: RLProxy list) |
| 81 | + |
90 | 82 | foreign import boolConj :: Boolean -> Boolean -> Boolean |
91 | 83 | foreign import boolDisj :: Boolean -> Boolean -> Boolean |
92 | 84 | foreign import boolNot :: Boolean -> Boolean |
93 | 85 |
|
94 | | -class HeytingAlgebraRow rowlist row subrow focus | rowlist -> subrow focus where |
95 | | - ffRecordImpl :: RLProxy rowlist -> RProxy row -> Record subrow |
96 | | - ttRecordImpl :: RLProxy rowlist -> RProxy row -> Record subrow |
97 | | - impliesRecordImpl :: RLProxy rowlist -> Record row -> Record row -> Record subrow |
98 | | - disjRecordImpl :: RLProxy rowlist -> Record row -> Record row -> Record subrow |
99 | | - conjRecordImpl :: RLProxy rowlist -> Record row -> Record row -> Record subrow |
100 | | - notRecordImpl :: RLProxy rowlist -> Record row -> Record subrow |
101 | | - |
102 | | -instance heytingAlgebraRowNil :: HeytingAlgebraRow RL.Nil row () focus where |
103 | | - conjRecordImpl _ _ _ = {} |
104 | | - disjRecordImpl _ _ _ = {} |
105 | | - ffRecordImpl _ _ = {} |
106 | | - impliesRecordImpl _ _ _ = {} |
107 | | - notRecordImpl _ _ = {} |
108 | | - ttRecordImpl _ _ = {} |
109 | | - |
110 | | -instance heytingAlgebraRowCons |
| 86 | +-- | A class for records where all fields have `HeytingAlgebra` instances, used |
| 87 | +-- | to implement the `HeytingAlgebra` instance for records. |
| 88 | +class HeytingAlgebraRecord rowlist row subrow | rowlist -> subrow where |
| 89 | + ffRecord :: RLProxy rowlist -> RProxy row -> Record subrow |
| 90 | + ttRecord :: RLProxy rowlist -> RProxy row -> Record subrow |
| 91 | + impliesRecord :: RLProxy rowlist -> Record row -> Record row -> Record subrow |
| 92 | + disjRecord :: RLProxy rowlist -> Record row -> Record row -> Record subrow |
| 93 | + conjRecord :: RLProxy rowlist -> Record row -> Record row -> Record subrow |
| 94 | + notRecord :: RLProxy rowlist -> Record row -> Record subrow |
| 95 | + |
| 96 | +instance heytingAlgebraRecordNil :: HeytingAlgebraRecord RL.Nil row () where |
| 97 | + conjRecord _ _ _ = {} |
| 98 | + disjRecord _ _ _ = {} |
| 99 | + ffRecord _ _ = {} |
| 100 | + impliesRecord _ _ _ = {} |
| 101 | + notRecord _ _ = {} |
| 102 | + ttRecord _ _ = {} |
| 103 | + |
| 104 | +instance heytingAlgebraRecordCons |
111 | 105 | :: ( IsSymbol key |
112 | 106 | , Row.Cons key focus subrowTail subrow |
113 | | - , HeytingAlgebraRow rowlistTail row subrowTail subfocus |
| 107 | + , HeytingAlgebraRecord rowlistTail row subrowTail |
114 | 108 | , HeytingAlgebra focus |
115 | 109 | ) |
116 | | - => HeytingAlgebraRow (RL.Cons key focus rowlistTail) row subrow focus where |
117 | | - conjRecordImpl _ ra rb = insert (conj (get ra) (get rb)) tail |
| 110 | + => HeytingAlgebraRecord (RL.Cons key focus rowlistTail) row subrow where |
| 111 | + conjRecord _ ra rb = insert (conj (get ra) (get rb)) tail |
118 | 112 | where |
119 | 113 | key = reflectSymbol (SProxy :: SProxy key) |
120 | 114 | get = unsafeGet key :: Record row -> focus |
121 | | - insert = unsafeInsert key :: focus -> Record subrowTail -> Record subrow |
122 | | - tail = conjRecordImpl (RLProxy :: RLProxy rowlistTail) ra rb |
| 115 | + insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow |
| 116 | + tail = conjRecord (RLProxy :: RLProxy rowlistTail) ra rb |
123 | 117 |
|
124 | | - disjRecordImpl _ ra rb = insert (disj (get ra) (get rb)) tail |
| 118 | + disjRecord _ ra rb = insert (disj (get ra) (get rb)) tail |
125 | 119 | where |
126 | 120 | key = reflectSymbol (SProxy :: SProxy key) |
127 | 121 | get = unsafeGet key :: Record row -> focus |
128 | | - insert = unsafeInsert key :: focus -> Record subrowTail -> Record subrow |
129 | | - tail = disjRecordImpl (RLProxy :: RLProxy rowlistTail) ra rb |
| 122 | + insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow |
| 123 | + tail = disjRecord (RLProxy :: RLProxy rowlistTail) ra rb |
130 | 124 |
|
131 | | - impliesRecordImpl _ ra rb = insert (implies (get ra) (get rb)) tail |
| 125 | + impliesRecord _ ra rb = insert (implies (get ra) (get rb)) tail |
132 | 126 | where |
133 | 127 | key = reflectSymbol (SProxy :: SProxy key) |
134 | 128 | get = unsafeGet key :: Record row -> focus |
135 | | - insert = unsafeInsert key :: focus -> Record subrowTail -> Record subrow |
136 | | - tail = impliesRecordImpl (RLProxy :: RLProxy rowlistTail) ra rb |
| 129 | + insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow |
| 130 | + tail = impliesRecord (RLProxy :: RLProxy rowlistTail) ra rb |
137 | 131 |
|
138 | | - ffRecordImpl _ row = insert ff tail |
| 132 | + ffRecord _ row = insert ff tail |
139 | 133 | where |
140 | 134 | key = reflectSymbol (SProxy :: SProxy key) |
141 | | - insert = unsafeInsert key :: focus -> Record subrowTail -> Record subrow |
142 | | - tail = ffRecordImpl (RLProxy :: RLProxy rowlistTail) row |
| 135 | + insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow |
| 136 | + tail = ffRecord (RLProxy :: RLProxy rowlistTail) row |
143 | 137 |
|
144 | | - notRecordImpl _ row |
| 138 | + notRecord _ row |
145 | 139 | = insert (not (get row)) tail |
146 | 140 | where |
147 | 141 | key = reflectSymbol (SProxy :: SProxy key) |
148 | 142 | get = unsafeGet key :: Record row -> focus |
149 | | - insert = unsafeInsert key :: focus -> Record subrowTail -> Record subrow |
150 | | - tail = notRecordImpl (RLProxy :: RLProxy rowlistTail) row |
| 143 | + insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow |
| 144 | + tail = notRecord (RLProxy :: RLProxy rowlistTail) row |
151 | 145 |
|
152 | | - ttRecordImpl _ row = insert tt tail |
| 146 | + ttRecord _ row = insert tt tail |
153 | 147 | where |
154 | 148 | key = reflectSymbol (SProxy :: SProxy key) |
155 | | - insert = unsafeInsert key :: focus -> Record subrowTail -> Record subrow |
156 | | - tail = ttRecordImpl (RLProxy :: RLProxy rowlistTail) row |
157 | | - |
158 | | -instance heytingAlgebraRecord |
159 | | - :: ( RL.RowToList row list |
160 | | - , HeytingAlgebraRow list row row focus |
161 | | - ) |
162 | | - => HeytingAlgebra (Record row) where |
163 | | - ff = ffRecordImpl (RLProxy :: RLProxy list) (RProxy :: RProxy row) |
164 | | - tt = ttRecordImpl (RLProxy :: RLProxy list) (RProxy :: RProxy row) |
165 | | - conj = conjRecordImpl (RLProxy :: RLProxy list) |
166 | | - disj = disjRecordImpl (RLProxy :: RLProxy list) |
167 | | - implies = impliesRecordImpl (RLProxy :: RLProxy list) |
168 | | - not = notRecordImpl (RLProxy :: RLProxy list) |
| 149 | + insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow |
| 150 | + tail = ttRecord (RLProxy :: RLProxy rowlistTail) row |
0 commit comments