[Haskell-cafe] STG Program to invoke rule 17?

Siddharth Bhat siddu.druid at gmail.com
Mon Jun 5 13:46:12 UTC 2017

I'm reading the original STG paper
and implementing it along the way. (Raw link to paper:
I'm not able to figure out how to invoke rule 17 at all. This rule is to
update a function call which calls another function. I've tried creating
examples, but all of them wind up invoking the constructor update rule.

╰─$ cat stg-programs/updatable-fn-calls.stg
define nu = {} \n {x, y, w, z} -> x {};
define main = {} \n {} -> let
                            x = {} \n {} -> One {};
                            y = {} \n {} -> Two {};
                            // closure to update
                            update = {x, y} \u {} -> nu {x, y, y, y};
                            // have something in argument stack
                            kickstart = {update} \n {a, b} -> update {};
                            // make sure this is never evaluated
                            bottom = {} \n {} -> bottom {}
                         in case (kickstart {bottom, bottom}) of
                                 One {} -> Done {};

This was a program I tried, hoping that the "kickstart" function would
ensure that there is something on the argument stack, so that when "nu" is
entered, the rule would trigger. However, in my toy STG implementation
here (simplexhc
link) <https://github.com/bollu/simplexhc> (Raw:
https://github.com/bollu/simplexhc), the rule is not triggered. You can run
it with:
$ stack build && stack exec simplexhc -- stg-programs/updatable-fn-calls.stg

I believe I have either misunderstood the rule or mis-implemented it. So if
someone could point me to a reference of how to trigger the rule, I'd be
very thankful.
I'd like to have some intuition on the rule and "why it works".

~ Siddharth
Sending this from my phone, please excuse any typos!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170605/90146d98/attachment.html>

More information about the Haskell-Cafe mailing list