title: Error "No instance for (Num [t])" in Collatz function
body: <p>I am new to Haskell, and programming in general. I am trying to define a function which generates the sequence of Collatz numbers from <em>n</em>. I have:</p>
  
  <pre><code>collatz n = (collatz' n) : 1
     where collatz' n = (takeWhile (&gt;1) (collatz'' n))
            where collatz'' n = n : collatz'' (collatz''' n)
                   where collatz''' 1 = 1
                         collatz''' n = if (even n) then (div n 2) else ((3*2)+1)
  </code></pre>
  
  <p>When I run this in GHCi, I get the error:</p>
  
  <pre><code>No instance for (Num [t])
    arising from the literal `2' at &lt;interactive&gt;:1:7
  Possible fix: add an instance declaration for (Num [t])
  </code></pre>
  
  <p>I don't know what this means. The problem seems to be appending "1" to the list. This problem emerges because </p>
  
  <pre><code>collatz' n = (takeWhile (&gt;0) (collatz'' n))
  </code></pre>
  
  <p>generates an infinite sequence of "1"s following the correct Collatz sequence; however,</p>
  
  <pre><code>collatz' n = (takeWhile (&gt;1) (collatz'' n))
  </code></pre>
  
  <p>generates all Collatz numbers from <em>n</em> except "1". What am I doing wrong?</p>