-- My Show class, polish notation for simplicity. {-# LANGUAGE DeriveGeneric, DefaultSignatures, FlexibleInstances, FlexibleContexts #-} module Show where import GHC.Generics class MyShow a where myshows :: a -> String -> String default myshows :: (Generic a, GShow (Rep a)) => a -> String -> String myshows x = gshows (from x) myshow :: a -> String myshow x = myshows x "" class GShow f where gshows :: f p -> String -> String instance GShow V1 where gshows _ = showString "" instance GShow U1 where gshows _ = id instance MyShow c => GShow (K1 i c) where gshows (K1 x) = showChar ' ' . myshows x instance (GShow f, GShow g) => GShow ((:*:) f g) where gshows (f :*: g) = gshows f . gshows g instance (GShow f, GShow g) => GShow ((:+:) f g) where gshows (L1 x) = gshows x gshows (R1 x) = gshows x instance GShow f => GShow (S1 c f) where gshows (M1 x) = gshows x instance (Constructor c, GShow f) => GShow (C1 c f) where gshows m@(M1 x) = showString (conName m) . gshows x instance GShow f => GShow (D1 c f) where gshows (M1 x) = gshows x data My = A Bool | B Int My deriving Generic instance MyShow Bool instance MyShow Int where myshows n = shows n instance MyShow My newtype N = N My deriving Generic instance MyShow N