module Darcs.Patch.Witnesses.Show
    ( Show1(..)
    , Show2(..)
    , show1
    , showsPrec1
    , show2
    , showsPrec2
    , showOp2
    , appPrec
    ) where

import Darcs.Prelude

import Darcs.Util.Show ( appPrec )

import Data.Constraint ( Dict(..) )

type ShowDict a = Dict (Show a)

showsPrecD :: ShowDict a -> Int -> a -> ShowS
showsPrecD :: ShowDict a -> Int -> a -> ShowS
showsPrecD ShowDict a
Dict       = Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

showD :: ShowDict a -> a -> String
showD :: ShowDict a -> a -> String
showD ShowDict a
Dict       = a -> String
forall a. Show a => a -> String
show

class Show1 a where
  showDict1 :: Dict (Show (a wX))
  default showDict1 :: Show (a wX) => ShowDict (a wX)
  showDict1 = ShowDict (a wX)
forall (a :: Constraint). a => Dict a
Dict

showsPrec1 :: Show1 a => Int -> a wX -> ShowS
showsPrec1 :: Int -> a wX -> ShowS
showsPrec1 = ShowDict (a wX) -> Int -> a wX -> ShowS
forall a. ShowDict a -> Int -> a -> ShowS
showsPrecD ShowDict (a wX)
forall (a :: * -> *) wX. Show1 a => Dict (Show (a wX))
showDict1

show1 :: Show1 a => a wX -> String
show1 :: a wX -> String
show1 = ShowDict (a wX) -> a wX -> String
forall a. ShowDict a -> a -> String
showD ShowDict (a wX)
forall (a :: * -> *) wX. Show1 a => Dict (Show (a wX))
showDict1

class Show2 a where
  showDict2 :: ShowDict (a wX wY)
  default showDict2 :: Show (a wX wY) => ShowDict (a wX wY)
  showDict2 = ShowDict (a wX wY)
forall (a :: Constraint). a => Dict a
Dict

showsPrec2 :: Show2 a => Int -> a wX wY -> ShowS
showsPrec2 :: Int -> a wX wY -> ShowS
showsPrec2 = ShowDict (a wX wY) -> Int -> a wX wY -> ShowS
forall a. ShowDict a -> Int -> a -> ShowS
showsPrecD ShowDict (a wX wY)
forall (a :: * -> * -> *) wX wY. Show2 a => ShowDict (a wX wY)
showDict2

show2 :: Show2 a => a wX wY -> String
show2 :: a wX wY -> String
show2 = ShowDict (a wX wY) -> a wX wY -> String
forall a. ShowDict a -> a -> String
showD ShowDict (a wX wY)
forall (a :: * -> * -> *) wX wY. Show2 a => ShowDict (a wX wY)
showDict2

showOp2 :: (Show2 a, Show2 b) => Int -> String -> Int -> a wW wX -> b wY wZ -> String -> String
showOp2 :: Int -> String -> Int -> a wW wX -> b wY wZ -> ShowS
showOp2 Int
prec String
opstr Int
d a wW wX
x b wY wZ
y = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
prec) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ Int -> a wW wX -> ShowS
forall (a :: * -> * -> *) wX wY. Show2 a => Int -> a wX wY -> ShowS
showsPrec2 (Int
prec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) a wW wX
x ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                          String -> ShowS
showString String
opstr ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> b wY wZ -> ShowS
forall (a :: * -> * -> *) wX wY. Show2 a => Int -> a wX wY -> ShowS
showsPrec2 (Int
prec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) b wY wZ
y