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.

38 lines
817 B

  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. #endif
  12. traceDoc :: Doc a -> b -> b
  13. #if defined(RELEASE)
  14. type DebugCallStack = (() :: Constraint)
  15. traceDoc !_ v = v
  16. #else
  17. type DebugCallStack = HasCallStack
  18. traceDoc x = D.trace (show x)
  19. #endif
  20. trace :: Pretty a => a -> b -> b
  21. trace x = traceDoc (pretty x)
  22. traceWith :: Pretty a => String -> a -> b -> b
  23. traceWith s x = traceDoc (pretty s <> pretty ": " <> pretty x)
  24. traceId :: Pretty a => a -> a
  25. traceId x = traceDoc (pretty x) x
  26. traceDocM :: (Applicative m) => Doc a -> m ()
  27. traceDocM x = traceDoc x (pure ())
  28. traceM :: (Applicative m, Pretty a) => a -> m ()
  29. traceM = traceDocM . pretty