diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2017-06-22 12:24:49 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-06-24 01:51:22 +0300 |
commit | b36973b3e08e6d1f8a7d42a6984249486d0cebfe (patch) | |
tree | d14d015a3d5aa20d8a6e1effb9630643abaa847a /lib/Malodivo/Types/Bill.hs | |
download | molodivo-0.0.0.tar.gz |
Initial commit0.0.0
Diffstat (limited to 'lib/Malodivo/Types/Bill.hs')
-rw-r--r-- | lib/Malodivo/Types/Bill.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Malodivo/Types/Bill.hs b/lib/Malodivo/Types/Bill.hs new file mode 100644 index 0000000..336c0fb --- /dev/null +++ b/lib/Malodivo/Types/Bill.hs @@ -0,0 +1,44 @@ +{-| + +A bill is a proposed law put before the Parliament to consider and +possibly implement. Bills can be encoded to and decoded from JSON. + +>>> :set -XOverloadedStrings +>>> import Data.Aeson (decode, encode) +>>> import Data.Maybe (fromJust) +>>> import Malodivo.Types.Ministry (Ministry(..)) + +>>> let billGreateWall = Bill { name = "The Great Wall of Malodivo", ministry = Defense, amount = 4000 } +>>> encode billGreateWall +"{\"amount\":4000,\"name\":\"The Great Wall of Malodivo\",\"ministry\":\"Defense\"}" + +>>> let billShelters = fromJust $ decode "{\"amount\":1234,\"name\":\"Shelters for the Homeless\",\"ministry\":\"Welfare\"}" +>>> billShelters :: Bill +Bill {name = "Shelters for the Homeless", ministry = Welfare, amount = 1234} + +>>> ministry <$> [billShelters, billGreateWall] +[Welfare,Defense] + +>>> sum $ amount <$> [billShelters, billGreateWall] +5234 + +-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} + +module Malodivo.Types.Bill + ( Bill(..) + ) where + +import GHC.Generics (Generic) + +import Data.Aeson (FromJSON, ToJSON) +import Data.Text (Text) + +import Malodivo.Types.Ministry (Ministry) + +data Bill = Bill + { name :: Text -- ^ the name of a bill, e. g. \"An Act to Construct the Great Wall of Malodivo\". + , ministry :: Ministry -- ^ the ministry getting funds to implement a bill. + , amount :: Integer -- ^ the amount of funds required to implement a bill. + } deriving (Show, Generic, FromJSON, ToJSON) |