{-# language OverloadedStrings #-}

module Utils
  ( module Utils
  , module Export
  )
  where

import GHC.Generics as Export (Generic)
import Data.Bifunctor as Export
import Data.Maybe as Export
import Data.Functor as Export
import Data.Foldable as Export
import Data.Traversable as Export
import Control.Monad as Export
import Data.Data as Export (Data)
import Data.Text as Export (Text)
import Data.Set as Export (Set)
import Data.Map as Export (Map)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import qualified Text.Pretty.Simple as PS

import Debug.Trace

ltrace :: Show a => String -> a -> a
ltrace :: String -> a -> a
ltrace String
lbl a
x = String -> a -> a
forall a. String -> a -> a
trace (String
lbl String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
": " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
toString (a -> Text
forall a. Show a => a -> Text
pShow a
x)) a
x
{-# warning ltrace "ltrace left in code" #-}

ltraceM :: Applicative m => Show a => String -> a -> m ()
ltraceM :: String -> a -> m ()
ltraceM String
lbl a
x = String -> m ()
forall (f :: * -> *). Applicative f => String -> f ()
traceM (String
lbl String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
": " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
toString (a -> Text
forall a. Show a => a -> Text
pShow a
x))
{-# warning ltraceM "ltraceM left in code" #-}

pShow :: Show a => a -> Text
pShow :: a -> Text
pShow = Text -> Text
TL.toStrict (Text -> Text) -> (a -> Text) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Text
forall a. Show a => a -> Text
PS.pShow

toString :: Text -> String
toString :: Text -> String
toString = Text -> String
T.unpack

toText :: String -> Text
toText :: String -> Text
toText = String -> Text
T.pack