Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides definitions for economic events.
/Note: The concept is not YET REA-compatible although we want to achieve it at some point/.
Synopsis
- data Event o (s :: Nat)
- = EventDecrement Day o (UnsignedQuantity s)
- | EventIncrement Day o (UnsignedQuantity s)
- eventDate :: KnownNat s => Event o s -> Day
- eventObject :: KnownNat s => Event o s -> o
- negateEvent :: KnownNat s => Event o s -> Event o s
- mkEvent :: MonadError String m => KnownNat s => Day -> o -> Quantity s -> m (Event o s)
Documentation
data Event o (s :: Nat) Source #
Type encoding of an economic increment/decrement event.
The event explicitly carries the date and quantity information along with a parameterized, arbitrary object providing the source of the event.
>>>
:set -XDataKinds
>>>
let date = read "2021-01-01"
>>>
let oid = 1 :: Int
>>>
let qty = $$(Refined.refineTH 42) :: UnsignedQuantity 2
>>>
let event = EventDecrement date oid qty
>>>
let json = Data.Aeson.encode event
>>>
json
"{\"qty\":42.0,\"type\":\"DECREMENT\",\"obj\":1,\"date\":\"2021-01-01\"}">>>
Data.Aeson.decode @(Event Int 2) json
Just (EventDecrement 2021-01-01 1 (Refined 42.00))>>>
Data.Aeson.decode json == Just event
True
EventDecrement Day o (UnsignedQuantity s) | |
EventIncrement Day o (UnsignedQuantity s) |
Instances
eventObject :: KnownNat s => Event o s -> o Source #
Returns the source object of the event.