Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>ghci</code> is your friend:</p> <pre>*Main> :t map head map head :: [[a]] -> [a] *Main> :t map tail map tail :: [[a]] -> [[a]]</pre> <p>Even if you don't understand <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3Amap" rel="nofollow noreferrer"><code>map</code></a> (a problem you'd want to correct quickly!), the types of these expressions tell much about how they work. The first is a single list taken from a list of lists, so let's feed a simple vector to it to see what happens.</p> <p>You might want to write</p> <pre><code>*Main&gt; map head [1,2,3] </code></pre> <p>but that fails to typecheck:</p> <pre>&lt;interactive>:1:14: No instance for (Num [a]) arising from the literal `3' at :1:14 Possible fix: add an instance declaration for (Num [a]) In the expression: 3 In the second argument of `map', namely `[1, 2, 3]' In the expression: map head [1, 2, 3]</pre> <p>Remember, the argument's type is a list of lists, so</p> <pre><code>*Main&gt; map head [[1,2,3]] [1] </code></pre> <p>Getting a bit more complex</p> <pre><code>*Main&gt; map head [[1,2,3],[4,5,6]] [1,4] </code></pre> <p>Doing the same but with <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3Atail" rel="nofollow noreferrer"><code>tail</code></a> instead of <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3Ahead" rel="nofollow noreferrer"><code>head</code></a> gives</p> <pre><code>*Main&gt; map tail [[1,2,3],[4,5,6]] [[2,3],[5,6]] </code></pre> <p>As you can see, the definition of <code>transpose</code> is repeatedly slicing off the first “row” with <code>map head x</code> and transposing the rest, which is <code>map tail x</code>.</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. 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