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

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

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]

Flags

Automatic Flags
NameDescriptionDefault
bytestring

Build interface for ByteString

Enabled
text

Build interface for Text

Enabled
vector

Build interface for Vector

Enabled

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

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2, 0.2.0.1, 0.2.0.2, 0.2.0.3, 0.2.0.4, 0.2.0.5, 0.2.0.6, 0.2.0.7
Change log CHANGELOG.md
Dependencies base (<5), bytestring, template-haskell, text, vector [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 2021-07-10T12:44:51Z
Distributions LTSHaskell:0.2.0.7, NixOS:0.2.0.7, Stackage:0.2.0.7
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3639 total (26 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-07-10 [all 1 reports]

Readme for static-text-0.2.0.7

[back to package description]

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

Github 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.ByteString.Char8 (ByteString, pack)
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.StaticText.length payload `mod` 100

message :: Static ByteString 64
message = mkPacket "Hello" `append` mkPacket "world"

main :: IO ()
main = print message

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: