Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It might be easier to use combinators, e.g. <code>_S</code> and <code>_K</code>, symbolically, and not their definitions as lambda-expressions,</p> <pre><code>_S f g x = f x (g x) _K x y = x </code></pre> <p>With functions, <code>fmap</code> is <code>(.)</code> and <code>&lt;*&gt;</code> is <code>_S</code>, as others already mentioned. So,</p> <pre><code>sequenceA [(+3),(+2)] 3 == ( ((:) &lt;$&gt; (+3)) &lt;*&gt; sequenceA [(+2)] ) 3 == _S ((:).(+3)) ( ((:) &lt;$&gt; (+2)) &lt;*&gt; pure [] ) 3 == _S ((:).(+3)) ( _S ((:).(+2)) (_K []) ) 3 == ((:).(+3)) 3 ( _S ((:).(+2)) (_K []) 3 ) == ((:).(+3)) 3 ( ((:).(+2)) 3 (_K [] 3) ) == (6:) ( (5:) [] ) == [6,5] </code></pre> <p>So it might be easier to decompose expressions down to basic functions and combinators and stop there (i.e. <em>not</em> decomposing <em>them</em> to their lambda expressions), using their <em>"re-write rules"</em> in manipulating the expression to find its more comprehensible form.</p> <p>If you wanted to, you could now write down for yourself a more abstract, informal re-write rule for <code>sequenceA</code> as</p> <pre><code>sequenceA [f,g,..., z] == _S ((:).f) . _S ((:).g) . _S ..... . _S ((:).z) . _K [] </code></pre> <p>and so</p> <pre><code>sequenceA [f,g,..., z] a == ((:).f) a $ ((:).g) a $ ..... $ ((:).z) a $ _K [] a == (f a:) $ (g a:) $ ..... $ (z a:) $ [] == [f a, g a, ..., z a] </code></pre> <p>and hence</p> <pre><code>sequenceA fs a == map ($ a) fs == flip (map . flip ($)) fs a </code></pre> <p>to wit,</p> <pre><code>Prelude Control.Applicative&gt; flip (map . flip ($)) [(+3),(+2)] 3 [6,5] </code></pre>
    singulars
    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. 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.
    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