Is there a (Template) Haskell library that would allow me to print/dump a few local bindings with their respective names? -


for instance:

let x = 1 in putstrln [dump|x, x+1|] 

would print

x=1, (x+1)=2 

and if there isn't currently, possible write similar?

i've solved problem now. not imagined, close. maybe else can use basis better version. either way, with

{-# language templatehaskell, lambdacase #-}  import language.haskell.th  dump :: expq -> expq dump tuple =     liste . map dumpexpr . getelems =<< tuple       getelems = \case { tupe xs -> xs; _ -> error "not tuple in splice!" }     dumpexpr exp = [| $(lite (stringl (pprint exp))) ++ " = " ++ show $(return exp)|] 

you ability like

λ> let x = true λ> print $(dump [|(not x, x, x == true)|]) ["ghc.classes.not x_1627412787 = false","x_1627412787 = true","x_1627412787 ghc.classes.== ghc.types.true = true"] 

which wanted. see, it's problem pprint function includes module prefixes , such, makes result... less ideally readable. don't yet know of fix that, other think usable.

it's bit syntactically heavy, because it's using regular [| quote syntax in haskell. if 1 wanted write own quasiquoter, suggest, i'm pretty sure 1 have re-implement parsing haskell, suck bit.


Comments