data AppError
= Interrupted
| ReadError String
| NegativeIncome
| Undefined
type App = ExceptT AppError (InputT IO)
do
r <- runInputT defaultSettings . runExceptT $ go
either (hPutStrLn stderr . ("An error occured: " ++) . show) return r
where
do
income <- readInput "Income: " (readEither @Int)
currency <- readInput "Currency: " Right
budget <- calculateBudget income currency
liftIO . print . PrettyPrint.printBudget $ budget
do
income <- mkIncome x curr
let rule = defaultRule
budget = calculateSomeBudget rule income
return budget
do
input <- lift $ getInputLine prompt
maybe (throwError Interrupted) (liftEither . mapLeft ReadError . f) input
do
pos <- liftEither . mapLeft (const NegativeIncome) $ eitherPos input
return $ withSomeSSymbol currency $ \curr -> SomePosMoney curr (PosMoney pos)