{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >=704
{-# LANGUAGE Safe #-}
#elif __GLASGOW_HASKELL__ >=702
{-# LANGUAGE Trustworthy #-}
#endif
-- | A 'Show' instance for functions, given the input is 'Finite' and both
-- the input and output are 'Show'.
module Data.Universe.Instances.Show () where

import Data.Universe.Class (Universe (..), Finite (..))
import qualified Data.Monoid as Mon

instance (Finite a, Show a, Show b) => Show (a -> b) where
  showsPrec :: Int -> (a -> b) -> ShowS
showsPrec Int
n a -> b
f = Int -> [(a, b)] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
n [(a
a, a -> b
f a
a) | a
a <- [a]
forall a. Finite a => [a]
universeF]

instance (Finite a, Show a) => Show (Mon.Endo a) where
  showsPrec :: Int -> Endo a -> ShowS
showsPrec Int
d (Mon.Endo a -> a
f) = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10)
    (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"Endo "
    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (a -> a) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a -> a
f