{-# LANGUAGE OverloadedStrings #-} module Language.Giml.Utils ( module Language.Giml.Utils, module Export, ) where import Control.DeepSeq as Export import Control.Monad as Export import Control.Monad.Reader as Export import Data.Bifunctor as Export import Data.Data as Export (Data) import Data.Foldable as Export import Data.Functor as Export import Data.Int as Export import Data.Map as Export (Map) import Data.Maybe as Export import Data.Set as Export (Set) import Data.String as Export (fromString) import Data.Text as Export (Text) import Data.Text qualified as T import Data.Text.Lazy qualified as TL import Data.Traversable as Export import Data.Typeable as Export import Data.Void as Export import Data.Word as Export import Debug.Trace import GHC.Generics as Export (Generic) import Text.Pretty.Simple qualified as PS ltrace :: (Show a) => String -> a -> a ltrace :: forall a. Show a => 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 :: forall (m :: * -> *) a. (Applicative m, Show a) => 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 :: forall a. Show a => 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 data Matches a b = OnlyLeft a | OnlyRight a | BothSides b unzipMatches :: [Matches a b] -> ([a], [a], [b]) unzipMatches :: forall a b. [Matches a b] -> ([a], [a], [b]) unzipMatches = \case [] -> ([], [], []) Matches a b current : [Matches a b] rest -> let ([a] lefts, [a] rights, [b] both) = [Matches a b] -> ([a], [a], [b]) forall a b. [Matches a b] -> ([a], [a], [b]) unzipMatches [Matches a b] rest in case Matches a b current of OnlyLeft a x -> (a x a -> [a] -> [a] forall a. a -> [a] -> [a] : [a] lefts, [a] rights, [b] both) OnlyRight a x -> ([a] lefts, a x a -> [a] -> [a] forall a. a -> [a] -> [a] : [a] rights, [b] both) BothSides b x -> ([a] lefts, [a] rights, b x b -> [b] -> [b] forall a. a -> [a] -> [a] : [b] both)