title: Type Specification in a Where Clause
body: <p>I'm trying to do something very simple as part of a homework. All I need to do is write a function that takes in a list of 2-tuples of numbers representing base and height lengths for triangles, and return a list of the areas corresponding to those triangles. One of the requirements is that I do that by defining a function and declaring its type in a <code>where</code> clause. Everything I've tried so far fails to compile, here's what I've got:</p>
  
  <pre><code>calcTriangleAreas xs = [triArea x | x&lt;-xs]
      where triArea:: (Num, Num) -&gt; Num --this uses 4 preceding spaces 
  triArea (base, height) = base*height/2
  </code></pre>
  
  <p>This fails with the error <code>The type signature for ‘triArea’ lacks an accompanying binding</code>, which to me sounds like triArea is not defined inside of the where-clause. Okay, so let's indent it to match the <code>where</code>:</p>
  
  <pre><code>calcTriangleAreas xs = [triArea x | x&lt;-xs]
      where triArea:: (Num, Num) -&gt; Num --this uses 4 preceding spaces 
      triArea (base, height) = base*height/2 --... and so does this
  </code></pre>
  
  <p>This one fails to compile the particularly uninformative error message <code>parse error on input triArea</code>. Just for fun, let's try indenting it a bit more, because idk what else to do:</p>
  
  <pre><code>calcTriangleAreas xs = [triArea x | x&lt;-xs]
      where triArea:: (Num, Num) -&gt; Num --this uses 4 preceding spaces 
          triArea (base, height) = base*height/2 --this has 8
  </code></pre>
  
  <p>but, no dice, fails with the same <code>parse error</code> message. I tried replacing the spacing in each of these with equivalent, 4-space tabs, but that didn't
  help. The first two produce the same errors with tabs as with spaces, but the last one, shown here:</p>
  
  <pre><code>calcTriangleAreas xs = [triArea x | x&lt;-xs]
      where triArea:: (Num, Num) -&gt; Num --this uses a preceding tab character 
          triArea (base, height) = base*height/2 --this has 2
  </code></pre>
  
  <p>gives the error message</p>
  
  <pre><code>Illegal type signature: ‘(Num, Num) -&gt; Num triArea (base, height)’
    Perhaps you intended to use ScopedTypeVariables
  In a pattern type-signature
  </code></pre>
  
  <p>and I have no idea what that's trying to say, but it seems to be ignoring newlines all of a sudden. I've been reading through "Learn You a Haskell", and I'm supposed to be able to do this with the information presented in the first three chapters, but I've scoured those and they never specify the type of a functioned defined in a <code>where</code> clause in those chapters. For the record, their examples seem to be irreverent of spacing, and I copied the style of one of them:</p>
  
  <pre><code>calcTriangleAreas xs = [triArea x | x&lt;-xs]
      where triArea:: (Num, Num) -&gt; Num --4 preceding spaces
            triArea (base, height) = base*height/2 --10 preceding spaces
  </code></pre>
  
  <p>but this also failed to compile, spitting out the utterly incomprehensible error message:</p>
  
  <pre><code>Expecting one more argument to ‘Num’
      The first argument of a tuple should have kind ‘*’,
        but ‘Num’ has kind ‘* -&gt; GHC.Prim.Constraint’
      In the type signature for ‘triArea’: triArea :: (Num, Num) -&gt; Num
      In an equation for ‘calcTriangleAreas’:
          calcTriangleAreas xs
            = [triArea x | x &lt;- xs]
            where
                triArea :: (Num, Num) -&gt; Num
                triArea (base, height) = base * height / 2
  </code></pre>
  
  <p>I can't find anything when I google/hoogle it, and I've looked at <a href="https://stackoverflow.com/questions/6928884/type-signature-in-a-where-clause">this question</a>, but not only is it showing haskell far too
  advanced for me to read, but based on the content I don't believe they're having the same problem as me. I've tried specifying the type of <code>calcTriangleAreas</code>, and I've tried aliasing the types in the specification for <code>triArea</code> to be <code>Floating</code> and frankly I'm at the end of my rope. The top line of my file is <code>module ChapterThree where</code>, but beyond that the code I've shown in every example is the entire file. </p>
  
  <p>I'm working on 32-bit Linux Mint 18, and I'm compiling with <code>ghc ChapterThree.hs Chapter3UnitTests.hs -o Test</code>, where ChapterThree.hs is my file and the unit tests are given by my teacher so I can easily tell if my program works (It never gets to the compilation step for ChapterThreeUnitTests.hs, so I didn't think the content would be important), and my ghc version is 7.10.3.</p>
  
  <p>EDIT: Note that if I just remove the type specification altogether, everything compiles just fine, and that function passes all of its associated unit tests.</p>
  
  <p>Please, save me from my madness.</p>