From d4a2e49173393c9f92ad0d46a496b2ad43c792b1 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 23 Mar 2023 16:35:04 +0100 Subject: [PATCH] Structured.Show instance for float/double --- src/Data/Structured.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Data/Structured.hs b/src/Data/Structured.hs index e556bd6..3dbc1a4 100644 --- a/src/Data/Structured.hs +++ b/src/Data/Structured.hs @@ -123,6 +123,9 @@ data Value where -- These are shown assuming @NumericUnderscores@. Integral :: forall a. (Prelude.Show a, Integral a) => a -> Value + -- | Floating point numbers + Floating :: Double -> Value + -- | Quasi-quote -- -- We separate out the quasi-quoter from the quoted string proper. @@ -259,6 +262,9 @@ instance Show Int128 where toValue = Integral instance Show Integer where toValue = Integral +instance Show Float where toValue = Floating . realToFrac +instance Show Double where toValue = Floating + instance {-# OVERLAPPABLE #-} Show a => Show [a] where toValue = List . map toValue @@ -451,6 +457,7 @@ render = \contextNeedsBrackets -> bracketIf (contextneedsBrackets && requiresBrackets val) $ case val of Integral x -> simple $ addNumericUnderscores (Prelude.show x) + Floating x -> simple $ Prelude.show x String x -> simple $ Prelude.show x Constr c ts xs -> renderComposite (compositeConstr c ts) $ map (go True) xs