title: Cannot understand why MonoFoldable for my type doesn't compile, or the error message
body: <p>I have the following code:</p>
  
  <pre class="lang-haskell prettyprint-override"><code>{-# LANGUAGE NoImplicitPrelude, OverloadedStrings, TypeFamilies #-}
  
  module AI.Analysis.Rules where
  
  import ClassyPrelude
  
  -- Our set of rules
  
  data RuleSet a = RuleSet [Rule a] [Rule a]
    deriving (Eq)
  
  mkRuleSet :: (Ord a) =&gt; [Rule a] -&gt; RuleSet a
  mkRuleSet rules = uncurry RuleSet (partition isStandard uniques)
    where uniques = ordNub rules
          isStandard x = case x of
            Standard _ _ -&gt; True
            LastResort _ -&gt; False
  
  instance (Show a) =&gt; Show (RuleSet a) where
    show (RuleSet s l) = unlines [toLines s, "----", toLines l]
      where toLines = unlines . fmap show
  
  instance (Ord a) =&gt; Monoid (RuleSet a) where
    mempty = RuleSet [] []
    mappend (RuleSet s1 l1) (RuleSet s2 l2) = RuleSet (ordNub (s1 ++ s2)) (ordNub (l1 ++ l2))
  
  instance (Ord a) =&gt; Semigroup (RuleSet a) where
    (&lt;&gt;) = mappend
  
  type instance Element (RuleSet a) = (Rule a)
  
  instance MonoFoldable (RuleSet a) --this is unhappy
  
  -- A rule in our system
  -- For now, we assume rules *individually* are always internally-consistent
  
  data Rule a = Standard [a] a | LastResort a
    deriving (Eq)
  
  mkRule :: (Eq a, Ord a) =&gt; [a] -&gt; a -&gt; Rule a
  mkRule as c = case as of
    [] -&gt; LastResort c
    _ -&gt; Standard ((sort . ordNub) as) c
  
  -- Last-resort rules and standard rules cannot be compared for consistency
  mutuallyConsistent :: (Eq a) =&gt; Rule a -&gt; Rule a -&gt; Maybe Bool
  mutuallyConsistent (LastResort c1) (LastResort c2) = Just (c1 == c2)
  mutuallyConsistent (Standard as1 c1) (Standard as2 c2) = Just ((as1 /= as2) || (c1 == c2))
  mutuallyConsistent _ _ = Nothing
  
  instance (Show a) =&gt; Show (Rule a) where
    show x = case x of
      Standard as c -&gt; formatAnd as ++ " -&gt; " ++ show c
      LastResort c -&gt; "-&gt; " ++ show c
       where formatAnd = unwords . intersperse "^" . map show . otoList
  
   -- LastResort rules are always ordered smaller than standard ones
   instance (Ord a) =&gt; Ord (Rule a) where
     (&lt;=) (LastResort _) (Standard _ _) = True
     (&lt;=) (Standard _ _) (LastResort _) = False
     (&lt;=) (LastResort c1) (LastResort c2) = c1 &lt;= c2
     (&lt;=) (Standard as1 c1) (Standard as2 c2) = (as1 &lt;= as2) || (c1 &lt;= c2)
  </code></pre>
  
  <p>However, I get the following error from the compiler, whose meaning I am having trouble understanding:</p>
  
  <pre><code>/home/koz/documents/uni/research/summer-research-2015/clinical/rules-analysis/src/AI/Analysis/Rules.hs:47:10:
      Couldn't match type ‘a’ with ‘Rule a’
        ‘a’ is a rigid type variable bound by
            the instance declaration
            at /home/koz/documents/uni/research/summer-research-2015/clinical/rules-analysis/src/AI/Analysis/Rules.hs:47:10
      Expected type: Element (RuleSet a)
        Actual type: a
      Relevant bindings include
        ofoldMap :: (Element (RuleSet a) -&gt; m) -&gt; RuleSet a -&gt; m
          (bound at /home/koz/documents/uni/research/summer-research-2015/clinical/rules-analysis/src/AI/Analysis/Rules.hs:47:10)
      In the expression:
        mono-traversable-0.10.0.1:Data.MonoTraversable.$gdmofoldMap
      In an equation for ‘ofoldMap’:
          ofoldMap
            = mono-traversable-0.10.0.1:Data.MonoTraversable.$gdmofoldMap
      In the instance declaration for ‘MonoFoldable (RuleSet a)’
  </code></pre>
  
  <p>Near as I can tell, my thinking seems to make sense - after all, a <code>RuleSet</code> is just a container for <code>Rule</code>s, which should allow for foldability, but the error message in question doesn't make any sense to me. Could someone please clarify what I failed to grasp here?</p>