@@ -70,52 +70,33 @@ type NewMoneyTags lhs rhs =
70
70
MoneyTags lhs
71
71
)
72
72
73
- data Money tags where
74
- Money ::
75
- forall tags .
76
- ( MoneyTags tags
77
- ) =>
78
- Ratio (IntRep tags ) ->
79
- Money tags
80
-
81
- deriving stock instance Eq (Money tags )
82
-
83
- deriving stock instance Ord (Money tags )
84
-
85
- deriving stock instance (MoneyTags tags ) => Show (Money tags )
86
-
87
- deriving stock instance (MoneyTags tags ) => Read (Money tags )
88
-
89
- deriving stock instance (MoneyTags tags ) => Data (Money tags )
73
+ type Money tags = Tagged tags (Ratio (IntRep tags ))
90
74
91
75
unMoney :: Money tags -> Ratio (IntRep tags )
92
- unMoney (Money x) = x
76
+ unMoney (Tagged x) = x
93
77
94
78
tagMoney ::
95
- forall prevTag prevTags nextTags .
96
- ( NewMoneyTags nextTags (prevTags |+| prevTag ),
97
- IntRep prevTags ~ IntRep nextTags
79
+ forall tag tags .
80
+ ( IntRep tags ~ IntRep (tags |+| tag )
98
81
) =>
99
- Money prevTags ->
100
- Money nextTags
82
+ Money tags ->
83
+ Money ( tags |+| tag )
101
84
tagMoney = newMoney . unMoney
102
85
103
86
unTagMoney ::
104
- forall prevTag prevTags nextTags .
105
- ( NewMoneyTags nextTags (prevTags |-| prevTag ),
106
- IntRep prevTags ~ IntRep nextTags
87
+ forall tag tags .
88
+ ( IntRep tags ~ IntRep (tags |-| tag )
107
89
) =>
108
- Money prevTags ->
109
- Money nextTags
90
+ Money tags ->
91
+ Money ( tags |-| tag )
110
92
unTagMoney = newMoney . unMoney
111
93
112
94
reTagMoney ::
113
- forall prevTag nextTag prevTags nextTags .
114
- ( NewMoneyTags nextTags (prevTags |-| prevTag |+| nextTag ),
115
- IntRep prevTags ~ IntRep nextTags
95
+ forall prev next tags .
96
+ ( IntRep tags ~ IntRep (tags |-| prev |+| next )
116
97
) =>
117
- Money prevTags ->
118
- Money nextTags
98
+ Money tags ->
99
+ Money ( tags |-| prev |+| next )
119
100
reTagMoney = newMoney . unMoney
120
101
121
102
parseMoney ::
@@ -129,7 +110,7 @@ parseMoney ::
129
110
str ->
130
111
m (Money tags )
131
112
parseMoney =
132
- fmap Money . parseRatio
113
+ fmap Tagged . parseRatio
133
114
134
115
addMoney :: (MoneyTags tags ) => Money tags -> Money tags -> Money tags
135
116
addMoney lhs rhs =
@@ -160,11 +141,9 @@ deriving stock instance Show (SomeMoney k tags)
160
141
161
142
newMoney ::
162
143
forall tags .
163
- ( MoneyTags tags
164
- ) =>
165
144
Ratio (IntRep tags ) ->
166
145
Money tags
167
- newMoney = Money
146
+ newMoney = Tagged
168
147
169
148
newUnsignedMoneyBOS ::
170
149
forall tags buy sell .
@@ -176,8 +155,8 @@ newUnsignedMoneyBOS ::
176
155
Rational ->
177
156
SomeMoney BuyOrSell (tags |+| 'Unsigned)
178
157
newUnsignedMoneyBOS raw
179
- | raw < 0 = SomeMoney (sing :: Sing 'Sell) (Money uns :: Money sell )
180
- | otherwise = SomeMoney (sing :: Sing 'Buy) (Money uns :: Money buy )
158
+ | raw < 0 = SomeMoney (sing :: Sing 'Sell) (Tagged uns :: Money sell )
159
+ | otherwise = SomeMoney (sing :: Sing 'Buy) (Tagged uns :: Money buy )
181
160
where
182
161
uns = unsafeFrom @ Rational @ (Ratio Natural ) $ abs raw
183
162
@@ -191,26 +170,22 @@ newUnsignedMoneyGOL ::
191
170
Rational ->
192
171
SomeMoney GainOrLose (tags |+| 'Unsigned)
193
172
newUnsignedMoneyGOL raw
194
- | raw < 0 = SomeMoney (sing :: Sing 'Lose) (Money uns :: Money lose )
195
- | otherwise = SomeMoney (sing :: Sing 'Gain) (Money uns :: Money gain )
173
+ | raw < 0 = SomeMoney (sing :: Sing 'Lose) (Tagged uns :: Money lose )
174
+ | otherwise = SomeMoney (sing :: Sing 'Gain) (Tagged uns :: Money gain )
196
175
where
197
176
uns = unsafeFrom @ Rational @ (Ratio Natural ) $ abs raw
198
177
199
178
newFeeRate ::
200
- forall prev next .
201
- ( NewMoneyTags next (prev |+| 'FeeRate)
202
- ) =>
203
- Ratio (IntRep next ) ->
204
- Money next
205
- newFeeRate = Money
179
+ forall tags .
180
+ Ratio (IntRep (tags |+| 'FeeRate)) ->
181
+ Money (tags |+| 'FeeRate)
182
+ newFeeRate = Tagged
206
183
207
184
newProfitRate ::
208
- forall prev next .
209
- ( NewMoneyTags next (prev |+| 'ProfitRate)
210
- ) =>
211
- Ratio (IntRep next ) ->
212
- Money next
213
- newProfitRate = Money
185
+ forall tags .
186
+ Ratio (IntRep (tags |+| 'ProfitRate)) ->
187
+ Money (tags |+| 'ProfitRate)
188
+ newProfitRate = Tagged
214
189
215
190
addFee ::
216
191
forall fee amt tags .
@@ -221,8 +196,8 @@ addFee ::
221
196
Money fee ->
222
197
Money amt ->
223
198
Money tags
224
- addFee (Money fee) (Money amt) =
225
- Money $ amt / (1 - fee)
199
+ addFee (Tagged fee) (Tagged amt) =
200
+ Tagged $ amt / (1 - fee)
226
201
227
202
deductFee ::
228
203
forall fee amt tags .
@@ -233,8 +208,8 @@ deductFee ::
233
208
Money fee ->
234
209
Money amt ->
235
210
Money tags
236
- deductFee (Money fee) (Money amt) =
237
- Money $ amt * (1 - fee)
211
+ deductFee (Tagged fee) (Tagged amt) =
212
+ Tagged $ amt * (1 - fee)
238
213
239
214
addProfit ::
240
215
forall tags .
@@ -245,8 +220,8 @@ addProfit ::
245
220
Money (tags |+| 'ProfitRate) ->
246
221
Money tags ->
247
222
Money (tags |+| 'Revenue)
248
- addProfit (Money rate) (Money amt) =
249
- Money $ amt * (1 + rate)
223
+ addProfit (Tagged rate) (Tagged amt) =
224
+ Tagged $ amt * (1 + rate)
250
225
251
226
exchangeMoney ::
252
227
forall tags .
@@ -257,8 +232,8 @@ exchangeMoney ::
257
232
Money (tags |+| 'QuotePerBase) ->
258
233
Money (tags |+| 'Base) ->
259
234
Money (tags |+| 'Quote)
260
- exchangeMoney (Money rate) (Money base) =
261
- Money $ rate * base
235
+ exchangeMoney (Tagged rate) (Tagged base) =
236
+ Tagged $ rate * base
262
237
263
238
newQuotePerBase ::
264
239
forall tags .
@@ -269,11 +244,17 @@ newQuotePerBase ::
269
244
Money (tags |+| 'Quote) ->
270
245
Money (tags |+| 'Base) ->
271
246
Money (tags |+| 'QuotePerBase)
272
- newQuotePerBase (Money quote) (Money base) =
273
- Money $ quote / base
247
+ newQuotePerBase (Tagged quote) (Tagged base) =
248
+ Tagged $ quote / base
274
249
275
250
data Funds tags where
276
- Funds :: Money tags -> CurrencyCode -> Funds tags
251
+ Funds ::
252
+ forall tags .
253
+ ( MoneyTags tags
254
+ ) =>
255
+ Money tags ->
256
+ CurrencyCode ->
257
+ Funds tags
277
258
278
259
fundsMoneyAmount :: Funds tags -> Money tags
279
260
fundsMoneyAmount (Funds amt _) = amt
0 commit comments