{-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE KindSignatures #-} module Debug where import qualified Debug.Trace as D #if defined(RELEASE) import GHC.Exts #else import GHC.Stack import Prettyprinter #endif traceDoc :: Doc a -> b -> b #if defined(RELEASE) type DebugCallStack = (() :: Constraint) traceDoc !_ v = v #else type DebugCallStack = HasCallStack traceDoc x = D.trace (show x) #endif trace :: Pretty a => a -> b -> b trace x = traceDoc (pretty x) traceWith :: Pretty a => String -> a -> b -> b traceWith s x = traceDoc (pretty s <> pretty ": " <> pretty x) traceId :: Pretty a => a -> a traceId x = traceDoc (pretty x) x traceDocM :: (Applicative m) => Doc a -> m () traceDocM x = traceDoc x (pure ()) traceM :: (Applicative m, Pretty a) => a -> m () traceM = traceDocM . pretty