Created
July 8, 2017 23:01
-
-
Save kunigami/96353028ff7fdc747aa12f88ceb15b5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
* exec evaluates the first element of the schedule stream. Because of memoization, this means that | |
* whenever we evaluate 'front', we guarantee that all operations are already memoized. | |
*) | |
let exec ({ front; rear; schedule }: 'a realTimeQueue) = | |
match schedule with | |
| lazy (StreamCell (_, rest_schedule)) -> | |
{ front; rear; schedule = rest_schedule } | |
(* Due to invariants, this means that |rear| > |front| *) | |
| lazy Nil -> | |
(* Now newFront = front @ (rev rear) *) | |
let newFront = rotate {front; rear; schedule = Stream.empty} in | |
{front = newFront; rear = []; schedule = newFront} | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment