title: Declaring a "subclass" in Haskell
body: <p>I have troubles with the following simple code in Haskell:</p>
  
  <pre><code>import Prelude hiding (cycle).
  
  class ICycle a where
      cycle :: a -&gt; a
  
  instance ICycle [a] where
      cycle [] = []
      cycle (x:xs) = xs ++ [x]
  
  instance ICycle Bool where
      cycle True = False
      cycle False = True
  
  instance Num a =&gt; ICycle a where
      cycle n = n+1
  
  main = do
      print $ cycle $ [1,2,3]
      print $ cycle $ True
      print $ cycle $ 42
  </code></pre>
  
  <p>Here the first two instance declarations work as expected, but the third one triggers various sorts of errors depending on flag combinations. </p>
  
  <p>I know that <code>Num a</code> is no shorter than <code>ICycle a</code> and hence the compiler can not finish type checking. In the examples, I have seen this is circumvented by either making the right-hand side a bigger term or by declaring a class of interest a subclass of other classes in the first place. Here, to the contrary, I essentially want to declare an existing class to be a subclass of a new one.</p>
  
  <p>I wonder if there are objections against this kind of use of type classes.  Or else, if there is a natural solution.</p>