@@ -28,11 +28,11 @@ class (MonetaryTypes mt, Eq mu) =>
2828 MonetaryUnit mt mu | mu -> mt where
2929 settle :: t ~ MT_TIME mt => t -> mu -> mu
3030 settledAt :: t ~ MT_TIME mt => mu -> t
31- flowRate :: fr ~ MT_FLOWRATE mt => mu -> fr
31+ flowRate :: MonetaryTypes'tr mt t fr => mu -> t -> fr
3232 rtb :: MonetaryTypes'tvr mt t v fr => mu -> t -> v
3333
3434-- | An indexed monetary value and its operators (1-primitives).
35- class (MonetaryUnit mt iv , Monoid iv , Eq iv ) =>
35+ class (MonetaryUnit mt iv , Monoid iv ) =>
3636 IndexedValue mt iv | iv -> mt where
3737 shift1 :: v ~ MT_VALUE mt => v -> iv -> (iv , v )
3838 flow1 :: fr ~ MT_FLOWRATE mt => fr -> iv -> (iv , fr )
@@ -57,7 +57,7 @@ flow2a, flow2b ::
5757 (MonetaryTypes'tr mt t fr , IndexedValue mt a , IndexedValue mt b ) =>
5858 fr -> t -> (a , b ) -> (a , b )
5959flow2a dfr t (a, b) =
60- let (b1, fr_a) = flow1 (flowRate a) (settle t mempty )
60+ let (b1, fr_a) = flow1 (flowRate a t ) (settle t mempty )
6161 (b2, fr_a') = flow1 (- fr_a + dfr) (settle t mempty )
6262 (a', fr_a'') = flow1 (- fr_a') (settle t a)
6363 in assert (fr_a' == - fr_a'') (a', b <> b1 <> b2)
@@ -70,13 +70,13 @@ flow2b dfr t (a, b) = swap (flow2a (-dfr) t (b, a))
7070-- 2) The adjustment must not produce new error term, or otherwise it would require recursive adjustments.
7171align2a , align2b ::
7272 (IndexedValue mt a , IndexedValue mt b ) =>
73- MT_UNIT mt -> MT_UNIT mt -> (a , b ) -> (a , b )
74- align2a u u' (a, b) = (a', b')
75- where fr = flowRate a
73+ MT_UNIT mt -> MT_UNIT mt -> MT_TIME mt -> (a , b ) -> (a , b )
74+ align2a u u' t (a, b) = (a', b')
75+ where fr = flowRate a t
7676 (fr', e) = if u' == 0 then (0 , fr `mt_fr_mul_u` u) else fr `mt_fr_mul_u_qr_u` (u, u')
7777 a' = fst (flow1 fr' a)
78- b' = fst (flow1 (e + flowRate b) b)
79- align2b u u' (a, b) = swap (align2a u u' (b, a))
78+ b' = fst (flow1 (e + flowRate b t ) b)
79+ align2b u u' t (a, b) = swap (align2a u u' t (b, a))
8080
8181------------------------------------------------------------------------------------------------------------------------
8282-- Basic Particle: building block for indexes
@@ -94,7 +94,7 @@ instance MonetaryTypes mt => Semigroup (BasicParticle mt) where
9494 a@ (BasicParticle t1 _ _) <> b@ (BasicParticle t2 _ _) = BasicParticle t' (sv1 + sv2) (r1 + r2)
9595 -- The binary operator supports negative time values while abiding the monoidal laws.
9696 -- The practical semantics of values of mixed-sign is not of the concern of this specification.
97- where t' | t1 == 0 = t2 | t2 == 0 = t1 | otherwise = max t1 t2
97+ where t' = max t1 t2
9898 (BasicParticle _ sv1 r1) = settle t' a
9999 (BasicParticle _ sv2 r2) = settle t' b
100100
@@ -107,7 +107,7 @@ instance MonetaryTypes mt =>
107107 , bp_settled_value = rtb a t'
108108 }
109109 settledAt = bp_settled_at
110- flowRate = bp_flow_rate
110+ flowRate = const . bp_flow_rate
111111 rtb (BasicParticle t s r) t' = r `mt_fr_mul_t` (t' - t) + s
112112
113113instance MonetaryTypes mt =>
@@ -142,7 +142,7 @@ pdp_UpdateMember2 ::
142142pdp_UpdateMember2 u' t' (a, (b, pm)) = (a'', (b'', pm''))
143143 where (PDP_Index tu mpi, pm'@ (PDP_Member u _ _)) = settle t' (b, pm)
144144 tu' = tu + u' - u
145- (mpi', a'') = align2b tu tu' (mpi, settle t' a)
145+ (mpi', a'') = align2b tu tu' t' (mpi, settle t' a)
146146 b'' = PDP_Index tu' mpi'
147147 pm'' = pm' { pdpm_owned_unit = u', pdpm_synced_wp = mpi' }
148148
@@ -199,7 +199,7 @@ instance MonetaryUnit mt wp =>
199199
200200 settledAt (_, PDP_Member _ _ mps) = settledAt mps
201201
202- flowRate (PDP_Index _ mpi, PDP_Member u _ _) = flowRate mpi `mt_fr_mul_u` u
202+ flowRate (PDP_Index _ mpi, PDP_Member u _ _) t = flowRate mpi t `mt_fr_mul_u` u
203203
204204 rtb (PDP_Index _ mpi, PDP_Member u sv mps) t' = sv +
205205 -- let ti = bp_settled_at mpi
0 commit comments