Commits

Bryan O'Sullivan committed 9482e52

Add more numeric instances.

  • Participants
  • Parent commits 920fe1e

Comments (0)

Files changed (2)

File Data/Configurator/Instances.hs

 
 import Control.Applicative
 import Data.Configurator.Types.Internal
+import Data.Int (Int8, Int16, Int32, Int64)
 import Data.Text.Encoding (encodeUtf8)
+import Data.Word (Word, Word8, Word16, Word32, Word64)
 import qualified Data.ByteString as B
 import qualified Data.ByteString.Lazy as LB
 import qualified Data.Text as T
     convert (Bool v) = Just v
     convert _        = Nothing
 
+convertNumber :: (Num a) => Value -> Maybe a
+convertNumber (Number v) = Just (fromIntegral v)
+convertNumber _          = Nothing
+
 instance Configured Int where
-    convert (Number v) = Just v
-    convert _          = Nothing
+    convert = convertNumber
+
+instance Configured Integer where
+    convert = convertNumber
+
+instance Configured Int8 where
+    convert = convertNumber
+
+instance Configured Int16 where
+    convert = convertNumber
+
+instance Configured Int32 where
+    convert = convertNumber
+
+instance Configured Int64 where
+    convert = convertNumber
+
+instance Configured Word where
+    convert = convertNumber
+
+instance Configured Word8 where
+    convert = convertNumber
+
+instance Configured Word16 where
+    convert = convertNumber
+
+instance Configured Word32 where
+    convert = convertNumber
+
+instance Configured Word64 where
+    convert = convertNumber
 
 instance Configured T.Text where
     convert (String v) = Just v

File Data/Configurator/Types/Internal.hs

            --
            -- * @\\u@/xxxx/@\\u@/xxxx/ - Unicode character (as two
            --   UTF-16 surrogates)
-           | Number Int
+           | Number Integer
            -- ^ Integer.
            | List [Value]
            -- ^ Heterogeneous list.  Represented in a configuration