joinRanges :: Range -> Range -> Range
joinRanges (Range (I c1 vs1)) (Range (I c2 vs2)) =
    Range $ I (up c1 c2) (vs1 `Set.union` vs2)
  where
    up Nothing   Nothing   = Nothing
    up (Just c)  Nothing   = Just c
    up Nothing   (Just c)  = Just c
    up (Just c1) (Just c2) = Just (Prelude.max c1 c2)
joinRanges :: Range -> Range -> Range
joinRanges (Range (I c1 vs1)) (Range (I c2 vs2)) =
    Range $ I (up c1 c2) (vs1 `Set.union` vs2)
  where
    up Nothing   Nothing   = Nothing
    up (Just c)  Nothing   = Just c
    up Nothing   (Just c)  = Just c
    up (Just c1) (Just c2) = Just (Prelude.max c1 c2)
joinRanges (Range (I c1 vs1)) (Range (I c2 vs2)) =
    Range $ I (up c1 c2) (vs1 `Set.union` vs2)
  where
    up Nothing   Nothing   = Nothing
    up (Just c)  Nothing   = Just c
    up Nothing   (Just c)  = Just c
    up (Just c1) (Just c2) = Just (Prelude.max c1 c2)