module TextShow.Data.Ratio () where
import Data.Monoid.Compat ((<>))
import GHC.Real (Ratio(..), ratioPrec, ratioPrec1)
import TextShow.Classes (TextShow(..), TextShow1(..), showbParen)
import TextShow.Data.Integral ()
instance TextShow a => TextShow (Ratio a) where
showbPrec p (numer :% denom) = showbParen (p > ratioPrec) $
showbPrec ratioPrec1 numer
<> " % "
<> showbPrec ratioPrec1 denom
instance TextShow1 Ratio where
liftShowbPrec sp _ p (numer :% denom) = showbParen (p > ratioPrec) $
sp ratioPrec1 numer
<> " % "
<> sp ratioPrec1 denom