Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Being an idle goodfornothing, I thought I would make a computer do the expansion for me. So into GHCi, I typed</p> <pre><code>let pu x = "(\\_ -&gt; " ++ x ++ ")" let f &gt;*&lt; a = "(\\g -&gt; " ++ f ++ " g (" ++ a ++ " g))" </code></pre> <p>So now I have funny versions of <code>pure</code> and <code>&lt;*&gt;</code> which map strings which look like expressions to string which look like more complicated expressions. I then defined, similarly, the analogue of <code>sequenceA</code>, replacing functions by strings.</p> <pre><code>let sqa [] = pu "[]" ; sqa (f : fs) = (pu "(:)" &gt;*&lt; f) &gt;*&lt; sqa fs </code></pre> <p>I was then able to generate the expanded form of the example as follows</p> <pre><code>putStrLn $ sqa ["(+3)","(+2)"] ++ " 3" </code></pre> <p>which duly printed</p> <pre><code>(\g -&gt; (\g -&gt; (\_ -&gt; (:)) g ((+3) g)) g ((\g -&gt; (\g -&gt; (\_ -&gt; (:)) g ((+2) g)) g ((\_ -&gt; []) g)) g)) 3 </code></pre> <p>This last, copied to the prompt, yielded</p> <pre><code>[6,5] </code></pre> <p>Comparing the output from my "metaprogram" with the attempt in the question shows a shorter initial prefix of lambdas, arising from a shallower nesting of <code>&lt;*&gt;</code> operations. Remember, it's</p> <pre><code>(pure (:) &lt;*&gt; (+3)) &lt;*&gt; ((pure (:) &lt;*&gt; (+2)) &lt;*&gt; pure []) </code></pre> <p>so the outer <code>(:)</code> should be only three lambdas deep. I suspect the proposed expansion may correspond to a differently bracketed version of the above, perhaps</p> <pre><code>pure (:) &lt;*&gt; (+3) &lt;*&gt; pure (:) &lt;*&gt; (+2) &lt;*&gt; pure [] </code></pre> <p>Indeed, when I evaluate</p> <pre><code>putStrLn $ pu "(:)" &gt;*&lt; "(+3)" &gt;*&lt; pu "(:)" &gt;*&lt; "(+2)" &gt;*&lt; pu "[]" ++ " 3 " </code></pre> <p>I get</p> <pre><code>(\g -&gt; (\g -&gt; (\g -&gt; (\g -&gt; (\_ -&gt; (:)) g ((+3) g)) g ((\_ -&gt; (:)) g)) g ((+2) g)) g ((\_ -&gt; []) g)) 3 </code></pre> <p>which looks like it matches the (updated)</p> <pre><code>(\d -&gt; (\c -&gt; (\b -&gt; (\a -&gt; (\_ -&gt; (:)) a ((+3) a)) b ((\_ -&gt; (:)) b)) c ((+2) c)) d ((\_ -&gt; []) d)) 3 </code></pre> <p>I hope this machine-assisted investigation helps to clarify what's going on.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload