toDetailedListing :: [Commented Var.Value] -> Module.DetailedListing
toDetailedListing values =
    let
        merge
            (Commented pre1 (inner1, tags1) post1)
            (Commented pre2 (inner2, tags2) post2)
            =
            Commented
                (pre1 ++ pre2)
                ( inner1 ++ inner2
                , mergeListing (mergeCommentedMap (\() () -> ())) tags1 tags2
                )
                (post1 ++ post2)


        step (vs, os, ts) (Commented pre val post) =
            case val of
                Var.Value name ->
                    (insert name (Commented pre () post) vs, os, ts)
                Var.OpValue name ->
                    (vs, insert name (Commented pre () post) os, ts)
                Var.Union (name, inner) tags ->
                    (vs, os, insertWith merge name (Commented pre (inner, tags) post) ts)

        done (vs, os, ts) =
            Module.DetailedListing vs os ts
    in
    foldl step (empty, empty, empty) values
        |> done
toDetailedListing :: [Commented Var.Value] -> Module.DetailedListing
toDetailedListing values =
    let
        merge
            (Commented pre1 (inner1, tags1) post1)
            (Commented pre2 (inner2, tags2) post2)
            =
            Commented
                (pre1 ++ pre2)
                ( inner1 ++ inner2
                , mergeListing (mergeCommentedMap (\() () -> ())) tags1 tags2
                )
                (post1 ++ post2)


        step (vs, os, ts) (Commented pre val post) =
            case val of
                Var.Value name ->
                    (insert name (Commented pre () post) vs, os, ts)
                Var.OpValue name ->
                    (vs, insert name (Commented pre () post) os, ts)
                Var.Union (name, inner) tags ->
                    (vs, os, insertWith merge name (Commented pre (inner, tags) post) ts)

        done (vs, os, ts) =
            Module.DetailedListing vs os ts
    in
    foldl step (empty, empty, empty) values
        |> done
toDetailedListing values =
    let
        merge
            (Commented pre1 (inner1, tags1) post1)
            (Commented pre2 (inner2, tags2) post2)
            =
            Commented
                (pre1 ++ pre2)
                ( inner1 ++ inner2
                , mergeListing (mergeCommentedMap (\() () -> ())) tags1 tags2
                )
                (post1 ++ post2)


        step (vs, os, ts) (Commented pre val post) =
            case val of
                Var.Value name ->
                    (insert name (Commented pre () post) vs, os, ts)
                Var.OpValue name ->
                    (vs, insert name (Commented pre () post) os, ts)
                Var.Union (name, inner) tags ->
                    (vs, os, insertWith merge name (Commented pre (inner, tags) post) ts)

        done (vs, os, ts) =
            Module.DetailedListing vs os ts
    in
    foldl step (empty, empty, empty) values
        |> done