title: Haskell allow only positive input
body: <p>I need to define a haskell function:</p>
  
  <pre><code>func :: Int -&gt; Int
  func 1 = 1
  func 2 = 2
  func x = x+1
  </code></pre>
  
  <p>So that it allows only positive numbers. I've already had a look at a similar question: <a href="https://stackoverflow.com/questions/2070989/non-negative-integers">Non-negative integers</a></p>
  
  <p>And wrote this:</p>
  
  <pre><code>newtype Positive a = Positive a
  
  toPositive :: (Num a, Ord a) =&gt; a -&gt; Positive a
  toPositive x
      | x &lt; 0 = error "number cannot be negative"
      | otherwise = Positive x
  
  func :: Positive a -&gt; a
  func (Positive n) = n
  </code></pre>
  
  <p>Which is however already throwing errors. Thoughts?</p>
  
  <p>Update:</p>
  
  <p>Sample error:</p>
  
  <pre><code>*Main&gt; func 1
  
  &lt;interactive&gt;:32:6:
      No instance for (Num (Positive a0)) arising from the literal `1'
      Possible fix: add an instance declaration for (Num (Positive a0))
      In the first argument of `func', namely `1'
      In the expression: func 1
      In an equation for `it': it = func 1
  *Main&gt;
  </code></pre>