diff options
Diffstat (limited to 'lib/Malodivo/Types/Ministry.hs')
-rw-r--r-- | lib/Malodivo/Types/Ministry.hs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/Malodivo/Types/Ministry.hs b/lib/Malodivo/Types/Ministry.hs index c3e315b..f3878d1 100644 --- a/lib/Malodivo/Types/Ministry.hs +++ b/lib/Malodivo/Types/Ministry.hs @@ -18,15 +18,38 @@ Just [Science] module Malodivo.Types.Ministry ( Ministry(..) + , MinistryInfo + , MinistryLimits + , mi2ml ) where +import Control.Arrow ((&&&)) import GHC.Generics (Generic) import Data.Aeson (FromJSON, ToJSON) +import qualified Data.HashMap.Strict as HM +import Data.Hashable (Hashable) -- | Ministry of the Kingdom of Malodivo. data Ministry = Defense | Science | Welfare - deriving (Show, Generic, FromJSON, ToJSON) + deriving (Eq, Hashable, Show, Generic, FromJSON, ToJSON) + +-- | Convenient type. Describes maximum money a ministry can get. +type MinistryLimits = HM.HashMap Ministry Integer + +{-| +We use this data type instead of 'MinistryLimits' for JSON, +because maps other than @HashMap Text _@ are hard to decode/encode see +<https://github.com/bos/aeson/issues/79>. Anyway, we still have type-checked +typos-proof structure. +-} +data MinistryInfo = MinistryInfo + { name :: Ministry + , amount :: Integer + } deriving (Generic, FromJSON) + +mi2ml :: [MinistryInfo] -> MinistryLimits +mi2ml = HM.fromListWith (+) . map (name &&& amount) |