imports :: IParser (Comments, Map [UppercaseIdentifier] (Comments, Module.ImportMethod), Comments)
imports =
    let
        merge :: PreCommented Module.ImportMethod -> PreCommented Module.ImportMethod -> PreCommented Module.ImportMethod
        merge (comments1, import1) (comments2, import2) =
            ( comments1 ++ comments2
            , Module.ImportMethod
                (Module.alias import1 Control.Applicative.<|> Module.alias import2)
                (mergePreCommented (mergePreCommented $ mergeListing mergeDetailedListing) (Module.exposedVars import1) (Module.exposedVars import2))
            )

        step (comments, m, finalComments) (((pre, name), method), post) =
            ( comments ++ finalComments
            , insertWith merge name (pre, method) m
            , post
            )

        done :: [(Module.UserImport, Comments)] -> (Comments, Map [UppercaseIdentifier] (Comments, Module.ImportMethod), Comments)
        done results =
            foldl step ([], empty, []) results
    in
    done <$> many ((,) <$> import' <*> freshLine)
imports :: IParser (Comments, Map [UppercaseIdentifier] (Comments, Module.ImportMethod), Comments)
imports =
    let
        merge :: PreCommented Module.ImportMethod -> PreCommented Module.ImportMethod -> PreCommented Module.ImportMethod
        merge (comments1, import1) (comments2, import2) =
            ( comments1 ++ comments2
            , Module.ImportMethod
                (Module.alias import1 Control.Applicative.<|> Module.alias import2)
                (mergePreCommented (mergePreCommented $ mergeListing mergeDetailedListing) (Module.exposedVars import1) (Module.exposedVars import2))
            )

        step (comments, m, finalComments) (((pre, name), method), post) =
            ( comments ++ finalComments
            , insertWith merge name (pre, method) m
            , post
            )

        done :: [(Module.UserImport, Comments)] -> (Comments, Map [UppercaseIdentifier] (Comments, Module.ImportMethod), Comments)
        done results =
            foldl step ([], empty, []) results
    in
    done <$> many ((,) <$> import' <*> freshLine)
imports =
    let
        merge :: PreCommented Module.ImportMethod -> PreCommented Module.ImportMethod -> PreCommented Module.ImportMethod
        merge (comments1, import1) (comments2, import2) =
            ( comments1 ++ comments2
            , Module.ImportMethod
                (Module.alias import1 Control.Applicative.<|> Module.alias import2)
                (mergePreCommented (mergePreCommented $ mergeListing mergeDetailedListing) (Module.exposedVars import1) (Module.exposedVars import2))
            )

        step (comments, m, finalComments) (((pre, name), method), post) =
            ( comments ++ finalComments
            , insertWith merge name (pre, method) m
            , post
            )

        done :: [(Module.UserImport, Comments)] -> (Comments, Map [UppercaseIdentifier] (Comments, Module.ImportMethod), Comments)
        done results =
            foldl step ([], empty, []) results
    in
    done <$> many ((,) <$> import' <*> freshLine)