Calling local bindings from GHCi #424
Replies: 3 comments 6 replies
-
You'll also want to have a story for what to do with cases like this:
What should |
Beta Was this translation helpful? Give feedback.
-
I don't agree with the obvious solution. Particularly with regard to syntactic challenges like ambiguous names, I think it's useful to consider this in two layers:
|
Beta Was this translation helpful? Give feedback.
-
I've wanted this before. @cdsmith mentions stack traces and indeed IIRC one can do this with the GHCi debugger. I would love to keep the connection and unify the features as much as possible if we do this. I guess that means snooping the environment of arbitrary bytecode thunks? |
Beta Was this translation helpful? Give feedback.
-
Imagine a function like
One feature that I've often wished existed is being able to call local bindings like
localBinding1
from GHCi. Too often I've written a function with some local bindings, only to find out that it doesn't work, and that if I want to debug these bindings, I have to convert them into top-level bindings, debug and fix the them, and then convert them back into local bindings.A somewhat similar feature exists in GHCi: For interpreted modules, it's possible to use names that weren't exported.
So it'd be nice if, at least in interpreted modules (I strongly suspect it's impossible for compiled modules), you could call
foo.localBinding1
as long aslocalBinding1
is a binding that could, in principle, be floated to the top level (i.e. as long aslocalBinding1
doesn't have any free variables referencing bindings which are declared in a local scope). Except the obvious syntax with.
is already taken by record dot syntax, so for the sake of this discussion I'll be usingfoo$localBinding1
for now.There are five questions I have about this:
Is there interest in this?
I know I've wanted this feature quite a few times, but I'm curious how others feel.
What kinds of local bindings should be callable?
My intuition would be to count anything in a
where
block. Others might feel thatlet
should count as well, but this comes with some issues (see next section), and I would be happy to just usewhere
. Is there anything else besides these?How to deal with ambiguities?
Examples:
Should
function1$f
refer toid
or(+1)
? Thelet
s infunction2
look even murkier to me from that perspective, which is why I'd be happy to ignorelet
.The obvious solution would be to only allow
where
blocks that are directly attached to a function definition, rather than to an expression inside of it, though it'd be nice if there was an elegant way to handle those bindings as well.(Edit) Especially when we consider that this is mainly a UI limitation, and other downstream applications such as haskell-language-server might have better ways to let the user disambiguate these definitions, it seems like a very good idea to at least have the functionality in place to address any declaration, even if it ends up being the case that we cannot think of a good way to invoke some of them from GHCi.
Should bindings that can't be floated to the top level be allowed as well?
Example:
You could imagine calling
localBinding
like(function undefined 42 53)$localBinding
, whereupon GHCi would tell you that it's95
.I imagine this'd be quite useful, if perhaps a bit confusing to look at (but since the main purpose is debugging I'm not too concerned about that).
Is there a good reason not to allow this?
Would the design of GHCi make this unreasonably difficult to implement?
I am, as yet, not familiar with the intricacies of GHCi interpretation.
Beta Was this translation helpful? Give feedback.
All reactions