TraceUtils (empty) → 0.1
raw patch · 4 files changed
+107/−0 lines, 4 filesdep +basesetup-changed
Dependencies added: base
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- TraceUtils.cabal +23/−0
- src/Debug/TraceUtils.hs +52/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Eyal Lotem++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 Eyal Lotem 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
+ TraceUtils.cabal view
@@ -0,0 +1,23 @@+-- TraceUtils.cabal auto-generated by cabal init. For additional+-- options, see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name: TraceUtils+Version: 0.1+Synopsis: Functions that should have been in Debug.Trace+Description: Functions that should have been in Debug.Trace+Homepage: https://github.com/Peaker/TraceUtils+License: BSD3+License-file: LICENSE+Author: Eyal Lotem+Maintainer: eyal.lotem@gmail.com+Category: Development+Build-type: Simple+Cabal-version: >=1.2++Library+ Exposed-modules: Debug.TraceUtils+ hs-source-dirs: src++ -- Packages needed in order to build this package.+ Build-depends: base >= 3 && < 10
+ src/Debug/TraceUtils.hs view
@@ -0,0 +1,52 @@+{-# OPTIONS -O2 -Wall #-}++-- | This module exposes some useful tracing functions that should+-- have been exported by Debug.Trace.+--+-- Feel free to copy&paste these functions into modules that need+-- them, that may be easier to remove/clean up than adding a cabal+-- dependency.++module Debug.TraceUtils(+ traceId+ ,traceIdVia+ ,traceAround+) where++import Debug.Trace(trace)++-- | Generate an identity function that has the side-effect of tracing+-- the value that passes through it by first processing it and then+-- showing the result.+--+-- Examples:+--+-- traceIdVia (take 5) \"First 5 sorted elements of: \" result+--+-- fmap (traceIdVia objName \"The object we got\") . receiveObject+traceIdVia :: Show b =>+ (a -> b) -- ^ Function to preprocess the value before showing it+ -> String -- ^ Prefix string to use before showing the result value+ -> a -> a+traceIdVia via prefix x = trace (prefix ++ show (via x)) x++-- | Generate an identity function that has the side-effect of showing+-- the value that passes through it.+--+-- Examples:+--+-- traceId \"x,y = \" (x, y)+traceId :: Show a =>+ String -- ^ Prefix string to use before showing the value+ -> a -> a+traceId = traceIdVia id++-- | Convert a pure function to one that also has a side effect of+-- tracing the value of the input and output values that pass through+-- the function.+--+-- Examples:+--+-- traceAround \"filterEntries\" filterEntries entries+traceAround :: (Show i, Show o) => String -> (i -> o) -> i -> o+traceAround funcName func = traceId ("output from " ++ funcName) . func . traceId ("input to " ++ funcName)