{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module TextShow.Data.Ratio () where
import GHC.Real (Ratio(..), ratioPrec, ratioPrec1)
import Prelude ()
import Prelude.Compat
import TextShow.Classes (TextShow(..), TextShow1(..), showbParen)
import TextShow.Data.Integral ()
instance TextShow a => TextShow (Ratio a) where
{-# SPECIALIZE instance TextShow Rational #-}
showbPrec :: Int -> Ratio a -> Builder
showbPrec Int
p (a
numer :% a
denom) = Bool -> Builder -> Builder
showbParen (Int
p forall a. Ord a => a -> a -> Bool
> Int
ratioPrec) forall a b. (a -> b) -> a -> b
$
forall a. TextShow a => Int -> a -> Builder
showbPrec Int
ratioPrec1 a
numer
forall a. Semigroup a => a -> a -> a
<> Builder
" % "
forall a. Semigroup a => a -> a -> a
<> forall a. TextShow a => Int -> a -> Builder
showbPrec Int
ratioPrec1 a
denom
{-# INLINE showbPrec #-}
instance TextShow1 Ratio where
liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> Ratio a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
_ Int
p (a
numer :% a
denom) = Bool -> Builder -> Builder
showbParen (Int
p forall a. Ord a => a -> a -> Bool
> Int
ratioPrec) forall a b. (a -> b) -> a -> b
$
Int -> a -> Builder
sp Int
ratioPrec1 a
numer
forall a. Semigroup a => a -> a -> a
<> Builder
" % "
forall a. Semigroup a => a -> a -> a
<> Int -> a -> Builder
sp Int
ratioPrec1 a
denom
{-# INLINE liftShowbPrec #-}