debug-trace-var: You do not have to write variable names twice in Debug.Trace

[ debug, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

Please see the README on GitHub at https://github.com/ncaq/debug-trace-var#readme


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.2.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), template-haskell, unicode-show [details]
License MIT
Copyright © ncaq
Author ncaq
Maintainer ncaq@ncaq.net
Category Debug
Home page https://github.com/ncaq/debug-trace-var#readme
Bug tracker https://github.com/ncaq/debug-trace-var/issues
Source repo head: git clone https://github.com/ncaq/debug-trace-var
Uploaded by ncaq at 2018-06-09T15:11:04Z
Distributions LTSHaskell:0.2.0, NixOS:0.2.0, Stackage:0.2.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1750 total (13 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-06-09 [all 1 reports]

Readme for debug-trace-var-0.2.0

[back to package description]

Hackage Stackage LTS

debug-trace-var

When writing print debug, we often write.

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.

{-# LANGUAGE QuasiQuotes #-}
import           Debug.Trace.Var

main :: IO ()
main = do
  let a = 1
  [traceVarIO|a|]

or

{-# LANGUAGE TemplateHaskell #-}
import           Debug.Trace.Var

main :: IO ()
main = let a = 1 :: Int
       in $(traceMTH 'a)

You may avoid name quotes that are confusing with character literals, Or often it may be to avoid the QuasiQuotes to destroy the syntax highlight of the text editor.

Example

{-# LANGUAGE QuasiQuotes     #-}
{-# LANGUAGE TemplateHaskell #-}

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|]

-- > f
-- n = 344
f :: IO ()
f = let n = 344
    in $(traceMTH 'n)

Motivation

I wanted to use Template Haskell.

One point advice

You can use ndmitchell/debug: Haskell library for debugging