Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The key to understanding currying is to understand that there is no such thing as a function with more than one argument. <em>Every</em> function in haskell has exactly one argument. But because of the right-associative properties of the <code>-&gt;</code> operator, that's not immediately clear. </p> <p>When you see this: </p> <pre><code>Integer -&gt; Integer -&gt; Integer </code></pre> <p>It is equivalent to this:</p> <pre><code>Integer -&gt; (Integer -&gt; Integer) </code></pre> <p>In both cases, the function takes an <code>Integer</code> and <em>returns a function</em>. (The function returned is one that takes an <code>Integer</code> and returns an <code>Integer</code>.) So this might be something like a simple mathematical operation; it takes an <code>Integer</code> (let's say 5) and returns a function that takes another <code>Integer</code> (5 again) and adds it to the first one, and returns the result (10). </p> <p>But when you do this:</p> <pre><code>(Integer -&gt; Integer) -&gt; Integer </code></pre> <p>You've created something very different -- a function that <em>takes</em> a function and returns an <code>Integer</code>. This could also be a way of implementing a mathematical function; but instead of taking an <code>Integer</code> as the first argument, it takes the mathematical operation itself! So for example, say you pass to this function a function that adds 5 to whatever is passed to it. This function then passes <code>5</code> to <em>that</em> function, and returns the result (10). </p>
 

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