-
Notifications
You must be signed in to change notification settings - Fork 54
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
Delay type #223
Delay type #223
Conversation
- Add a new type constructor `delay` - `TDelay` is now written with special double brackets `{{...}}`; `{{t}} : delay ty` whenever `t : ty` - Add a special case to the parser: `{{}}` parses as `delay noop` - `force : delay ty -> ty` is now written as a prefix `!` e.g. `{{5}} : delay int` and `!{{5}} : int` - Change the types of `build` and `reprogram` to require a delayed program, e.g. `build : string -> delay (cmd a) -> cmd string` - Don't elaborate `Build` and `Reprogram` with extra `Delay` wrappers since one is now required by the type
Once we're all on the same page re syntax etc, I will update the tutorial and example programs. |
This made me realize a few things and I'm wondering if we should do this at all. Adding my thoughts/questions to #150 so the conversation doesn't get fragmented. |
Now that the arguments to `if` must be delayed: - Remove the elaboration for applications of `if` - Assume the arguments will be VDelay at runtime
It is now a CESK machine, though we don't yet use the store for anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I only have a few nits.
I reviewed the PR because if I understand the github UI correctly you did request a review. But the step function is not modified yet. Is it because you'd like to stage the review? (Which is very much welcome if that is the case: it's always easier to review small chunks.) Or is it because you're planning on modifying the step function in a different PR?
@polux I think I requested a review when I initially opened the PR. I didn't specifically request one just now, but I appreciate the feedback, and you're right, reviewing in small chunks is helpful! I do plan to update the step function in this PR. Right now a store exists but is never used for anything. |
Some bugs to fix noted by comments, and we still don't yet use memoized delay for recursion.
Note, `Build` and `Reprogram` still need to be updated.
I think this is ready for another round of review. Note that at the moment, all delays are non-memoizing except for recursive |
Great work @byorgey! 👍 I will play with this some more, but the first thing I thought about was that it would be helpful to add the braces to F1 help:
Could you please add a table of types, now that we have |
Good ideas @xsebek , will do! |
How do you think the table of types should fit with the rest of the help? If I just add another table horizontally they all get too narrow in a reasonably-sized terminal window. |
Also it seems this fixes the wait cancellation 🥳 #194 |
I updated my
The improvement is small*, but it is there and all that matters is that it is not slower. 👍 There is a small bug with cancelling and then repeating a long computation, for example: > let lbiggest = cons (2^2^21) $ cons (2^2^7) nil in len lbiggest // Ctrl-C
> let lbiggest = cons (2^2^21) $ cons (2^2^7) nil in len lbiggest
fatal error: Reference to unknown memory
cell 16
|
@byorgey ad F1 help - I was thinking the table would be above commands, but it may need scrolling to fit in smaller terminals. Which is probably OK as it is focused and can use ⬇️ and ⬆️ . We can leave that for another PR - with scrolling we could even list all available commands. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incredible work @byorgey! I think this is good to merge except for the problem with cancelling computation, which is unchecked and hopefully easy to fix. 🙂
You're right, it does fix #194, though I didn't realize I was fixing it. =) The bug previously was that we did Ctrl+C just by setting the robot's machine to |
Hmm, good catch re: Ctrl+C causing problems with memory cells. This is a bit tricky. When we hit Ctrl+C we set the base's Perhaps the solution is that a Hmm, I discovered by accident that we can end up with stray |
- Add functions `cancel` and `resetBlackholes` to reset the store properly - Use those functions (1) when cancelling the base computation via Ctrl+C, or (2) when there is an uncaught exception
This ought to fix the issues with Ctrl+C and the store. |
Based on suggestion in #223 (comment) . Not quite sure how to effectively use it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I gave it a good look but couldn't find anything really meaningful to say.
-- body, binding the variable to a reference to the memory cell we | ||
-- just allocated for the body expression itself. As a fun aside, | ||
-- notice how Haskell's recursion and laziness play a starring | ||
-- role: @loc@ is both an output from @allocate@ and used as part |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminds me of "Assembly: Circular Programming with Recursive do" in https://wiki.haskell.org/wikiupload/1/14/TMR-Issue6.pdf :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ought to fix the issues with Ctrl+C and the store.
I checked it out and it works perfectly! 🥳
Make explicit in the type system when evaluation of a computation should be delayed. This gives the user fine-grained control over selective laziness (for example, once we have sum types and recursive types, one could use this to define lazy infinite data structures). It also allows us to guarantee that certain commands such as
build
andreprogram
delay evaluation of their arguments, and lets the user e.g. define their own modified versions ofbuild
without compromising those guarantees.t : ty
then{t} : {ty}
.force : {ty} -> ty
is now exposed in the surface language.let
anddef
delay via allocating a cell in the store. For now, there is no other way to allocate anything in the store, but see discussion at Error when wrapping build #150 for some possible future directions.build
andreprogram
to require a delayed program, e.g.build : string -> {cmd a} -> cmd string
if
andtry
also require delayed arguments.Closes #150. Closes #226.