Skip to content

Commit 10aaed6

Browse files
authored
Merge pull request #48 from purescript/reorg-modules
Add new module Type.RowList
2 parents f5b3b0d + 62d08b1 commit 10aaed6

File tree

4 files changed

+98
-94
lines changed

4 files changed

+98
-94
lines changed

src/Type/Prelude.purs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ module Type.Prelude
55
, module Type.Equality
66
, module Type.Proxy
77
, module Type.Row
8+
, module Type.RowList
89
) where
910

1011
import Type.Data.Boolean (kind Boolean, True, False, BProxy(..), class IsBoolean, reflectBoolean, reifyBoolean)
1112
import Type.Data.Ordering (kind Ordering, LT, EQ, GT, OProxy(..), class IsOrdering, reflectOrdering, reifyOrdering)
1213
import Type.Proxy (Proxy(..))
1314
import Type.Data.Symbol (SProxy(..), class IsSymbol, reflectSymbol, reifySymbol, class Compare, compare, class Append, append)
1415
import Type.Equality (class TypeEquals, from, to)
15-
import Type.Row (class Union, class Lacks, class RowToList, class ListToRow, RProxy(..), RLProxy(..))
16-
16+
import Type.Row (class Union, class Lacks, RProxy(..))
17+
import Type.RowList (class RowToList, class ListToRow, RLProxy(..))

src/Type/Row.purs

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,12 @@
11
module Type.Row
22
( module Prim.Row
33
, module RProxy
4-
, module Prim.RowList
5-
, module RLProxy
6-
, class ListToRow
7-
, class RowListRemove
8-
, class RowListSet
9-
, class RowListNub
10-
, class RowListAppend
114
, RowApply
125
, type (+)
136
) where
147

