Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The lowercase letters in the type declarations are <strong>type variables</strong>. This means that when there is an <code>a</code> this must be the same type.</p> <p>Bracketed (eg <code>(a -&gt; b)</code>) subexpressions tend to mean that the function accepts a function as one of its parametres.</p> <p>Rectangular brackets indicate a list of something.</p> <p>So <code>map</code> accepts these arguments:</p> <ul> <li><code>(a -&gt; b)</code> a function that accepts one argument</li> <li><code>[a]</code> a list that the first argument function can act on</li> </ul> <p>and produces <code>[b]</code> a list as a result.</p> <p>We can decode <code>(.)</code> the same way:</p> <ul> <li><code>(a -&gt; b)</code> is a function that accepts a single argument</li> <li><code>(c -&gt; a)</code> is a function that produces the same typa as the argument to the first function</li> <li><code>c</code> an argument of the same type that the second function uses</li> </ul> <p>However Haskell can do a neat thing and that is if you omit an argument it returns a function that has the remaining signature. So <code>(.)</code> is commonly used to chain functions.</p> <p>Let's say we have 2 functions <code>ord :: Char -&gt; Int</code> which takes a character and returns it's integer representation and <code>add32 :: Int -&gt; Int</code> that adds 32 to it's argument.</p> <p>When we write <code>upcaseVal = add32 . ord</code> the function upcaseVal now has the signature <code>upcaseVal :: Char -&gt; Int</code> because the <code>(.)</code> function would have left it with <code>c -&gt; b</code> and we substitue thes in the function definition.</p> <p>So <code>foldr map</code> would have to be like this:</p> <ol> <li><code>foldr</code>'s first argument is a function that takes 2 arguments which <code>map</code> is.</li> <li>Since the functions output has to be of the same type as the second argument (<code>(a -&gt; b -&gt; b</code>) we see that in <code>map</code> <code>a = b</code></li> </ol> <p>Thus the final type will be: </p> <pre><code>(b -&gt; b) -&gt; [b] -&gt; [b] -&gt; b -&gt; [b] -&gt; b </code></pre> <p>But I guess that doesn't have to bother you that much since the compiler deals with stuff like this most of the time.</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. This table or related slice is empty.
    1. 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