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.

45 lines
1.0 KiB

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