title: QuickCheck Tests for Custom Type
body: <p>With the following Algebraic Data Type:</p>
  
  <p><code>data Cons a = Cons a (Cons a) | Empty deriving (Show, Eq)</code></p>
  
  <p>I wrote an instance of <code>Arbitrary</code>:</p>
  
  <p>My <strong>understanding</strong> is that it's necessary to create an instance of <code>Arbitrary</code> for QuickCheck to know how to find a <code>Cons Int</code> to plug in for its tests.</p>
  
  <pre><code>instance Arbitrary (Cons Int) where
      arbitrary = elements [Empty, Cons 10 (Cons 100 (Cons 55 Empty)), Cons 1 Empty]
  </code></pre>
  
  <p>and a function:</p>
  
  <pre><code>makeArbitraryCons :: Gen (Cons Int)
  makeArbitraryCons = arbitrary 
  </code></pre>
  
  <p>Then, I wrote a QuickCheck test:</p>
  
  <pre><code>prop_id_functor_law_int ::  Cons Int -&gt; Bool
  prop_id_functor_law_int x = fmap id x == id x
  </code></pre>
  
  <p>And it works:</p>
  
  <pre><code>ghci&gt; quickCheck prop_id_functor_law_int
  *** Failed! Falsifiable (after 1 test):
  Cons 10 (Cons 100 (Cons 55 Empty))
  </code></pre>
  
  <p>However, when I try to run the following test, it fails:</p>
  
  <pre><code>second_functor_law_int :: (Int -&gt; Int) -&gt; (Int -&gt; Int) -&gt; Cons Int -&gt; Bool
  second_functor_law_int f g x = left == right
    where left = fmap (f . g) $ x
          right = (fmap f) . (fmap g) $ x
  </code></pre>
  
  <p>with this error:</p>
  
  <pre><code>ghci&gt; quickCheck second_functor_law_int
  
  &lt;interactive&gt;:418:1:
      No instance for (Show (Int -&gt; Int))
        arising from a use of `quickCheck'
      In the expression: quickCheck second_functor_law_int
      In an equation for `it': it = quickCheck second_functor_law_int
  </code></pre>
  
  <p>My questions are:</p>
  
  <ol>
  <li>is it necessary to define an <code>Arbritrary</code> instance for a new
  data type (such as my <code>Cons a</code>)?</li>
  <li>must I create a function that
  creates a <code>Gen (Cons Int)</code> - <code>makeArbitraryCons</code>?</li>
  <li>lastly, what's going on when I run my second test via <code>quickCheck
  second_functor_law_int</code>?</li>
  </ol>