mergeListing :: (a -> a -> a) -> Var.Listing a -> Var.Listing a -> Var.Listing a
mergeListing merge left right =
    case (left, right) of
        (Var.ClosedListing, Var.ClosedListing) -> Var.ClosedListing
        (Var.ClosedListing, Var.OpenListing comments) -> Var.OpenListing comments
        (Var.OpenListing comments, Var.ClosedListing) -> Var.OpenListing comments
        (Var.OpenListing (Commented pre1 () post1), Var.OpenListing (Commented pre2 () post2)) -> Var.OpenListing (Commented (pre1 ++ pre2) () (post1 ++ post2))
        (Var.ClosedListing, Var.ExplicitListing a multiline) -> Var.ExplicitListing a multiline
        (Var.ExplicitListing a multiline, Var.ClosedListing) -> Var.ExplicitListing a multiline
        (Var.OpenListing comments, Var.ExplicitListing a multiline) -> Var.OpenListing comments
        (Var.ExplicitListing a multiline, Var.OpenListing comments) -> Var.OpenListing comments
        (Var.ExplicitListing a multiline1, Var.ExplicitListing b multiline2) -> Var.ExplicitListing (merge a b) (multiline1 || multiline2)
mergeListing :: (a -> a -> a) -> Var.Listing a -> Var.Listing a -> Var.Listing a
mergeListing merge left right =
    case (left, right) of
        (Var.ClosedListing, Var.ClosedListing) -> Var.ClosedListing
        (Var.ClosedListing, Var.OpenListing comments) -> Var.OpenListing comments
        (Var.OpenListing comments, Var.ClosedListing) -> Var.OpenListing comments
        (Var.OpenListing (Commented pre1 () post1), Var.OpenListing (Commented pre2 () post2)) -> Var.OpenListing (Commented (pre1 ++ pre2) () (post1 ++ post2))
        (Var.ClosedListing, Var.ExplicitListing a multiline) -> Var.ExplicitListing a multiline
        (Var.ExplicitListing a multiline, Var.ClosedListing) -> Var.ExplicitListing a multiline
        (Var.OpenListing comments, Var.ExplicitListing a multiline) -> Var.OpenListing comments
        (Var.ExplicitListing a multiline, Var.OpenListing comments) -> Var.OpenListing comments
        (Var.ExplicitListing a multiline1, Var.ExplicitListing b multiline2) -> Var.ExplicitListing (merge a b) (multiline1 || multiline2)
mergeListing merge left right =
    case (left, right) of
        (Var.ClosedListing, Var.ClosedListing) -> Var.ClosedListing
        (Var.ClosedListing, Var.OpenListing comments) -> Var.OpenListing comments
        (Var.OpenListing comments, Var.ClosedListing) -> Var.OpenListing comments
        (Var.OpenListing (Commented pre1 () post1), Var.OpenListing (Commented pre2 () post2)) -> Var.OpenListing (Commented (pre1 ++ pre2) () (post1 ++ post2))
        (Var.ClosedListing, Var.ExplicitListing a multiline) -> Var.ExplicitListing a multiline
        (Var.ExplicitListing a multiline, Var.ClosedListing) -> Var.ExplicitListing a multiline
        (Var.OpenListing comments, Var.ExplicitListing a multiline) -> Var.OpenListing comments
        (Var.ExplicitListing a multiline, Var.OpenListing comments) -> Var.OpenListing comments
        (Var.ExplicitListing a multiline1, Var.ExplicitListing b multiline2) -> Var.ExplicitListing (merge a b) (multiline1 || multiline2)