Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Put simply, <code>.</code> is function composition, just like in math:</p> <pre><code>f (g x) = (f . g) x </code></pre> <p>In your case, you are creating a new function, <code>sumEuler</code> that could also be defined like this:</p> <pre><code>sumEuler x = sum (map euler (mkList x)) </code></pre> <p>The style in your example is called "point-free" style -- the arguments to the function are omitted. This makes for clearer code in many cases. (It can be hard to grok the first time you see it, but you will get used to it after a while. It is a common Haskell idiom.)</p> <p>If you are still confused, it may help to relate <code>.</code> to something like a UNIX pipe. If <code>f</code>'s output becomes <code>g</code>'s input, whose output becomes <code>h</code>'s input, you'd write that on the command-line like <code>f &lt; x | g | h</code>. In Haskell, <code>.</code> works like the UNIX <code>|</code>, but "backwards" -- <code>h . g . f $ x</code>. I find this notation to be quite helpful when, say, processing a list. Instead of some unwieldy construction like <code>map (\x -&gt; x * 2 + 10) [1..10]</code>, you could just write <code>(+10) . (*2) &lt;$&gt; [1..10]</code>. (And, if you want to only apply that function to a single value; it's <code>(+10) . (*2) $ 10</code>. Consistent!)</p> <p>The Haskell wiki has a good article with some more detail: <a href="http://www.haskell.org/haskellwiki/Pointfree" rel="noreferrer">http://www.haskell.org/haskellwiki/Pointfree</a></p>
    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. 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.
    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