title: Haskell Typeclass Type Constraints and Deduction
body: <p>I've been running through the "Learn You a Haskell" book, and I'm trying to wrap my head around Haskell Type Classes. As practice, I'm trying to create a simple vector type class. The following snippet of code has been giving me some grief (resulting in my first post to StackOverflow):</p>
  
  <pre><code>data Vec2 a = Vec2 (a,a) deriving (Show, Eq, Read)
  
  class Vector a where
      (&lt;*) :: (Num b) =&gt; a -&gt; b -&gt; a
  
  instance (Num a) =&gt; Vector (Vec2 a) where
      Vec2 (x,y) &lt;* a = Vec2 (a*x, a*y)
  </code></pre>
  
  <p>I get the following error message:</p>
  
  <pre><code>Could not deduce (a~b) from the context (Num a) or from (Num b) bound by the type signature for
      &lt;* :: Num b =&gt; Vec2 a -&gt; b -&gt; Vec2 a
  </code></pre>
  
  <p>It seems like the <code>Num</code> being specified in the typeclass should supply the type of <code>a</code>, and <code>Num a</code> spefication in the instance should supply the type of <code>x</code> and <code>y</code>, so why is it complaining? What misconception do I have about this code?</p>