Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It means exactly what the error says. You have specified that the type of your function is</p> <pre><code>divideby :: ( Int-&gt;Int -&gt; Int ) -&gt; Int -&gt;float </code></pre> <p>That means, the first argument must be a function, with the type <code>Int-&gt;Int -&gt; Int</code>, and the second input must be an <code>Int</code>, and then it will produce a <code>float</code>. Naturally, Haskell does not know how to divide a function by an Int, which is what you are telling it to do with the expression <code>f / z</code>.</p> <hr> <p>In response to the comment: no. That is not a higher-order function, but it is close. Take a look:</p> <pre><code>addNum :: Int -&gt; Int -&gt; Int addNum a b = a + b divideBy :: Int -&gt; Int -&gt; Int -&gt; Int divideBy a b c = (addNum a b) `div` c </code></pre> <p><code>divideBy</code> is a function that takes 3 <code>Int</code>s as input, and produces an <code>Int</code>. Since its inputs are merely <code>Int</code>, it is <em>not</em> a higher-order function. However, you could abstract the use of <code>addNum</code> into an input, thus making it a higher-order function. <code>addNum</code> has type <code>(Int -&gt; Int -&gt; Int)</code>, so, in addition to the inputs we have already, we will make that the type of our first input</p> <pre><code>divideBy :: (Int -&gt; Int -&gt; Int) -&gt; Int -&gt; Int -&gt; Int -&gt; Int divideBy f a b c = (f a b) `div` c </code></pre> <p><em>This</em> is a higher-order function, that also compiles correctly and has meaning. :) You can pass <code>addNum</code> as an input to this function.</p> <pre><code>ghci&gt; divideBy addNum 2 4 6 -- (2 + 4) / 6 1 </code></pre>
 

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