Skip to content

Commit

Permalink
Annotated execution
Browse files Browse the repository at this point in the history
  • Loading branch information
edsko committed Dec 17, 2023
1 parent a59bccb commit 9bf052c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist-newstyle/
.stack-work
.cabal.sandbox.config
.envrc
foo.js
18 changes: 18 additions & 0 deletions examples/circular_hos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
-- > --hide-selector-thunk-opt \
-- > --javascript foo.js \
-- > -i examples/circular_hos.hs
--
-- Annotated execution (as of a59bccb):
--
-- 2. As soon as we demand the value of @maxBV body_0@ to determine the
-- variable to be used for the outer-most lambda, this will force the
-- construction of the next term down. This happens recursively, so the
-- entire term is build in memory.
-- 14. This is an instructive subsequence: we will see the evaluation of
-- the simple term @lam (\y -> y)@.
-- 20. At this point this term is fully known: @Lam 1 (Var 1)@.
-- 21. The computation is driven by the computation of the variable to be used
-- for the outermost lambda; we can now continue this computation a little
-- bit, because we now know the @maxBV@ of the subterm @Lam 1 (Var 1)@.
-- 22. We repeat for the second simple term @lam (\z -> z)@.
-- 32. At this point we're almost done: we need to know the @max@BV@ of the
-- subterm @Var n_1@, but there aren't any, so that is just @0@.
-- 34. At this point all bound variables are known, and the new term has been
-- constructed.
maxBV = (\exp ->
case exp of {
Var x -> 0
Expand Down
16 changes: 16 additions & 0 deletions examples/repmin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
-- > --hide-selector-thunk-opt \
-- > --javascript foo.js \
-- > -i examples/repmin.hs
--
-- Annotated execution (as of a59bccb):
--
-- 1. One way to think about this circular program is to consider that it
-- first creates a pointer to an int (the new value in the leaves), and
-- then starts building up a tree with all leaves pointing to this int;
-- as it builds the tree, it is also computing the value of this int.
-- 6. We're starting to see the tree take shape here; the top-level structure
-- of the tree is now known.
-- 10. Similarly, we now see the shape of the left subtree.
-- 13. Here we see the first @Leaf@, ponting to @m_1@; part of the computation
-- of @m_1@ is now also known (@mb_7@).
-- 16. The second @Leaf@ is known.
-- 18. The minimum value of the left subtree is known (@mb_4@).
-- 28. At this point the structure of the tree is mostly done. We can
-- finish the value computation.
worker = (\m -> \t ->
case t of {
Leaf x -> Pair x (Leaf m)
Expand Down

0 comments on commit 9bf052c

Please sign in to comment.