Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The first thing to note is the signature of <code>getLines</code>. Since <code>p `isPrefixOf`</code> has type <code>(Eq a) =&gt; [a] -&gt; Bool</code>, <code>getLines p</code> has type <code>(Eq a) =&gt; [[a]] -&gt; [[a]]</code> (based on the type of <code>filter</code>). Here <code>[a]</code> seems to be <code>String</code>, so <code>getLines p</code> has type <code>[String] -&gt; [String]</code> and <code>p</code> thus seems to have type <code>String</code>. So in fact, <code>getLines</code> has type <code>String -&gt; [String] -&gt; [String]</code>.</p> <p>Lastly, <code>head</code> has (specialized) type <code>[String] -&gt; String</code>, and you're trying to postcompose it with <code>getLines</code>. I would guess you're trying to build a function with type <code>String -&gt; [String] -&gt; String</code>, defined by <code>\p ss -&gt; head (getLines p ss)</code>. That is, however, <em>not</em> what <code>head . getLines</code> is!</p> <p>To see this, consider <code>f :: a -&gt; b -&gt; c</code> and <code>g :: c -&gt; d</code> (where I mean to say that the <code>c</code>s are the same type in both signatures, so I'm not really writing proper Haskell signatures here). Since one often likes to think of <code>f</code> as a "function of two variables", one might err and think of <code>g . f</code> as being the function <code>\x y -&gt; g (f x y)</code> (type <code>a -&gt; b -&gt; d</code>). This is not the case: See for example <a href="https://stackoverflow.com/q/5821089/453616">this question and its answers</a> or the concrete example in <a href="https://stackoverflow.com/a/4341123/453616">this answer.</a> Or even better: Look at <a href="http://hackage.haskell.org/package/base-4.6.0.1/docs/Prelude.html#g:10" rel="nofollow noreferrer">the type of</a> <code>(.)</code> and work out what <code>g . f</code> must be yourself! (Hint: <a href="http://learnyouahaskell.com/higher-order-functions" rel="nofollow noreferrer">Every function takes precisely <em>one</em> argument</a>. What is the type of <code>f</code>'s one argument?)</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