static-text 0.2 → 0.2.0.1
raw patch · 7 files changed
+83/−22 lines, 7 filesdep ~doctestdep ~doctest-discoverdep ~tasty
Dependency ranges changed: doctest, doctest-discover, tasty, template-haskell
Files
- CHANGELOG.md +5/−1
- README.md +56/−0
- src/Data/StaticText.hs +2/−2
- src/Data/StaticText/Class.hs +6/−6
- src/Data/StaticText/TH.hs +2/−2
- static-text.cabal +11/−10
- tests/Main.hs +1/−1
CHANGELOG.md view
@@ -1,6 +1,10 @@ # Changelog -## [Unreleased]+## [0.2.0.1] - 2018-03-15++### Changed++- GHC 8.4.x support ## [0.2.0] - 2018-02-17
+ README.md view
@@ -0,0 +1,56 @@+# static-text: lists, Texts, ByteStrings and Vectors of statically known length++[](https://travis-ci.org/dzhus/static-text)+[](https://hackage.haskell.org/package/static-text)+[](http://packdeps.haskellers.com/feed?needle=static-text)++static-text provides type-level safety for basic operations on+string-like types (finite lists of elements), such as `Data.Text`,+`String` (and all lists), `Data.ByteString` and `Data.Vector`. Use it+when you need static guarantee on lengths of strings produced in your+code.++An example application would be a network exchange protocol built of+packets with fixed-width fields:++```haskell+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-}+import Data.StaticText++mkPacket :: ByteString -> Static ByteString 32+mkPacket inp =+ -- 5-character version signature+ $(st "PKT10") `append`+ -- 25-character payload+ payload `append`+ -- 2-character payload checksum+ checksum+ where+ payload = createLeft 0x20 inp+ checksum :: Static ByteString 2+ checksum = createLeft 0x20 $+ pack $ show $ Data.Static.length payload `mod` 100++message :: Static ByteString 64+message = mkPacket "Hello" `append` mkPacket "world"+```++Please consult the [Hackage page for static-text][hackage-doc] for+documentation and examples.++## Alternatives++The emphasis of static-text is on type-safe padding/truncation and+type-safe string literals. Other similar libraries may suit different+use cases:++- [vector-sized][] and [fixed-vector][]: full support for Vector API,+ but not string-like types.++[hackage-doc]: http://hackage.haskell.org/package/static-text/docs/Data-StaticText.html++[fixed-vector]: https://hackage.haskell.org/package/fixed-vector++[vector-sized]: https://hackage.haskell.org/package/vector-sized
src/Data/StaticText.hs view
@@ -58,7 +58,7 @@ module Data.StaticText (- -- * Constructing StaticTexts+ -- * Constructing static texts -- -- | See also 'C.unsafeCreate' createLeft@@ -67,7 +67,7 @@ , create , replicate - -- * Working with StaticTexts+ -- * Working with static texts , append , take , drop
src/Data/StaticText/Class.hs view
@@ -51,18 +51,18 @@ -- | Simply wrap a value in a Static as is, assuming any length. --+ -- __WARNING__ Use it only when you know what you're doing.+ -- -- For example, an expression like --- -- > unsafeCreate "somestring" :: Static 50 String+ -- > unsafeCreate "somestring" :: Static String 50 -- -- will typecheck, although the stored length information will not -- match actual string size. This may result in wrong behaviour of- -- all functions defined for Static.- --- -- Use it only when you know what you're doing.+ -- all functions defined for "IsStaticText". --- -- When implementing new IsStaticText instances, code this to simply- -- apply the constructor of 'StaticText'.+ -- When writing new "IsStaticText" instances, make this simply apply+ -- the constructor of "Static". unsafeCreate :: a -> Static a i -- | Forget type-level length, obtaining the underlying value.
src/Data/StaticText/TH.hs view
@@ -28,7 +28,7 @@ newtype LitS = LitS String deriving IsString --- | Type-safe StaticText constructor macro for string literals.+-- | Type-safe Static constructor macro for string literals. -- -- Example: --@@ -36,7 +36,7 @@ -- -- compiles to ----- > unsafeCreate "Foobar" :: forall a. (IsString a, IsStaticText a) => StaticText 6 a+-- > unsafeCreate "Foobar" :: forall a. (IsString a, IsStaticText a) => Static a 6 -- -- where 6 is the string length obtained at compile time. st :: LitS -> Q Exp
static-text.cabal view
@@ -1,5 +1,5 @@ name: static-text-version: 0.2+version: 0.2.0.1 cabal-version: >=1.10 build-type: Simple license: BSD3@@ -14,6 +14,7 @@ author: Dmitry Dzhus extra-source-files: CHANGELOG.md+ README.md source-repository head type: git@@ -53,27 +54,27 @@ Data.StaticText.TH build-depends: base <5,- template-haskell <2.13+ template-haskell <2.14 default-language: Haskell2010 hs-source-dirs: src other-modules: Paths_static_text- ghc-options: -Wall+ ghc-options: -Wall -Wcompat test-suite static-text-doctests type: exitcode-stdio-1.0 main-is: doctest-driver.hs build-depends: base <5,- doctest <0.14,- doctest-discover <0.2,- template-haskell <2.13+ doctest <0.16,+ doctest-discover >=0.1.0.8 && <0.2,+ template-haskell <2.14 default-language: Haskell2010 hs-source-dirs: tests other-modules: Main Paths_static_text- ghc-options: -Wall -threaded+ ghc-options: -Wall -Wcompat -threaded test-suite static-text-example type: exitcode-stdio-1.0 main-is: Main.hs@@ -81,11 +82,11 @@ base <5, bytestring <0.11, static-text -any,- tasty <0.13,+ tasty <1.1, tasty-hunit <0.11,- template-haskell <2.13+ template-haskell <2.14 default-language: Haskell2010 hs-source-dirs: tests other-modules: Paths_static_text- ghc-options: -Wall+ ghc-options: -Wall -Wcompat
tests/Main.hs view
@@ -29,7 +29,7 @@ tests :: [TestTree] tests = [ testCase ("The actual length of " ++ show (typeOf message)) $- assertEqual "" 64 (Data.ByteString.Char8.length $ unwrap message)+ Data.ByteString.Char8.length (unwrap message) @=? 64 ] main :: IO ()