I was working on this tool for inspecting values at runtime recently - https://hackage.haskell.org/package/heap-console
Basically, it let's you pause at presence of special combinators, starting console which you can use to inspect and force custom bindings.
If anyone wants some more powerful alternative to traceShow, you can give it a go - personally I'm excited to try it out in compiler-ish stuff where I often want to explore big, nested values to find out what went wrong. :smile:
ah I guess what was confusing me is that I expected the inspectD version to be the one creating bindings, as opposed to inspect, because this is the first time inspectD is mentioned in the docs and it's in the context of bindings
something that would be really cool is a pattern synonym that you can add to a particular case match and get all the bindings from that case match in the "console" automatically
something that would be really cool is a pattern synonym that you can add to a particular case match and get all the bindings from that case match in the "console" automatically
That's a cool idea - maybe I could make quasiquoter like
well I kind of realised my original suggestion is easily doable as is, no? the issue is more that you need a way to access the "fields" of the constructor if it's not a record type
Thank you guys for feedback! One question - do you think it would be better to preserve all bound values between console runs? (not just those bound with evidence-like combinators)
Hmm, thing is, this basically only changes behaviour of it and binds created in console
I guess binding lots of things with evidence is more probable, and in that case, I could implement the opposite - cleaning of binds when closing console
But if that's going to be an option, I probably need to start thinking about persistent configuration - how would that work in app that may be tested through cabal run or from completely different location?
Version on GitLab now preserves state across console runs - and I've added option to clean bindings on console exit (now it can be at least slightly useful)
I've pushed new version on GitLab with refactored console that should be easier to extend and should make it easier to support auto-complete - once I finish Generic I'll make a new release and start working on tests
@Georgi Lyubenov // googleson78 I've just realized why Generic may be slightly more problematic - it hides actual laziness of input value, so lazy indexing isn't very informative
I was working on this tool for inspecting values at runtime recently - https://hackage.haskell.org/package/heap-console
Basically, it let's you pause at presence of special combinators, starting console which you can use to inspect and force custom bindings.
If anyone wants some more powerful alternative to
traceShow
, you can give it a go - personally I'm excited to try it out in compiler-ish stuff where I often want to explore big, nested values to find out what went wrong. :smile:cool!
Bindings can be automatically created with functions like inspectD
what doesBindings
mean here?They're just values bound to some names inside of console
Will make it more clear in docs, thanks for mentioning!
so if I use
inspectD 42
what binding is automatically created? it might be a good idea to show this in the example forinspectD
Yeah, it gets bound to
it
as mentioned ininspect
s descriptionI guess I will move longer descriptions to
D
versions and add queries forit
in examples, thanks!ah I guess what was confusing me is that I expected the
inspectD
version to be the one creating bindings, as opposed toinspect
, because this is the first timeinspectD
is mentioned in the docs and it's in the context of bindingssomething that would be really cool is a pattern synonym that you can add to a particular case match and get all the bindings from that case match in the "console" automatically
but I'm not sure this is possible without a source plugin or something
D
is forData
- they otherwise behave in the same wayGeorgi Lyubenov // googleson78 said:
That's a cool idea - maybe I could make quasiquoter like
that works in both expressions and patterns
well I kind of realised my original suggestion is easily doable as is, no? the issue is more that you need a way to access the "fields" of the constructor if it's not a record type
e.g. indexing?
e.g.
and now you can write
and
right?
Yeah - I thought you mean binding variables introduced by pattern
though I wonder whether it's big win over
(inspectD -> Person ...)
:smile:yeah I guess the only thing missing is reusing the actual names you've bound in the program
Yeah, that's hard without TH or plugin
very interesting!
This is super cool. Looking forward to trying it out in a project!
Thank you guys for feedback! One question - do you think it would be better to preserve all bound values between console runs? (not just those bound with
evidence
-like combinators)I would say no, as it could get expensive in some apps. Having the ability to optionally do that might be cool, but I'd default to no.
Hmm, thing is, this basically only changes behaviour of
it
and binds created in consoleI guess binding lots of things with
evidence
is more probable, and in that case, I could implement the opposite - cleaning of binds when closing consoleBut if that's going to be an option, I probably need to start thinking about persistent configuration - how would that work in app that may be tested through
cabal run
or from completely different location?I have no idea what black magic you use for
evidence
, but couldn't you use that to have a function that turns a flag on or off?it's an
IORef
containing aMap
!a noinline global
IORef
*so to answer @Vladimir Ciobanu 's question: yes!
Oh, lol. An actual global variable. Neato. So why not stick the option in there, and provide on/off helpers.
I'm not that worried about adding bindings based on control flow - but I feel more uneasy about doing so with configuration :sweat_smile:
Not like this is meant for something other than debugging, but still
Version on GitLab now preserves state across console runs - and I've added option to clean bindings on console exit (now it can be at least slightly useful)
BTW, what do you think about searching for
.heap-console
conf file in location of executable?And
:save
command that dumps settings thereare there any other settings?
(also, I'd recommend in the location of the executable, and also recursively in parents, so it's easier to use with something like stack)
Georgi Lyubenov // googleson78 said:
Sounds reasonable - will try it
prompt = "heap-console> "
hehe, nice
this "global" heap-console config seems to have turned out pretty nice for usage
put a universal one in home and forget about it
Next up on list are
Generic
support and refactoring of console - and I should really start writing tests :sweat_smile:I've pushed new version on GitLab with refactored console that should be easier to extend and should make it easier to support auto-complete - once I finish
Generic
I'll make a new release and start working on tests@Georgi Lyubenov // googleson78 I've just realized why
Generic
may be slightly more problematic - it hides actual laziness of input value, so lazy indexing isn't very informativeI guess I'll mention it as a drawback, similarly to problems with non-
Data
combinators