Skip to content

Instantly share code, notes, and snippets.

@kunigami
Created July 8, 2017 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/96353028ff7fdc747aa12f88ceb15b5d to your computer and use it in GitHub Desktop.
Save kunigami/96353028ff7fdc747aa12f88ceb15b5d to your computer and use it in GitHub Desktop.
(*
* 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