@@ -8,8 +8,16 @@ module Type.Row
8
8
, RLProxy (..)
9
9
, class RowToList
10
10
, class ListToRow
11
+ , class RowListRemove
12
+ , class RowListSet
13
+ , class RowListNub
14
+ , class RowListAppend
11
15
) where
12
16
17
+ import Type.Equality (class TypeEquals )
18
+ import Type.Data.Symbol as Symbol
19
+ import Type.Data.Boolean as Boolean
20
+
13
21
data RProxy (row :: # Type ) = RProxy
14
22
15
23
-- Must not be exported
@@ -70,3 +78,67 @@ instance listToRowCons
70
78
:: ( ListToRow tail tailRow
71
79
, RowCons label ty tailRow row )
72
80
=> ListToRow (Cons label ty tail ) row
81
+
82
+ -- | Remove all occurences of a given label from a RowList
83
+ class RowListRemove (label :: Symbol )
84
+ (input :: RowList )
85
+ (output :: RowList )
86
+ | label input -> output
87
+
88
+ instance rowListRemoveNil
89
+ :: RowListRemove label Nil Nil
90
+
91
+ instance rowListRemoveCons
92
+ :: ( RowListRemove label tail tailOutput
93
+ , Symbol.Equals label key eq
94
+ , Boolean.If eq
95
+ (RLProxy tailOutput )
96
+ (RLProxy (Cons key head tailOutput ))
97
+ (RLProxy output )
98
+ )
99
+ => RowListRemove label (Cons key head tail ) output
100
+
101
+ -- | Add a label to a RowList after removing other occurences.
102
+ class RowListSet (label :: Symbol )
103
+ (typ :: Type )
104
+ (input :: RowList )
105
+ (output :: RowList )
106
+ | label typ input -> output
107
+
108
+ instance rowListSetImpl
109
+ :: ( TypeEquals (Symbol.SProxy label ) (Symbol.SProxy label' )
110
+ , TypeEquals typ typ'
111
+ , RowListRemove label input lacking )
112
+ => RowListSet label typ input (Cons label' typ' lacking )
113
+
114
+ -- | Remove label duplicates, keeps earlier occurrences.
115
+ class RowListNub (input :: RowList )
116
+ (output :: RowList )
117
+ | input -> output
118
+
119
+ instance rowListNubNil
120
+ :: RowListNub Nil Nil
121
+
122
+ instance rowListNubCons
123
+ :: ( TypeEquals (Symbol.SProxy label ) (Symbol.SProxy label' )
124
+ , TypeEquals head head'
125
+ , TypeEquals (RLProxy nubbed ) (RLProxy nubbed' )
126
+ , RowListRemove label tail removed
127
+ , RowListNub removed nubbed )
128
+ => RowListNub (Cons label head tail ) (Cons label' head' nubbed' )
129
+
130
+ -- Append two row lists together
131
+ class RowListAppend (lhs :: RowList )
132
+ (rhs :: RowList )
133
+ (out :: RowList )
134
+ | lhs rhs -> out
135
+
136
+ instance rowListAppendNil
137
+ :: TypeEquals (RLProxy rhs ) (RLProxy out )
138
+ => RowListAppend Nil rhs out
139
+
140
+ instance rowListAppendCons
141
+ :: ( RowListAppend tail rhs out'
142
+ , TypeEquals (RLProxy (Cons label head out' )) (RLProxy out ) )
143
+ => RowListAppend (Cons label head tail ) rhs out
144
+
0 commit comments