-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explicit Environments #41
Comments
In the expression language, rather than the value language, we could indeed have
meaning the matching environment, with the possibility of an exception. I think this is way cooler and more economical than the practical-joke-on-JSON option. |
I'm now bikeshedding the operator with myself. So join in. I'm wondering whether the symmetrical I.e., not just "as-patterns", but I'm wondering whether |
Open for business on this branch. |
I haven't put it in the JS interpreter yet, but I did three things:
So local definition is now as follows:
Now, this plays merry hell with scope checking. For the moment, things scope-checked as local or out of scope can be captured by an explicit environment, but things scope-checked as global cannot. That creates the obvious problem that making new definitions in an imported module can change the meaning of a program by preventing an explicit environment from capturing and shadowing a name, e.g., the We have options.
Note that I avoided extending the value type by writing code to marshal and unmarshal values and finite maps. In JS, I'll probably just have to start representing environments as association trees instead of JS objects. Again, big design space. |
I've done 4, above. All shortnamed variables can be shadowed. |
There are still bikeshed options for the notation. Alternatives to Moreover, we should consider the option to flip things around and write
I'm currently warming to |
Tangentially, the often insightful twitter haskeller, @ luqui, observes that we could reduce the weight of the notation by making
means the same as
Note that if
This would either make it very good or very bad to retain It also combines nicely with the idea that guarding by Booleans (numbers 0 or not) is contextualization.
aborts if We currently have a special kind of stack frame dedicated to being left of a semicolon. Adopting this proposal would replace it by yer ordinary |
One worry is that we might want to use One thing that confuses me is that I could well have imagined that the role of |
We certainly do want Non-singleton examples include things like
Unification of patterns is a generalization of as-patterns, and is reducible to as-patterns. OK, we need the "grumpy" pattern, $#!£, which refuses to match anything. We have
and such like. I worry that |
Could we also reuse as-patterns but on the RHS? |
Whilst I've also just realised that
I think the |
OK, here's where I think we are with this:
|
It's now a pull request. But I'm sure there are still things to fix. |
Alea iacta est. |
I started talking about explicit environments on #37 and on Slack. Let me be both broader and deeper in an issue of its own.
The idea is to introduce a crude but alarmingly effective form of what some might call "object orientation" if they wanted to try to wind us up: as a tactic, it wouldn't work on me, anyway.
Yer regular "mathematical" functions are, at least in a cbv language, an extreme form of contextualization. In
f(a)
,f
contextualizesa
by waiting patiently for its value, and then postprocessing it. Meanwhile, back in dear old Pascal, one could writewhere
r
is an expression of record type andc
is a command for whichr
's fields are in scope.c
could, of course, bereturn e
, but it was a tad annoying that there was no version ofwith
in the expression language, only in the command language. One of my main irritations (for it is superficial) with oo style, is all that projection all over the place like bad acne. I went through a period (ha ha) of pronouncing.
as "spot" rather than "dot". IIRC, there's a version of this rant in my thesis. Anyhow,r
contextualisesc
by allowing lookup asc
runs, and quietly going away whenc
stops. It's pretty much the other extreme from functions, when it comes to what activities "contextualization" amounts to.So I'm proposing an notion of first class environment
e
which allows us to writeto contextualize the evaluation of
a
by the value bindings ine
.What is such an
e
? It's an association tree.[]
['var | value]
[env0 | env1]
whereenv0
's bindings may shadowenv1
's.So, we're exploiting the fact that atoms apart from
[]
are the quotations of identifiers. (Indeed, perhaps it is now stretching a point to call[]
an atom, given that it does not quote an identifier, you can't write it with a quote-mark, etc. But it is, at least, genuinely indivisible, which quoted identifiers wouldn't be if were to allow them to explode as strings.) We can tell the difference between a singleton and a binary by checking their heads. We can thus crunch such a structure down to a Haskell map or a JS object, when we need to use it as an actual environment.Why is it a tree and not a list? It's a monoid, so why bother normalising it? Also, you get to preserve sharing when you build bigger environments from smaller ones. Bargain basement inheritance is gained by the expedient of shoving old environments at the back end of new ones.
In the it-looks-like-C-but-it-so-isn't brutality of this language, I am sorely sorely tempted to make the notation
sugar for
so that we can (never let that mean assignment and also) write things like
and yer common or garden
let x = s in t
becomes
(x = s)(t)
Around the corner, there's the option to consider pattern matching as "compute an explicit environment or abort", where our beloved
->
is also concealing yet another use of application-as-contextualization.It's cheap; it's fun; it's encapsulation for hooligans. It's the polite version of dynamic binding, just as we're already doing the polite version of delimited control.
Shall we do this?
The text was updated successfully, but these errors were encountered: