sext-0.1.3: Lists, Texts, ByteStrings and Vectors with type-encoded length

Safe HaskellNone
LanguageHaskell2010

Data.Sext.Class

Description

Use this only if you need to make some type Sextable.

Synopsis

Documentation

class Sextable a where Source #

Class of types which can be assigned a type-level length.

Minimal complete definition

unsafeCreate, unwrap, length, append, replicate, map, take, drop

Associated Types

data Sext (i :: Nat) a Source #

Data family which wraps values of the underlying type giving them a type-level length. Sext 6 t means a value of type t of length 6.

type Elem a Source #

Basic element type. For Sextable [a], this is a.

Methods

unsafeCreate :: a -> Sext i a Source #

Simply wrap a value in a Sext as is, assuming any length.

For example, an expression like

unsafeCreate "somestring" :: Sext 50 String

will typecheck, although the stored length information will not match actual string size. This may result in wrong behaviour of all functions defined for Sext.

Use it only when you know what you're doing.

When implementing new Sextable instances, code this to simply apply the constructor of Sext.

unwrap :: Sext i a -> a Source #

Forget type-level length, obtaining the underlying value.

length :: a -> Int Source #

append :: a -> a -> a Source #

replicate :: Int -> Elem a -> a Source #

map :: (Elem a -> Elem a) -> a -> a Source #

take :: Int -> a -> a Source #

drop :: Int -> a -> a Source #

Instances

Sextable ShortByteString Source #

Sextable instance for ShortByteString uses intermediate ByteStrings (pinned) for all modification operations.

Sextable ByteString Source # 
Sextable Text Source # 

Associated Types

data Sext (i :: Nat) Text :: * Source #

type Elem Text :: * Source #

Sextable [a] Source # 

Associated Types

data Sext (i :: Nat) [a] :: * Source #

type Elem [a] :: * Source #

Methods

unsafeCreate :: [a] -> Sext i [a] Source #

unwrap :: Sext i [a] -> [a] Source #

length :: [a] -> Int Source #

append :: [a] -> [a] -> [a] Source #

replicate :: Int -> Elem [a] -> [a] Source #

map :: (Elem [a] -> Elem [a]) -> [a] -> [a] Source #

take :: Int -> [a] -> [a] Source #

drop :: Int -> [a] -> [a] Source #

Sextable (Vector a) Source # 

Associated Types

data Sext (i :: Nat) (Vector a) :: * Source #

type Elem (Vector a) :: * Source #

Methods

unsafeCreate :: Vector a -> Sext i (Vector a) Source #

unwrap :: Sext i (Vector a) -> Vector a Source #

length :: Vector a -> Int Source #

append :: Vector a -> Vector a -> Vector a Source #

replicate :: Int -> Elem (Vector a) -> Vector a Source #

map :: (Elem (Vector a) -> Elem (Vector a)) -> Vector a -> Vector a Source #

take :: Int -> Vector a -> Vector a Source #

drop :: Int -> Vector a -> Vector a Source #