diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2018-05-13 10:42:46 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2018-05-13 10:42:46 -0700 |
commit | b3102087ce4cfceb395ce981c4ac167a9d6b7642 (patch) | |
tree | 1feb8e3fd4a877a765afa6efa6c2a3be35dcbd7a /lib/Language/Haskell/Stylish/Step/Imports.hs | |
parent | 01298b15d95aec5945be8c5839045763d57657fc (diff) | |
parent | 7fac380bd83d51191e223560449d808e323d7ca6 (diff) | |
download | stylish-haskell-b3102087ce4cfceb395ce981c4ac167a9d6b7642.tar.gz |
Merge tag 'v0.9.2.0'
v0.9.2.0
Diffstat (limited to 'lib/Language/Haskell/Stylish/Step/Imports.hs')
-rw-r--r-- | lib/Language/Haskell/Stylish/Step/Imports.hs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Language/Haskell/Stylish/Step/Imports.hs b/lib/Language/Haskell/Stylish/Step/Imports.hs index 2284f3d..fc035a2 100644 --- a/lib/Language/Haskell/Stylish/Step/Imports.hs +++ b/lib/Language/Haskell/Stylish/Step/Imports.hs @@ -22,9 +22,9 @@ import Data.Char (toLower) import Data.List (intercalate, sortBy) import qualified Data.Map as M import Data.Maybe (isJust, maybeToList) -import Data.Monoid ((<>)) import Data.Ord (comparing) import qualified Data.Set as S +import Data.Semigroup (Semigroup ((<>))) import qualified Language.Haskell.Exts as H @@ -168,10 +168,13 @@ data ImportPortion l = ImportSome [H.CName l] -- ^ @A(x, y, z)@ | ImportAll -- ^ @A(..)@ +instance Ord l => Semigroup (ImportPortion l) where + ImportSome a <> ImportSome b = ImportSome (setUnion a b) + _ <> _ = ImportAll + instance Ord l => Monoid (ImportPortion l) where mempty = ImportSome [] - mappend (ImportSome a) (ImportSome b) = ImportSome (setUnion a b) - mappend _ _ = ImportAll + mappend = (<>) -- | O(n log n) union. setUnion :: Ord a => [a] -> [a] -> [a] @@ -311,7 +314,11 @@ prettyImport columns Options{..} padQualified padName longest imp ( mapSpecs ( withHead ("( " ++) . withTail (", " ++)) - ++ [")"]) + ++ closer) + where + closer = if null importSpecs + then [] + else [")"] paddedBase = base $ padImport $ compoundImportName imp |