packages feed

debug-tracy (empty) → 0.1.0.0

raw patch · 5 files changed

+218/−0 lines, 5 filesdep +basedep +randomdep +transformerssetup-changed

Dependencies added: base, random, transformers

Files

+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for debug-tracy++## 0.1.0.0  -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2017, Isaac Shapira++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Isaac Shapira nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ debug-tracy.cabal view
@@ -0,0 +1,30 @@+-- Initial debug-tracy.cabal generated by cabal init.  For further+-- documentation, see http://haskell.org/cabal/users-guide/++name:                debug-tracy+version:             0.1.0.0+synopsis:            More useful trace functions for investigating bugs+description:         A collection of things for debugging, (to prevent me from writing them again)+license:             BSD3+license-file:        LICENSE+author:              Isaac Shapira+maintainer:          fresheyeball@gmail.com+-- copyright:+category:            Development+build-type:          Simple+extra-source-files:  ChangeLog.md+cabal-version:       >=1.10++source-repository head+  type: git+  location: https://gitlab.com/fresheyeball/debug-tracy.git++library+  exposed-modules:     Debug.Tracy+  -- other-modules:+  -- other-extensions:+  build-depends:       base >=4.9 && <4.10+                     , random+                     , transformers+  hs-source-dirs:      src+  default-language:    Haskell2010
+ src/Debug/Tracy.hs view
@@ -0,0 +1,151 @@+{-# LANGUAGE DeriveFoldable            #-}+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE LambdaCase                #-}++module Debug.Tracy+  ( module Debug.Trace+  , tracy+  , keanu+  , arnold+  , hasLength+  , isFound+  , Find+  , FindT )  where+++import           Control.Monad.Trans.Maybe+import qualified Data.Foldable             as Fold+import           Debug.Trace               (trace)+import           System.IO.Unsafe          (unsafePerformIO)+import           System.Random             (randomRIO)++++delimit :: String -> String -> String+delimit s s' = s ++ " -> " ++ s'++-- | trace with show and a delimiter built in+tracy :: Show a => String -> a -> a+tracy s x = trace (delimit s $ show x) x++-- | Spit out a random Keanu Reaves quote when @a@ is evauluated+keanu :: a -> a+keanu x = trace (delimit "KEANU" . (ks !!) . unsafePerformIO $ randomRIO (0, length ks - 1)) x+  where+   ks = [ "Woah"+        , "I am the one."+        , "Party on"+        , "No way"+        , "Woah"+        , "I know kung fu"+        , "Excellent!"+        , "Huh?"+        , "Whoah.."+        , "All we are is dust in the wind, dude"+        , "Most Triumphant"+        , "Strange things are a foot at the Circle K"+        , "no way"+        , "69 Dudes!"+        , "Those are historic babes!"+        , "Bodacious!"+        , "Fully full on evil robots"+        , "So-crates"+        , "Morpheous"+        , "I'm going to learn jiu jitsu?"+        , "My name is Neo."+        , "No."+        , "take 1 step out and take my hand"+        , "freeze"+        , "id wanna know what bus it was"+        , "bomb on bus"+        , "i need to know can you handle this bus"+        , "the man has no time"+        , "theres a gap in the freeway"+        , "thats all we can do"+        , "floor it"+        , "thats against the rules"+        , "im gonna rip your fucking spine out i swear to god"+        , "pop quiz asshole"+        , "your crazy your fuckin crazy"+        , "he lost his head" ]++-- | spit out a random Arnold Schwarzenegger quote when @a@ is evaluated+arnold :: a -> a+arnold x = trace (delimit "ARNOLD" . (as !!) . unsafePerformIO $ randomRIO (0, length as - 1)) x+  where+  as = [ "It's simple, if it jiggles, it's fat."+       , "Milk is for babies. When you grow up you have to drink beer."+       , "The best activities for your health are pumping and humping."+       , "You're Fiuhed!"+       , "Cookies, who told you you could MY COOKIES!!!!??"+       , "Who is your Daddy, and what does he do?"+       , "I'm detective John Kimble"+       , "Get in the chopper, now!!"+       , "Guwhah ruuugh guawh!"+       , "Grrrgh uu ahhh!"+       , "Naaa gruh aagghh!!!"+       , "Grrruu guaw ghh raaaaaagh!"+       , "IT'S NOT A TUMOR!"+       , "SHAAAD AAAAAAAAAAAAAAAP!"+       , "I let him go.."+       , "He had to split"+       , "Remember Sully when I said I'd kill you last? I lied."+       , "You are not sending me to the coolah..."+       , "Stop CHEEERING ME UP!"+       , "You are one ugly motherfucker..."+       , "Do it."+       , "I'll be back."+       , "Foget it, I'm nut goiing to sit on yo lap" ]++-- | Inspect if @t a@ is null+isFound :: Foldable t => String -> t a -> t a+isFound s x = trace  (delimit s $ "was" ++ (if Fold.null x then " NOT" else "") ++ " found") x++-- | Inspect if @t a@ contains @a@+isElem :: (Foldable t, Eq a, Show a) => String -> a -> t a -> t a+isElem s x t = let s' = show x in trace (delimit s $+             if Fold.elem x t then "contains " ++ s' else "does NOT contain " ++ s') t++-- | Inspect if @Bool@ is legit+isTrue :: String -> Bool -> Bool+isTrue s x = trace (delimit s $ if x then "is legit" else "is buillshit") x++-- | Inspect the size of a collection+hasLength :: Foldable t => String -> t a -> t a+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)++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++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)++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 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