-- | Penny quantities. A quantity is simply a count (possibly-- fractional) of something. It does not have a commodity or a-- Debit/Credit.modulePenny.Lincoln.Bits.Qty(Qty,unQty,partialNewQty,newQty,add,subt,mult,zero,Difference(LeftBiggerBy,RightBiggerBy,Equal),difference)whereimportData.Decimal(DecimalRaw(Decimal),Decimal)-- | A quantity is always greater than zero. Various odd questions-- happen if quantities can be zero. For instance, what if you have a-- debit whose quantity is zero? Does it require a balancing credit-- that is also zero? And how can you have a debit of zero anyway?---- I can imagine situations where a quantity of zero might be useful;-- for instance maybe you want to specifically indicate that a-- particular posting in a transaction did not happen (for instance,-- that a paycheck deduction did not take place). I think the better-- way to handle that though would be through an addition to-- Debit/Credit - maybe Debit/Credit/Zero. Barring the addition of-- that, though, the best way to indicate a situation such as this-- would be through transaction memos.newtypeQty=QtyDecimalderiving(Eq,Ord,Show)dataDifference=LeftBiggerByQty|RightBiggerByQty|Equal-- | Subtract the second Qty from the first.difference::Qty->Qty->Differencedifference(Qtyq1)(Qtyq2)=casecompareq1q2ofGT->LeftBiggerBy(Qty$q1-q2)LT->RightBiggerBy(Qty$q2-q1)EQ->Equal-- | Unwrap a Qty to get the underlying Decimal. This Decimal will-- always be greater than zero.unQty::Qty->DecimalunQty(Qtyd)=d-- | Make a new Qty. This function is partial. It will call error if-- its argument is less than or equal to zero.partialNewQty::Decimal->QtypartialNewQtyd=ifd<=0thenerror$"partialNewQty: argument less than or equal to zero: "++showdelseQtyd-- | Make a new Qty. Returns Nothing if its argument is less than-- zero.newQty::Decimal->MaybeQtynewQtyd=ifd<=0thenNothingelseJust(Qtyd)add::Qty->Qty->Qtyadd(Qtyq1)(Qtyq2)=Qty$q1+q2subt::Qty->Qty->MaybeQtysubt(Qtyq1)(Qtyq2)=ifq2>q1thenNothingelseJust$Qty(q1-q2)mult::Qty->Qty->Qtymult(Qtyq1)(Qtyq2)=Qty$q1*q2zero::Qtyzero=Qty$Decimal00