Merge pull request #6 from BeFunctional/edsko/structured-floating
Structured.Show instance for float/double
This commit is contained in:
commit
c28efafcb6
1 changed files with 7 additions and 0 deletions
|
@ -123,6 +123,9 @@ data Value where
|
||||||
-- These are shown assuming @NumericUnderscores@.
|
-- These are shown assuming @NumericUnderscores@.
|
||||||
Integral :: forall a. (Prelude.Show a, Integral a) => a -> Value
|
Integral :: forall a. (Prelude.Show a, Integral a) => a -> Value
|
||||||
|
|
||||||
|
-- | Floating point numbers
|
||||||
|
Floating :: Double -> Value
|
||||||
|
|
||||||
-- | Quasi-quote
|
-- | Quasi-quote
|
||||||
--
|
--
|
||||||
-- We separate out the quasi-quoter from the quoted string proper.
|
-- 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 Integer where toValue = Integral
|
||||||
|
|
||||||
|
instance Show Float where toValue = Floating . realToFrac
|
||||||
|
instance Show Double where toValue = Floating
|
||||||
|
|
||||||
instance {-# OVERLAPPABLE #-} Show a => Show [a] where
|
instance {-# OVERLAPPABLE #-} Show a => Show [a] where
|
||||||
toValue = List . map toValue
|
toValue = List . map toValue
|
||||||
|
|
||||||
|
@ -451,6 +457,7 @@ render = \contextNeedsBrackets ->
|
||||||
bracketIf (contextneedsBrackets && requiresBrackets val) $
|
bracketIf (contextneedsBrackets && requiresBrackets val) $
|
||||||
case val of
|
case val of
|
||||||
Integral x -> simple $ addNumericUnderscores (Prelude.show x)
|
Integral x -> simple $ addNumericUnderscores (Prelude.show x)
|
||||||
|
Floating x -> simple $ Prelude.show x
|
||||||
String x -> simple $ Prelude.show x
|
String x -> simple $ Prelude.show x
|
||||||
Constr c ts xs -> renderComposite (compositeConstr c ts) $
|
Constr c ts xs -> renderComposite (compositeConstr c ts) $
|
||||||
map (go True) xs
|
map (go True) xs
|
||||||
|
|
Loading…
Reference in a new issue