Skip to content

Instantly share code, notes, and snippets.

@luqui
Created May 29, 2012 05:53
Show Gist options
  • Save luqui/2822844 to your computer and use it in GitHub Desktop.
Save luqui/2822844 to your computer and use it in GitHub Desktop.
Stuck on Sequent

I admit, I am stuck. I don't know what to do next on this project. I have a very simple javascript repl, it really is nothing fancy, and the first innovative feature I have I can't figure out how to implement.

The feature is abstraction. My working example, not anything practical, has been

two = 1 + 1              --> 2
four = two + two         --> 4
eight = four + four      --> 8

This represents an interactive session in which the programmer was experimenting with things, tweaking them, trying to get things to come out just right for two. Now that the correct answer has come out, the programmer wants to abstract his solution to work for any value of two. I picture a little button next to two (maybe in a menu -- whatever), which will purge two from the definitions and move it to the environment of the functions that use it; roughly

four = \two -> two + two
eight = \two -> four(two) + four(two)

like closing a Coq section. However, we don't have the luxury of being able to analyze (or perhaps I should say we have the luxury of not being able to analyze) javascript source, so we can't quite do it this way. The first solution I came up with was to allow objects to have signatures (which are still dependent on the environment):

[two]  four = two + two

[two]  let four = four({two: two})
       eight = four + four

And the other is to introduce nested scopes:

[two]
    four = two + two
    eight = four + four

I suppose in the philosophy of Sequent these are both correct -- equivalent -- two ways to see the same thing. However, I don't think that starting with the former we can easily transform to the latter, that let is a bit too powerful. I suppose if the structure of let is sufficiently restricted then we could move back and forth, but there is a hint of an underlying structure into which these could both be views. I wonder what it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment