{-# 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 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
ratioPrec) (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$
Int -> a -> Builder
forall a. TextShow a => Int -> a -> Builder
showbPrec Int
ratioPrec1 a
numer
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" % "
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Int -> a -> Builder
forall a. TextShow a => Int -> a -> Builder
showbPrec Int
ratioPrec1 a
denom
{-# INLINE showbPrec #-}
instance TextShow1 Ratio where
liftShowbPrec :: (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 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
ratioPrec) (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$
Int -> a -> Builder
sp Int
ratioPrec1 a
numer
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" % "
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Int -> a -> Builder
sp Int
ratioPrec1 a
denom
{-# INLINE liftShowbPrec #-}