From 9d7aa4cbd8d66e8a8db0ea4916d3f6d221e0c2db Mon Sep 17 00:00:00 2001 From: Brendan Hay Date: Mon, 29 Dec 2014 12:10:33 +1300 Subject: [PATCH] Ensuring defaulted type constraint no longer raises warning --- core/src/Network/AWS/Data/Internal/Numeric.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/src/Network/AWS/Data/Internal/Numeric.hs b/core/src/Network/AWS/Data/Internal/Numeric.hs index 7b9df5ed2d7..93b92c4d53a 100644 --- a/core/src/Network/AWS/Data/Internal/Numeric.hs +++ b/core/src/Network/AWS/Data/Internal/Numeric.hs @@ -1,4 +1,5 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-} -- Module : Network.AWS.Data.Internal.Numeric @@ -13,10 +14,10 @@ module Network.AWS.Data.Internal.Numeric where -import Control.Applicative import Control.Lens.TH import Control.Monad import Data.Aeson.Types +import Data.Monoid import Data.Scientific import Network.AWS.Data.Internal.ByteString import Network.AWS.Data.Internal.Query @@ -43,12 +44,16 @@ newtype Nat = Nat { unNat :: Natural } ) instance FromJSON Nat where - parseJSON = parseJSON >=> \n -> - case floatingOrInteger n of - Left _ -> fail $ "Cannot convert float to Natural: " ++ show n + parseJSON = parseJSON >=> go + where + go n = case floatingOrInteger n of + Left (_ :: Double) -> fail (floatErr n) Right i - | n < 0 -> fail $ "Cannot convert negative number to Natural: " ++ show n - | otherwise -> pure $ Nat (fromInteger i) + | n < 0 -> fail (negateErr n) + | otherwise -> return . Nat $ fromInteger i + + floatErr = mappend "Cannot convert float to Natural: " . show + negateErr = mappend "Cannot convert negative number to Natural: " . show instance ToJSON Nat where toJSON = Number . flip scientific 0 . toInteger . unNat