packages feed

show-combinators 0.1.1.0 → 0.2.0.0

raw patch · 4 files changed

+36/−25 lines, 4 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.2.0.0++- Fix a bug where `showRecord` would not parenthesize the output if a high+  enough precedence were supplied.+ # 0.1.1.0  - Added `showInfixl`, `showInfixr`, `showInfixl'`, `showInfixr'`.
show-combinators.cabal view
@@ -1,5 +1,5 @@ name:                show-combinators-version:             0.1.1.0+version:             0.2.0.0 synopsis:            Combinators to write Show instances description:   A minimal pretty-printing library for Show instances in Haskell.@@ -13,7 +13,7 @@ build-type:          Simple extra-source-files:  README.md, CHANGELOG.md cabal-version:       >=1.10-tested-with:         GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.6.3+tested-with:         GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.1  library   hs-source-dirs:      src@@ -21,7 +21,7 @@     Text.Show.Combinators   build-depends:     -- This upper bound is conservative-    base >= 4.8 && < 4.13+    base >= 4.8 && < 4.14   ghc-options:         -Wall   default-language:    Haskell2010 
src/Text/Show/Combinators.hs view
@@ -32,7 +32,7 @@   , showInfix'      -- ** Combinators for associative operators-    -- | Use with care, see 'showInfixl'.+    -- | Use with care, see warning under 'showInfixl'.   , showInfixl   , showInfixl'   , showInfixr@@ -110,11 +110,14 @@ -- | Show an applied infix operator which is left associative (@infixl@). -- Use with care. --+-- ==== Warning+-- -- This combinator assumes that, if there is another infix operator to the -- left, it is either left associative with the same precedence, or it has a -- different precedence. -- An expression containing two operators at the same level with different--- associativities is ambiguous.+-- associativities is ambiguous and will not be shown correctly with+-- 'showInfixl' and 'showInfixr'. -- -- By default, prefer 'showInfix' and 'showInfix''. showInfixl :: String -> Int -> PrecShowS -> PrecShowS -> PrecShowS@@ -133,11 +136,14 @@ -- | Show an applied infix operator which is right associative (@infixr@). -- Use with care. --+-- ==== Warning+-- -- This combinator assumes that, if there is another infix operator to the -- right, it is either right associative with the same precedence, or it has a -- different precedence. -- An expression containing two operators at the same level with different--- associativities is ambiguous.+-- associativities is ambiguous and will not be shown correctly with+-- 'showInfixl' and 'showInfixr'. -- -- By default, prefer 'showInfix' and 'showInfix''. --@@ -178,8 +184,8 @@ -- | Show a record. The first argument is the constructor name. -- The second represents the set of record fields. showRecord :: String -> ShowFields -> PrecShowS-showRecord con showFields _ =-  showString con . showSpace . showChar '{' . showFields . showChar '}'+showRecord con showFields d = showParen (d > appPrec)+  (showString con . showSpace . showChar '{' . showFields . showChar '}')  -- | Show a single record field: a field name and a value separated by @\'=\'@. showField :: String -> PrecShowS -> ShowFields@@ -203,7 +209,7 @@  infixr 1 `appendFields`, &| --- | Separate two nonempty sets of record fields by a comma.+-- | Separate two __nonempty__ sets of record fields by a comma. appendFields :: ShowFields -> ShowFields -> ShowFields appendFields showFds1 showFds2 = showFds1 . showString ", " . showFds2 
test/test.hs view
@@ -21,20 +21,20 @@ _showsMyType' (R {f1 = e, f2 = f}) =   showRecord "R" ("f1" .=. e &| "f2" .=. f) -showL :: [Int] -> PrecShowS-showL [] = showCon "[]"-showL (x : xs) = showInfixr ":" 5 (flip showsPrec x) (showL xs)---- snoc lists showR :: [Int] -> PrecShowS showR [] = showCon "[]"-showR (x : xs) = showInfixl ":" 5 (showR xs) (flip showsPrec x)+showR (x : xs) = showInfixr ":" 5 (flip showsPrec x) (showR xs) -check :: Show a => (a -> PrecShowS) -> a -> IO ()-check show' x = assertEqual s s'+-- snoc lists+showL :: [Int] -> PrecShowS+showL [] = showCon "[]"+showL (x : xs) = showInfixl ":" 5 (showL xs) (flip showsPrec x)++check :: Show a => (a -> PrecShowS) -> Int -> a -> IO ()+check show' d x = assertEqual s s'   where-    s = show x-    s' = show' x 0 ""+    s = showsPrec d x ""+    s' = show' x d ""  assertEqual :: (Eq a, Show a) => a -> a -> IO () assertEqual s s' =@@ -48,12 +48,12 @@  main :: IO () main = do-  check smt1 (C () ())-  check smt2 (C (C () ()) (() :+: ()))-  check smt2 ((() :+: ()) :+: (() :+: ()))-  check smt2 (R (C () ()) (C () ()))-  assertEqual (unPS showL [1,2,3]) "1 : 2 : 3 : []"-  assertEqual (unPS showR [1,2,3]) "[] : 3 : 2 : 1"+  check smt1  0 (C () ())+  check smt2  0 (C (C () ()) (() :+: ()))+  check smt2  0 ((() :+: ()) :+: (() :+: ()))+  check smt2 11 (R (C () ()) (C () ()))+  assertEqual (unPS showR [1,2,3]) "1 : 2 : 3 : []"+  assertEqual (unPS showL [1,2,3]) "[] : 3 : 2 : 1"   where     smt1 = showsMyType (flip showsPrec)     smt2 = showsMyType smt1