packages feed

debug-tracy 0.1.0.1 → 0.1.0.2

raw patch · 3 files changed

+52/−31 lines, 3 filesdep +debug-tracydep +lensdep ~basenew-component:exe:testPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: debug-tracy, lens

Dependency ranges changed: base

API changes (from Hackage documentation)

- Debug.Tracy: data Find a
- Debug.Tracy: data FindT m a
- Debug.Tracy: instance Data.Foldable.Foldable Debug.Tracy.Find
- Debug.Tracy: instance GHC.Base.Applicative Debug.Tracy.Find
- Debug.Tracy: instance GHC.Base.Functor Debug.Tracy.Find
- Debug.Tracy: instance GHC.Base.Monad Debug.Tracy.Find
- Debug.Tracy: instance GHC.Base.Monad m => GHC.Base.Applicative (Debug.Tracy.FindT m)
- Debug.Tracy: instance GHC.Base.Monad m => GHC.Base.Functor (Debug.Tracy.FindT m)
- Debug.Tracy: instance GHC.Base.Monad m => GHC.Base.Monad (Debug.Tracy.FindT m)
- Debug.Tracy: instance GHC.Classes.Eq a => GHC.Classes.Eq (Debug.Tracy.Find a)
- Debug.Tracy: instance GHC.Classes.Ord a => GHC.Classes.Ord (Debug.Tracy.Find a)
- Debug.Tracy: instance GHC.Show.Show a => GHC.Show.Show (Debug.Tracy.Find a)
+ Debug.Tracy: data Scope f a
+ Debug.Tracy: instance (GHC.Base.Applicative f, Data.Foldable.Foldable f) => GHC.Base.Applicative (Debug.Tracy.Scope f)
+ Debug.Tracy: instance (GHC.Base.Functor f, Data.Foldable.Foldable f) => GHC.Base.Functor (Debug.Tracy.Scope f)
+ Debug.Tracy: instance (GHC.Base.Monad m, Data.Foldable.Foldable m) => GHC.Base.Monad (Debug.Tracy.Scope m)
+ Debug.Tracy: scope :: String -> f a -> Scope f a
+ Debug.Tracy: spy :: Show b => String -> (a -> b) -> a -> a
+ Debug.Tracy: unScope :: Scope f a -> f a

Files

debug-tracy.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                debug-tracy-version:             0.1.0.1+version:             0.1.0.2 synopsis:            More useful trace functions for investigating bugs description:         A collection of things for debugging, (to prevent me from writing them again) license:             BSD3@@ -14,6 +14,7 @@ build-type:          Simple extra-source-files:  ChangeLog.md cabal-version:       >=1.10+tested-with:         GHC == 8.4.1, GHC == 8.2.2, GHC == 8.0.2  source-repository head   type: git@@ -23,8 +24,16 @@   exposed-modules:     Debug.Tracy   -- other-modules:   -- other-extensions:-  build-depends:       base >=4.9 && <4.11+  build-depends:       base >=4.9 && <4.12+                     , lens                      , random                      , transformers   hs-source-dirs:      src   default-language:    Haskell2010++executable test+  main-is:             Main.hs+  default-language:    Haskell2010+  hs-source-dirs:      test+  build-depends:       base >= 4.9 && < 4.12+                     , debug-tracy
src/Debug/Tracy.hs view
@@ -1,5 +1,7 @@ {-# LANGUAGE DeriveFoldable            #-} {-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE FlexibleInstances         #-}+{-# LANGUAGE KindSignatures            #-} {-# LANGUAGE LambdaCase                #-}  module Debug.Tracy@@ -9,10 +11,13 @@   , arnold   , hasLength   , isFound-  , Find-  , FindT )  where+  , spy+  , scope+  , unScope+  , Scope )  where  +import           Control.Monad.Trans.Class import           Control.Monad.Trans.Maybe import qualified Data.Foldable             as Fold import           Debug.Trace               (trace)@@ -20,9 +25,12 @@ import           System.Random             (randomRIO)  +spy :: Show b => String -> (a -> b) -> a -> a+spy m f x = trace (delimit m $ show (f x)) x + delimit :: String -> String -> String-delimit s s' = s ++ " -> " ++ s'+delimit s s' = s ++ "\t-> " ++ s'  -- | trace with show and a delimiter built in tracy :: Show a => String -> a -> a@@ -115,37 +123,26 @@ hasLength s f = trace (delimit s $ "has length " ++ show (Fold.length f)) f  --- | Wrapper for inspecting a usage of the Maybe Monad-data Find a = Find String (Maybe a)-  deriving (Show, Eq, Ord, Foldable)+data Scope f a = Scope String (f a) -instance Functor Find where-  fmap f (Find s x) = Find s $ f <$> isFound s x -instance Applicative Find where-  pure = Find "pure" . pure-  Find _ mf <*> Find s x = Find s $ mf <*> isFound s x+unScope :: Scope f a -> f a+unScope (Scope _ x) = x -instance Monad Find where-  Find s x >>= f = case isFound s x of-    Just x' -> f x'-    _       -> Find s Nothing --- | Wrapper for inspecting a usage of the MaybeT Monad Transformer-data FindT m a = FindT String (MaybeT m a)+scope :: String -> f a -> Scope f a+scope = Scope -runFindT (FindT _ x) = x -instance Monad m => Functor (FindT m) where-  fmap f (FindT s x) = FindT s . MaybeT $ fmap f . isFound s <$> runMaybeT x+instance (Functor f, Foldable f) => Functor (Scope f) where+  fmap f (Scope m x) = Scope m $ f <$> (isFound m x) -instance Monad m => Applicative (FindT m) where-  pure = FindT "pure" . pure-  FindT _ mf <*> FindT s x = FindT s $ mf <*> MaybeT (isFound s <$> runMaybeT x) -instance Monad m => Monad (FindT m) where-  FindT s x >>= f = FindT s $ MaybeT $ do-    y <- runMaybeT x-    case isFound s y of-      Just x' -> runMaybeT $ runFindT (f x')-      _       -> return Nothing+instance (Applicative f, Foldable f) => Applicative (Scope f) where+  pure x = Scope "pure" $ pure x+  Scope fm fx <*> Scope m x = Scope m $ isFound fm fx <*> isFound m x+++instance (Monad m, Foldable m) => Monad (Scope m) where+  Scope m x >>= f = Scope m $ isFound m x >>= unScope . f+  return x = Scope "return" $ return x
+ test/Main.hs view
@@ -0,0 +1,15 @@+module Main where++import Debug.Tracy++main :: IO ()+main = print $ unScope $ do+  x <- scope "x" $ [0..(3 :: Int)]+  y <- scope "y" ([] :: [Int]) -- return (4 :: Int)+  return (x, y)++++--   x <- scope "x" $ Just (3 :: Int)+--   y <- scope "y" $ Just (5 :: Int) -- (Nothing :: Maybe Int)+--   return (tracy "x" x, keanu y)