itBounds :: RefGroup -> RefGroup
noteImplicitBounds rg =
     if implicits > 0
        then rg { rgBounds = bounds2 }
        else rg
   where
     bounds1 = rgBounds rg
     bounds2 =
         -- We only ever modify the lower bound constraints:
         --
         -- * if there's a lower bound constraint, raise it to
         --   the number of implicits (as needed)
         -- * otherwise, set the lower bound (but only if we
         --   already have an explicit constraint, in the form
         --   of an upper bound)
         --
         -- Note also we don't bother to verify that upper bounds
         -- make sense wrt their lower bounds
         case bLower bounds1 of
             Just l  -> bounds1 { bLower = Just (max l implicits) }
             Nothing -> if isJust (bUpper bounds1)
                           then bounds1 { bLower = Just implicits }
                           else bounds1
     implicits = Set.size (rgIdxes rg)

-- ----------------------------------------------------------------------
-- * query
-- ----------------------------------------------------------------------

-- | @hasDistractorGroup st k@ returns whether or not the discourse history
--   @st@ contains a group with distractors to @k@.
--
--   See 'distractorGroups' for more details
hasDistra
noteImplicitBounds :: RefGroup -> RefGroup
noteImplicitBounds rg =
     if implicits > 0
        then rg { rgBounds = bounds2 }
        else rg
   where
     bounds1 = rgBounds rg
     bounds2 =
         -- We only ever modify the lower bound constraints:
         --
         -- * if there's a lower bound constraint, raise it to
         --   the number of implicits (as needed)
         -- * otherwise, set the lower bound (but only if we
         --   already have an explicit constraint, in the form
         --   of an upper bound)
         --
         -- Note also we don't bother to verify that upper bounds
         -- make sense wrt their lower bounds
         case bLower bounds1 of
             Just l  -> bounds1 { bLower = Just (max l implicits) }
             Nothing -> if isJust (bUpper bounds1)
                           then bounds1 { bLower = Just implicits }
                           else bounds1
     implicits = Set.size (rgIdxes rg)

-- ----------------------------------------------------------------------
-- * query
-- ----------------------------------------------------------------------

-- | @hasDistractorGroup st k@ returns whether or not the discourse history
--   @st@ contains a group with distractors to @k@.
--
--   See 'distractorGroups' for more details
noteImplicitBounds rg =
     if implicits > 0
        then rg { rgBounds = bounds2 }
        else rg
   where
     bounds1 = rgBounds rg
     bounds2 =
         -- We only ever modify the lower bound constraints:
         --
         -- * if there's a lower bound constraint, raise it to
         --   the number of implicits (as needed)
         -- * otherwise, set the lower bound (but only if we
         --   already have an explicit constraint, in the form
         --   of an upper bound)
         --
         -- Note also we don't bother to verify that upper bounds
         -- make sense wrt their lower bounds
         case bLower bounds1 of
             Just l  -> bounds1 { bLower = Just (max l implicits) }
             Nothing -> if isJust (bUpper bounds1)
                           then bounds1 { bLower = Just implicits }
                           else bounds1
     implicits = Set.size (rgIdxes rg)

-- ----------------------------------------------------------------------
-- * query
-- ----------------------------------------------------------------------

-- | @hasDistractorGroup st k@ returns whether or not the discourse history
--   @st@ contains a group with distractors to @k@.
--
--   See 'distractorGroups' for more details