From 6fbffc586cd951180c5a4ed328bd43a1f3920a85 Mon Sep 17 00:00:00 2001 From: "Nikolaos S. Papaspyrou" Date: Mon, 31 Oct 2016 10:36:41 +0200 Subject: Fix integer fields in YAML metadata If a numeric field contains an integer number, it should be shown as an integer number. Without this patch, the field: answer = 42 would be shown as "42.0". Before the introduction of YAML in metadata, this was treated as a string and therefore shown as just "42". This patch reinstates the older (and IMHO correct) behavior. --- src/Data/Yaml/Extended.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Data/Yaml/Extended.hs b/src/Data/Yaml/Extended.hs index 099e945..1600bab 100644 --- a/src/Data/Yaml/Extended.hs +++ b/src/Data/Yaml/Extended.hs @@ -7,12 +7,14 @@ module Data.Yaml.Extended import qualified Data.Text as T import qualified Data.Vector as V import Data.Yaml +import Data.Scientific toString :: Value -> Maybe String toString (String t) = Just (T.unpack t) toString (Bool True) = Just "true" toString (Bool False) = Just "false" -toString (Number d) = Just (show d) +toString (Number d) | isInteger d = Just (formatScientific Fixed (Just 0) d) + | otherwise = Just (show d) toString _ = Nothing toList :: Value -> Maybe [Value] -- cgit v1.2.3