158
import Prim.Row (class Lacks, class Nub, class Cons, class Union)
16-
import Prim.RowList (kind RowList, Cons, Nil, class RowToList)
17-
import Type.Equality (class TypeEquals)
18-
import Type.Data.Symbol as Symbol
19-
import Type.Data.Boolean as Boolean
209
import Type.Data.Row (RProxy(..)) as RProxy
21-
import Type.Data.RowList (RLProxy)
22-
import Type.Data.RowList (RLProxy(..)) as RLProxy
23-
24-
25-
-- | Convert a RowList to a row of types.
26-
-- | The inverse of this operation is `RowToList`.
27-
class ListToRow (list :: RowList)
28-
(row :: # Type) |
29-
list -> row
30-
31-
instance listToRowNil
32-
:: ListToRow Nil ()
33-
34-
instance listToCons
35-
:: ( ListToRow tail tailRow
36-
, Cons label ty tailRow row )
37-
=> ListToRow (Cons label ty tail) row
38-
39-
-- | Remove all occurences of a given label from a RowList
40-
class RowListRemove (label :: Symbol)
41-
(input :: RowList)
42-
(output :: RowList)
43-
| label input -> output
44-
45-
instance rowListRemoveNil
46-
:: RowListRemove label Nil Nil
47-
48-
instance rowListRemoveCons
49-
:: ( RowListRemove label tail tailOutput
50-
, Symbol.Equals label key eq
51-
, Boolean.If eq
52-
(RLProxy tailOutput)
53-
(RLProxy (Cons key head tailOutput))
54-
(RLProxy output)
55-
)
56-
=> RowListRemove label (Cons key head tail) output
57-
58-
-- | Add a label to a RowList after removing other occurences.
59-
class RowListSet (label :: Symbol)
60-
(typ :: Type)
61-
(input :: RowList)
62-
(output :: RowList)
63-
| label typ input -> output
64-
65-
instance rowListSetImpl
66-
:: ( TypeEquals (Symbol.SProxy label) (Symbol.SProxy label')
67-
, TypeEquals typ typ'
68-
, RowListRemove label input lacking )
69-
=> RowListSet label typ input (Cons label' typ' lacking)
70-
71-
-- | Remove label duplicates, keeps earlier occurrences.
72-
class RowListNub (input :: RowList)
73-
(output :: RowList)
74-
| input -> output
75-
76-
instance rowListNubNil
77-
:: RowListNub Nil Nil
78-
79-
instance rowListNubCons
80-
:: ( TypeEquals (Symbol.SProxy label) (Symbol.SProxy label')
81-
, TypeEquals head head'
82-
, TypeEquals (RLProxy nubbed) (RLProxy nubbed')
83-
, RowListRemove label tail removed
84-
, RowListNub removed nubbed )
85-
=> RowListNub (Cons label head tail) (Cons label' head' nubbed')
86-
87-
-- Append two row lists together
88-
class RowListAppend (lhs :: RowList)
89-
(rhs :: RowList)
90-
(out :: RowList)
91-
| lhs rhs -> out
92-
93-
instance rowListAppendNil
94-
:: TypeEquals (RLProxy rhs) (RLProxy out)
95-
=> RowListAppend Nil rhs out
96-
97-
instance rowListAppendCons
98-
:: ( RowListAppend tail rhs out'
99-
, TypeEquals (RLProxy (Cons label head out')) (RLProxy out) )
100-
=> RowListAppend (Cons label head tail) rhs out
10110

10211
-- | Type application for rows.
10312
type RowApply (f :: # Type -> # Type) (a :: # Type) = f a

src/Type/Row/Homogeneous.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Type.Row.Homogeneous
44
) where
55

66
import Type.Equality (class TypeEquals)
7-
import Type.Row (class RowToList, Cons, Nil, kind RowList)
7+
import Type.RowList (class RowToList, Cons, Nil, kind RowList)
88

99
-- | Ensure that every field in a row has the same type.
1010
class Homogeneous (row :: # Type) fieldType | row -> fieldType

src/Type/RowList.purs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
module Type.RowList
2+
( module Prim.RowList
3+
, module RLProxy
4+
, class ListToRow
5+
, class RowListRemove
6+
, class RowListSet
7+
, class RowListNub
8+
, class RowListAppend
9+
) where
10+
11+
import Prim.Row as Row
12+
import Prim.RowList (kind RowList, Cons, Nil, class RowToList)
13+
import Type.Equality (class TypeEquals)
14+
import Type.Data.Symbol as Symbol
15+
import Type.Data.Boolean as Boolean
16+
import Type.Data.RowList (RLProxy)
17+
import Type.Data.RowList (RLProxy(..)) as RLProxy
18+
19+
-- | Convert a RowList to a row of types.
20+
-- | The inverse of this operation is `RowToList`.
21+
class ListToRow (list :: RowList)
22+
(row :: # Type) |
23+
list -> row
24+
25+
instance listToRowNil
26+
:: ListToRow Nil ()
27+
28+
instance listToRowCons
29+
:: ( ListToRow tail tailRow
30+
, Row.Cons label ty tailRow row )
31+
=> ListToRow (Cons label ty tail) row
32+
33+
-- | Remove all occurences of a given label from a RowList
34+
class RowListRemove (label :: Symbol)
35+
(input :: RowList)
36+
(output :: RowList)
37+
| label input -> output
38+
39+
instance rowListRemoveNil
40+
:: RowListRemove label Nil Nil
41+
42+
instance rowListRemoveCons
43+
:: ( RowListRemove label tail tailOutput
44+
, Symbol.Equals label key eq
45+
, Boolean.If eq
46+
(RLProxy tailOutput)
47+
(RLProxy (Cons key head tailOutput))
48+
(RLProxy output)
49+
)
50+
=> RowListRemove label (Cons key head tail) output
51+
52+
-- | Add a label to a RowList after removing other occurences.
53+
class RowListSet (label :: Symbol)
54+
(typ :: Type)
55+
(input :: RowList)
56+
(output :: RowList)
57+
| label typ input -> output
58+
59+
instance rowListSetImpl
60+
:: ( TypeEquals (Symbol.SProxy label) (Symbol.SProxy label')
61+
, TypeEquals typ typ'
62+
, RowListRemove label input lacking )
63+
=> RowListSet label typ input (Cons label' typ' lacking)
64+
65+
-- | Remove label duplicates, keeps earlier occurrences.
66+
class RowListNub (input :: RowList)
67+
(output :: RowList)
68+
| input -> output
69+
70+
instance rowListNubNil
71+
:: RowListNub Nil Nil
72+
73+
instance rowListNubCons
74+
:: ( TypeEquals (Symbol.SProxy label) (Symbol.SProxy label')
75+
, TypeEquals head head'
76+
, TypeEquals (RLProxy nubbed) (RLProxy nubbed')
77+
, RowListRemove label tail removed
78+
, RowListNub removed nubbed )
79+
=> RowListNub (Cons label head tail) (Cons label' head' nubbed')
80+
81+
-- Append two row lists together
82+
class RowListAppend (lhs :: RowList)
83+
(rhs :: RowList)
84+
(out :: RowList)
85+
| lhs rhs -> out
86+
87+
instance rowListAppendNil
88+
:: TypeEquals (RLProxy rhs) (RLProxy out)
89+
=> RowListAppend Nil rhs out
90+
91+
instance rowListAppendCons
92+
:: ( RowListAppend tail rhs out'
93+
, TypeEquals (RLProxy (Cons label head out')) (RLProxy out) )
94+
=> RowListAppend (Cons label head tail) rhs out

0 commit comments

Comments
 (0)