combineExists :: [Concept] -> [Concept]
combineExists cs =
  -- TODO use standard groupBy
  let groups = groupWith (\x -> case x of (Exists _ r) -> Just r
                                          _ -> Nothing) cs
      (noCombine, toCombine) = break (\x -> case x of (Exists _ _:_) -> True
                                                      _ -> False) groups
      getMinRel (Exists n _) = n
      combine [c] = c
      combine cs2@(Exists _ rn:_) = let maxN = foldl (flip $ max . getMinRel) 0 cs2
                                       in Exists maxN rn
  in concat noCombine ++ map combine toCombine
combineExists :: [Concept] -> [Concept]
combineExists cs =
  -- TODO use standard groupBy
  let groups = groupWith (\x -> case x of (Exists _ r) -> Just r
                                          _ -> Nothing) cs
      (noCombine, toCombine) = break (\x -> case x of (Exists _ _:_) -> True
                                                      _ -> False) groups
      getMinRel (Exists n _) = n
      combine [c] = c
      combine cs2@(Exists _ rn:_) = let maxN = foldl (flip $ max . getMinRel) 0 cs2
                                       in Exists maxN rn
  in concat noCombine ++ map combine toCombine
combineExists cs =
  -- TODO use standard groupBy
  let groups = groupWith (\x -> case x of (Exists _ r) -> Just r
                                          _ -> Nothing) cs
      (noCombine, toCombine) = break (\x -> case x of (Exists _ _:_) -> True
                                                      _ -> False) groups
      getMinRel (Exists n _) = n
      combine [c] = c
      combine cs2@(Exists _ rn:_) = let maxN = foldl (flip $ max . getMinRel) 0 cs2
                                       in Exists maxN rn
  in concat noCombine ++ map combine toCombine