less prototype, less bad code implementation of CCHM type theory
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.0 KiB

  1. {-# LANGUAGE CPP #-}
  2. {-# LANGUAGE ConstraintKinds #-}
  3. {-# LANGUAGE KindSignatures #-}
  4. module Debug where
  5. import qualified Debug.Trace as D
  6. #if defined(RELEASE)
  7. import GHC.Exts
  8. #else
  9. import GHC.Stack
  10. import Prettyprinter
  11. import qualified Data.Text.Lazy as T
  12. import Data.Text.Prettyprint.Doc.Render.Text (renderLazy)
  13. #endif
  14. traceDoc :: Doc a -> b -> b
  15. #if defined(RELEASE)
  16. type DebugCallStack = (() :: Constraint)
  17. traceDoc !_ v = v
  18. #else
  19. type DebugCallStack = HasCallStack
  20. traceDoc x = D.trace (T.unpack (renderLazy (layoutPretty defaultLayoutOptions x)))
  21. #endif
  22. trace :: Pretty a => a -> b -> b
  23. trace x = traceDoc (pretty x)
  24. traceWith :: Pretty a => String -> a -> b -> b
  25. traceWith s x = traceDoc (pretty s <+> pretty x)
  26. traceId :: Pretty a => a -> a
  27. traceId x = traceDoc (pretty x) x
  28. traceWithId :: Pretty a => String -> a -> a
  29. traceWithId s x = traceWith s x x
  30. traceDocM :: (Applicative m) => Doc a -> m ()
  31. traceDocM x = traceDoc x (pure ())
  32. traceM :: (Applicative m, Pretty a) => a -> m ()
  33. traceM = traceDocM . pretty