title: How does "(\x y z -> [x,y,z]) <$> (+3) <*> (*2) <*> (/2) $ 5 " really work?
body: <p>In <a href="http://learnyouahaskell.com/functors-applicative-functors-and-monoids" rel="nofollow noreferrer">this example from Learn you a Haskell</a>, the author showed how to declare an instance of <code>Applicative</code> for function <code>-&gt;r</code></p>
  
  <pre><code>instance Applicative ((-&gt;) r) where  
      pure x = (\_ -&gt; x)  
      f &lt;*&gt; g = \x -&gt; f x (g x)  
  </code></pre>
  
  <p>Later on, he gave a concrete example</p>
  
  <pre><code>ghci&gt; (\x y z -&gt; [x,y,z]) &lt;$&gt; (+3) &lt;*&gt; (*2) &lt;*&gt; (/2) $ 5  
  [8.0,10.0,2.5]  
  </code></pre>
  
  <p>I try to reason this snippet step by step</p>
  
  <ol>
  <li>Seeing <code>(+3) &lt;*&gt; (*2) &lt;*&gt; (/2)</code> as <code>f &lt;*&gt; g &lt;*&gt; h</code> and thinking that <code>f &lt;*&gt; g &lt;*&gt; h</code> returns a function <code>\x -&gt; f x (g x (h x))</code>, I thought <code>(+3) &lt;*&gt; (*2) &lt;*&gt; (/2)</code> returns a function <code>\x -&gt; x+3 (x*2 (x/2))</code>. But I can not do <code>:t (+3) &lt;*&gt; (*2) &lt;*&gt; (/2)</code> in ghci, which raises this error</li>
  </ol>
  
  <pre><code>error:
      • Occurs check: cannot construct the infinite type:
          a1 ~ a -&gt; a1 -&gt; b
        Expected type: (a -&gt; a1 -&gt; b) -&gt; a1
          Actual type: a1 -&gt; a1
      • In the second argument of ‘(&lt;*&gt;)’, namely ‘(/ 2)’
        In the expression: (+ 3) &lt;*&gt; (* 2) &lt;*&gt; (/ 2)
  </code></pre>
  
  <ol start="2">
  <li>If <code>(+3) &lt;*&gt; (*2) &lt;*&gt; (/2)</code> does return a function <code>\x -&gt; x+3 (x*2 (x/2))</code>, how does it pattern match with the lambda function <code>\x y z -&gt; [x,y,z]</code>? (Actually I am still having some trouble to understand lambda functions except for the really basic simple ones.)</li>
  </ol>