debug-trace-var (empty) → 0.1.0
raw patch · 6 files changed
+175/−0 lines, 6 filesdep +basedep +template-haskelldep +unicode-showsetup-changed
Dependencies added: base, template-haskell, unicode-show
Files
- ChangeLog.md +3/−0
- LICENSE +7/−0
- README.md +82/−0
- Setup.hs +2/−0
- debug-trace-var.cabal +41/−0
- src/Debug/Trace/Var.hs +40/−0
+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for debug-trace-var++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,7 @@+Copyright 2018 ncaq++Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,82 @@+[](https://hackage.haskell.org/package/debug-trace-var)+[](http://stackage.org/lts/package/debug-trace-var)++# debug-trace-var++When writing print debug, we often write.++~~~hs+import Debug.Trace++main :: IO ()+main = do+ let a = 1+ traceIO $ "a = " ++ show a+~~~++This is troublesome to describe the name of the variable twice.++With debug-trace-var you write variables only once.++~~~hs+{-# LANGUAGE QuasiQuotes #-}+import Debug.Trace.Var++main :: IO ()+main = do+ let a = 1+ [traceVarIO|a|]+~~~++# Example++~~~hs+{-# LANGUAGE QuasiQuotes #-}++import Debug.Trace.Var++-- > a+-- n = 1+-- s = "あ"+a :: IO ()+a = let n = 1+ s = "あ"+ in [traceVar|n|] ([traceVar|s|] return ())++-- > b+-- "n = 1+-- n = 1"+b :: String+b = let n = 1+ in [traceVarId|n|]++-- > c+-- n = 344+c :: IO ()+c = let n = 344+ in [traceStackVar|n|] (return ())++-- > d+-- n = 344+-- n = 344+d :: IO ()+d = do+ let n = 344+ [traceVarIO|n|]+ [traceVarIO|n|]++-- > e+-- n = 344+e :: IO ()+e = do+ let n = 344+ [traceVarM|n|]+~~~++# Motivation++I wanted to use Template Haskell.++# One point advice++You can use [ndmitchell/debug: Haskell library for debugging](https://github.com/ndmitchell/debug)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ debug-trace-var.cabal view
@@ -0,0 +1,41 @@+-- This file has been generated from package.yaml by hpack version 0.28.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: 792b5b4b1b3e1126e975c29ffdfc6897c6a82e610ec0b8e38511c6ee20708c50++name: debug-trace-var+version: 0.1.0+synopsis: You do not have to write variable names twice in Debug.Trace+description: Please see the README on GitHub at <https://github.com/ncaq/debug-trace-var#readme>+category: Debug+homepage: https://github.com/ncaq/debug-trace-var#readme+bug-reports: https://github.com/ncaq/debug-trace-var/issues+author: ncaq+maintainer: ncaq@ncaq.net+copyright: © ncaq+license: MIT+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10+extra-source-files:+ ChangeLog.md+ README.md++source-repository head+ type: git+ location: https://github.com/ncaq/debug-trace-var++library+ exposed-modules:+ Debug.Trace.Var+ other-modules:+ Paths_debug_trace_var+ hs-source-dirs:+ src+ ghc-options: -Wall -fwarn-tabs+ build-depends:+ base >=4.7 && <5+ , template-haskell+ , unicode-show+ default-language: Haskell2010
+ src/Debug/Trace/Var.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+module Debug.Trace.Var (traceVar, traceVarId, traceStackVar, traceVarIO, traceVarM) where++import Data.Maybe+import Debug.Trace+import Language.Haskell.TH+import Language.Haskell.TH.Quote+import Text.Show.Unicode++traceVar :: QuasiQuoter+traceVar = traceVarBase [|trace|]++traceVarId :: QuasiQuoter+traceVarId = traceVarBase [|traceId|]++traceStackVar :: QuasiQuoter+traceStackVar = traceVarBase [|traceStack|]++traceVarIO :: QuasiQuoter+traceVarIO = traceVarBase [|traceIO|]++traceVarM :: QuasiQuoter+traceVarM = traceVarBase [|traceM|]++traceVarBase :: Q Exp -> QuasiQuoter+traceVarBase traceFuncEQ = QuasiQuoter+ { quoteExp = \str -> AppE <$> traceFuncEQ <*> traceFormat str+ , quotePat = error "no support"+ , quoteType = error "no support"+ , quoteDec = error "no support"+ }++traceFormat :: String -> Q Exp+traceFormat str = do+ valueName <- fromMaybe (error $ "variable " ++ str ++ " is not found") <$> lookupValueName str+ concatE <- [|concat|]+ ushowE <- [|ushow|]+ return $ AppE concatE $+ ListE [LitE (StringL str), LitE (StringL " = "), AppE ushowE (VarE valueName)]