static-text: Lists, Texts, ByteStrings and Vectors of statically known length

[ bsd3, data, library, text, type-system ] [ Propose Tags ]

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.


[Skip to Readme]
Versions 0.2, 0.2.0.1
Change log CHANGELOG.md
Dependencies base (<5), bytestring (<0.11), template-haskell (<2.14), text (<1.3), vector (<0.13) [details]
License BSD-3-Clause
Author Dmitry Dzhus
Maintainer dima@dzhus.org
Category Data, Text, Type System
Home page https://github.com/dzhus/static-text#readme
Bug tracker https://github.com/dzhus/static-text/issues
Source repo head: git clone https://github.com/dzhus/static-text
Uploaded by DmitryDzhus at Thu Mar 15 16:17:43 UTC 2018
Distributions LTSHaskell:0.2.0.1, NixOS:0.2.0.1, Stackage:0.2.0.1
Downloads 94 total (11 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-03-15 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Flags

NameDescriptionDefaultType
bytestring

Build interface for ByteString

EnabledAutomatic
text

Build interface for Text

EnabledAutomatic
vector

Build interface for Vector

EnabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for static-text-0.2.0.1

[back to package description]

static-text: lists, Texts, ByteStrings and Vectors of statically known length

Travis CI build status Hackage Hackage deps

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:

{-# 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 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: