module Anoma.Balance;
import Anoma.Prelude open;
import Data.ByteString open;
import Anoma.Resource open;
import Anoma.Kind open;
import Data.Map as Map;
type Balance := balance : List (Kind × Int) -> Balance;
emptyBalance : Balance := balance nil;
addBalance : Balance -> Balance -> Balance
| (balance xs) (balance ys) :=
balance (Map.toList (Map.fromListWith (+) (xs ++ ys)));
negateBalance : Balance -> Balance
| (balance bs) := balance (map (b in bs) second neg b);
subBalance (b1 : Balance) (b2 : Balance) : Balance :=
addBalance b1 (negateBalance b2);
sumBalances (bs : List Balance) : Balance :=
for (acc := emptyBalance) (b in bs)
addBalance acc b;
balanceIsZero : Balance -> Bool
| (balance bs) := all (b in bs) snd b == 0;
Last modified on 2023-12-07 10:36 UTC