From 75d73f019cd785b4943567fe641af29d34f5c464 Mon Sep 17 00:00:00 2001 From: Justus Adam Date: Sat, 7 Nov 2015 12:06:03 +0100 Subject: [PATCH] Added some number conversion instances. --- src/lib/Text/Mustache/Types.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/Text/Mustache/Types.hs b/src/lib/Text/Mustache/Types.hs index 2ab5b53..a503b87 100644 --- a/src/lib/Text/Mustache/Types.hs +++ b/src/lib/Text/Mustache/Types.hs @@ -102,6 +102,18 @@ class ToMustache ω where listToMustache ∷ [ω] → Value listToMustache = Array ∘ V.fromList ∘ fmap toMustache +instance ToMustache Float where + toMustache = Number ∘ fromFloatDigits + +instance ToMustache Double where + toMustache = Number ∘ fromFloatDigits + +instance ToMustache Integer where + toMustache = Number ∘ flip scientific 0 + +instance ToMustache Int where + toMustache = toMustache . toInteger + instance ToMustache Char where toMustache = toMustache ∘ (:[]) listToMustache = String ∘ pack