module Universum.Debug
( Undefined (..)
, error
, trace
, traceM
, traceId
, traceShow
, traceShowId
, traceShowM
, undefined
) where
import Control.Monad (Monad, return)
import Data.Data (Data)
import Data.Text (Text, unpack)
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import System.IO.Unsafe (unsafePerformIO)
#if ( __GLASGOW_HASKELL__ >= 800 )
import GHC.Exts (RuntimeRep, TYPE)
import Universum.Base (HasCallStack)
#endif
import Universum.Applicative (pass)
import Universum.Print (Print, putStrLn)
import qualified Prelude as P
trace :: Print b => b -> a -> a
trace string expr = unsafePerformIO (do
putStrLn string
return expr)
#if ( __GLASGOW_HASKELL__ >= 800 )
error :: forall (r :: RuntimeRep) . forall (a :: TYPE r) . HasCallStack
=> Text -> a
#else
error :: Text -> a
#endif
error s = P.error (unpack s)
traceShow :: P.Show a => a -> b -> b
traceShow a b = trace (P.show a) b
traceShowId :: P.Show a => a -> a
traceShowId a = trace (P.show a) a
traceShowM :: (P.Show a, Monad m) => a -> m ()
traceShowM a = trace (P.show a) pass
traceM :: (Monad m) => Text -> m ()
traceM s = trace (unpack s) pass
traceId :: Text -> Text
traceId s = trace s s
data Undefined = Undefined
deriving (P.Eq, P.Ord, P.Show, P.Read, P.Enum, P.Bounded, Data, Typeable, Generic)
#if ( __GLASGOW_HASKELL__ >= 800 )
undefined :: forall (r :: RuntimeRep) . forall (a :: TYPE r) . HasCallStack => a
#else
undefined :: a
#endif
undefined = P.undefined