packages feed

formatting 3.0.0 → 3.0.1

raw patch · 4 files changed

+107/−7 lines, 4 files

Files

formatting.cabal view
@@ -1,5 +1,5 @@ name:                formatting-version:             3.0.0+version:             3.0.1 synopsis:            Combinator-based type-safe formatting (like printf() or FORMAT) description:         Combinator-based type-safe formatting (like printf() or FORMAT), modelled from the HoleyMonoids package. license:             BSD3@@ -15,8 +15,13 @@   exposed-modules:   Formatting,                      Formatting.Holey,                      Formatting.Formatters,-                     Formatting.ShortFormatters+                     Formatting.ShortFormatters,+                     Formatting.Examples   build-depends:     base >= 4 && < 5,                      text-format,                      text   hs-source-dirs:    src++source-repository head+  type:     git+  location: http://github.com/chrisdone/formatting
src/Formatting.hs view
@@ -15,12 +15,15 @@ -- -- Example: ----- >>> format ("Person's name is " %text% ", age is " %hex) "Dave" 54+-- >>> format ("Person's name is " % text % ", age is " % hex) "Dave" 54+--+-- See "Formatting.Formatters" for a complete list of formatting combinators.  module Formatting   (   -- * Top-level functions   format,+  bprint,   fprint,   hprint,   -- * Formatting library@@ -40,6 +43,10 @@ -- | Run the formatter and return a "Text" value. format :: Holey Builder Text a -> a format m = runHM m T.toLazyText++-- | Run the formatter and return a "Builder" value.+bprint :: Holey Builder Builder a -> a+bprint m = runHM m id  -- | Run the formatter and print out the text to stdout. fprint :: Holey Builder (IO ()) a -> a
+ src/Formatting/Examples.hs view
@@ -0,0 +1,61 @@+{-# LANGUAGE OverloadedStrings #-}++-- | Examples that should always compile. If reading on Haddock, you+-- can view the sources to each of these.++module Formatting.Examples where++import Data.Text.Lazy (Text)+import Data.Text.Lazy.Builder (Builder)+import Formatting++-- | Simple hello, world!+hello :: Text+hello = format ("Hello, World!")++-- | Printing strings.+strings :: Text+strings =+  format ("Here comes a string: " % string % " and another " % string)+         "Hello, World!"+         "Ahoy!"++-- | Printing texts.+texts :: Text+texts =+  format ("Here comes a string: " % text % " and another " % text)+         "Hello, World!"+         "Ahoy!"++-- | Printing builders.+builders :: Text+builders =+  format ("Here comes a string: " % builder % " and another " % text)+         ("Hello, World!" :: Builder)+         "Ahoy!"++-- | Printing integers.+integers :: Text+integers =+  format ("Here comes an integer: " % int % " and another: " % int)+         (23 :: Int)+         (0 :: Integer)++-- | Printing floating points.+floats :: Text+floats =+  format ("Here comes a float: " % float % " and a double with sci notation: " % prec 6)+         (123.2342 :: Float)+         (13434242423.23420000 :: Double)++-- | Printing integrals in hex (base-16).+hexes :: Text+hexes =+  format ("Here comes a hex: " % hex)+         (123 :: Int)++-- | Padding.+padding :: Text+padding =+  format ("A left-padded number: " % left 3 '0')+         (9 :: Int)
src/Formatting/Formatters.hs view
@@ -15,17 +15,26 @@  module Formatting.Formatters   (-  -- * Formatters+  -- * Text/string types   text,-  hex,   stext,   string,+  builder,+  -- * Numbers+  int,+  float,   expt,   fixed,   prec,   shortest,+  -- * Padding   left,-  right+  right,+  -- * Bases+  hex,+  -- * Buildables+  build,+  Buildable   ) where  import           Formatting.Holey@@ -33,8 +42,10 @@ import qualified Data.Text as S import qualified Data.Text as T import           Data.Text.Buildable    (Buildable)+import qualified Data.Text.Buildable    as B (build) import qualified Data.Text.Format       as T import           Data.Text.Lazy (Text)+import           Data.Text.Lazy.Builder (Builder) import qualified Data.Text.Lazy.Builder as T  -- | Output a lazy text.@@ -43,7 +54,7 @@  -- | Render an integer using hexadecimal notation. (No leading 0x is -- added.)-hex :: Format Integer+hex :: Integral a => Format a hex = later T.hex  -- | Output a strict text.@@ -53,6 +64,22 @@ -- | Output a string. string :: Format String string = later (T.fromText . T.pack)++-- | Build a builder.+builder :: Format Builder+builder = later id++-- | Build anything that implements the "Buildable" class.+build :: Buildable a => Format a+build = later B.build++-- | Render an integral e.g. 123 -> \"123\", 0 -> \"0\".+int :: Integral a => Format a+int = later T.shortest++-- | Render some floating point with the usual notation, e.g. 123.32 => "123.32"+float :: Real a => Format a+float = later (T.shortest)  -- | Render a floating point number using scientific/engineering -- notation (e.g. 2.3e123), with the given number of decimal places.