infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree athe derived instance of Show is equivalent to
instance (Show a) => Show (Tree a) where showsPrec d (Leaf m) = showParen (d > app_prec) $ showString "Leaf " . showsPrec (app_prec+1) m where app_prec = 10 showsPrec d (u :^: v) = showParen (d > up_prec) $ showsPrec (up_prec+1) u . showString " :^: " . showsPrec (up_prec+1) v where up_prec = 5Note that right-associativity of :^: is ignored. For example,
>>> show (errorX "undefined" :: Integer, 4 :: Int) "(*** Exception: X: undefined CallStack (from HasCallStack): ... >>> showX (errorX "undefined" :: Integer, 4 :: Int) "(undefined,4)"Can be derived using Generics:
{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} import Clash.Prelude import GHC.Generics data T = MkTA Int | MkTB Bool deriving (Show,Generic,ShowX)
>>> d789 d789 >>> toBNat d789 b789 >>> showBNat (toBNat d789) "0b1100010101" >>> 0b1100010101 :: Integer 789
data T = ... instance Show T where ... instance ShowX T where showsPrecX = showsPrecXWith showsPrec