packages feed

pretty-types 0.2.2.1 → 0.2.3.0

raw patch · 3 files changed

+54/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Type.Pretty: data Prettifier :: Type -> Type
+ Data.Type.Pretty: data PrettyTitled (title :: PrettyType) (indentation :: Nat) :: Prettifies t
+ Data.Type.Pretty: type Prettifies t = Prettifier t -> Type

Files

pretty-types.cabal view
@@ -1,5 +1,5 @@ name:                pretty-types-version:             0.2.2.1+version:             0.2.3.0 synopsis:            A small pretty printing DSL for complex types. description:         Please see README.md homepage:            https://github.com/sheyll/pretty-types#readme
spec/PrettyTypesSpec.hs view
@@ -143,6 +143,11 @@                             PutStr "bar4")))       `shouldBe` "foo\n  bar1\n  bar2\n    bar3\n    bar4" +  describe "PrettifyWith" $+    it "applies a 'Prettifier' and creates the desired 'PrettyType'" $+       showPretty (PX :: PX (PrettifyWith (PrettyTitled (PutStr "The Title") 10) "body"))+       `shouldBe`+       "The Title\n          body"   describe "ToPretty" $ do     it "renders a 'Tagged'" $       showPretty (PX :: PX (ToPretty (Tagged "foo" Word8))) `shouldBe` "Word8 (foo)"
src/Data/Type/Pretty.hs view
@@ -112,6 +112,7 @@ import Data.Word import Data.Int import Data.Tagged+import Data.Kind (type Type)  -- * Pretty Printing Types @@ -495,6 +496,53 @@     -- >>> showPretty (Proxy::Proxy (PrettyNat PrettyUnpadded PrettyPrecise PrettyHexU 51966))     -- "1100101011111110"   | PrettyBit++-- * 'PrettyType' Functions++-- | /Kind/ of 'Prettifier' data types.+--+-- The type that all data types share, such that they can be passed to+-- 'PrettifyWith'.+--+-- Sometimes it is desirable to pass around __pretty-printing functions__ called+-- 'Prettifier' in this library. A 'Prettifier' is a __parameterized pretty-printer__+-- that accepts a parameter of a specific kind.+--+-- For example:+--+-- @+-- data PutStrIsh :: Prettifies Symbol+--+-- type instance PrettifyWith PutStrIsh str = PutStr str <++> PutStr "ish"+-- @+--+-- >>> showPretty (Proxy @(PrettifyWith PutStrIsh "That's pretty okay"))+-- "That's pretty okayish"+--+-- @since 0.2.3.0+type Prettifies t = Prettifier t -> Type++-- | An abstract declaration of a __pretty-printing (type-)function__ that takes+-- a specific kind of types as parameter.+--+-- @since 0.2.3.0+data Prettifier :: Type -> Type++-- | Apply a 'Prettifier' to a type in order to get a 'PrettyType'+--+-- @since 0.2.3.0+type family PrettifyWith (f :: Prettifies k) (x :: k) :: PrettyType++-- ** Basic 'Prettifier's++-- | Write a title and print the indented, 'ToPretty'-fied body starting on the+-- next line.+--+-- @since 0.2.3.0+data PrettyTitled (title :: PrettyType) (indentation :: Nat) :: Prettifies t++type instance PrettifyWith (PrettyTitled title indentation) body =+  'PrettyInfix 'PrettyNewline title ('PrettyIndent indentation (ToPretty body))  -- *  Pretty Rendering