Skip to content

Commit be0e74f

Browse files
committed
RefineTags combinator
1 parent b4e1984 commit be0e74f

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

pub/functora/src/money/Functora/Money.hs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,19 @@ type NewRatTags lhs rhs =
6565
RatTags lhs
6666
)
6767

68-
type family MoneyTagsFamily tags mtag where
69-
MoneyTagsFamily tags ('Just _) = tags
70-
MoneyTagsFamily tags ('Nothing :: Maybe k) =
71-
TypeError
72-
( 'ShowType k
73-
':<>: 'Text " key is missing in "
74-
':<>: 'ShowType tags
75-
)
76-
7768
type Money tags =
7869
Tagged
7970
tags
8071
( Ratio
8172
( IntRep
82-
( MoneyTagsFamily tags (MaybeGetTag MoneyKind tags)
73+
( RefineTags tags '[SignedOrUnsigned, MoneyKind]
8374
)
8475
)
8576
)
8677

8778
type MoneyTags tags =
8879
( RatTags tags,
89-
tags ~ MoneyTagsFamily tags (MaybeGetTag MoneyKind tags)
80+
tags ~ RefineTags tags '[SignedOrUnsigned, MoneyKind]
9081
)
9182

9283
type NewMoneyTags lhs rhs =

pub/functora/src/tags/Functora/TagsFamily.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Functora.TagsFamily
1515
MaybeGetTag,
1616
GetTag,
1717
HasTag,
18+
RefineTags,
1819

1920
-- * Fingerprints
2021
-- $fingerprints
@@ -82,6 +83,8 @@ type HasTag (v :: k) tags =
8283
v ~ GetTag k tags
8384
)
8485

86+
type RefineTags tags keys = RefineTagsFamily tags keys
87+
8588
-- $fingerprints
8689
-- Fingerprints
8790

@@ -188,6 +191,22 @@ type family GetTagFamily k tags mv where
188191
':<>: 'ShowType tags
189192
)
190193

194+
type family RefineTagsFamily tags keys where
195+
RefineTagsFamily tags '[] = tags
196+
RefineTagsFamily tags (k ': keys) =
197+
RefineTagsFamilyRec tags k keys (MaybeGetTag k tags)
198+
199+
type family RefineTagsFamilyRec tags k keys mv where
200+
RefineTagsFamilyRec tags _ '[] ('Just _) = tags
201+
RefineTagsFamilyRec tags _ (k ': keys) ('Just _) =
202+
RefineTagsFamilyRec tags k keys (MaybeGetTag k tags)
203+
RefineTagsFamilyRec tags k _ 'Nothing =
204+
TypeError
205+
( 'ShowType k
206+
':<>: 'Text " key is missing in "
207+
':<>: 'ShowType tags
208+
)
209+
191210
--
192211
-- TODO : NEED A PROPER INSTANCE!
193212
-- At the moment I don't know how to get

0 commit comments

Comments
 (0)