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