array-builder-0.1.2.0: Builders for arrays
Safe HaskellNone
LanguageHaskell2010

Data.Builder.Catenable

Description

Builder with cheap concatenation. Like the builder type from Data.Builder.ST, this builder can be stored somewhere and this used again later. However, this builder type has several advantages:

  • Supports both cons and snoc (Data.Builder.ST only supports snoc)
  • No linear-use restriction
  • Extremely cheap concatenation (not supported by Data.Builder.ST at all)

In exchange for all of these, this implementation trades performance. Performance is degraded for two reasons:

  • Evaluation of the builder is deferred, and the evaluation requires walking a tree of nodes.
  • This builder stores individual elements rather than chunks. There is no fundamental reason for this. It is possible to store a SmallArray in each Cons and Snoc instead, but this makes the implementation a little more simple.

One reason to prefer this module instead of Data.Builder.ST is that this module lets the user works with builder in a more monoidal style rather than a stateful style. Consider a data type with several fields that is being converted to a builder. Here, Data.Builder.ST would require that Builder appear as both an argument and an result for each field's encode function. The linearly-used builder must be threaded through by hand or by clever use of StateT. With Data.Builder.Catenable, the encode functions only need return the builder.

Synopsis

Type

data Builder a Source #

Constructors

Empty 
Cons a !(Builder a) 
Snoc !(Builder a) a 
Append !(Builder a) !(Builder a) 

Instances

Instances details
IsList (Builder a) Source # 
Instance details

Defined in Data.Builder.Catenable

Associated Types

type Item (Builder a) #

Methods

fromList :: [Item (Builder a)] -> Builder a #

fromListN :: Int -> [Item (Builder a)] -> Builder a #

toList :: Builder a -> [Item (Builder a)] #

Semigroup (Builder a) Source # 
Instance details

Defined in Data.Builder.Catenable

Methods

(<>) :: Builder a -> Builder a -> Builder a #

sconcat :: NonEmpty (Builder a) -> Builder a #

stimes :: Integral b => b -> Builder a -> Builder a #

Monoid (Builder a) Source # 
Instance details

Defined in Data.Builder.Catenable

Methods

mempty :: Builder a #

mappend :: Builder a -> Builder a -> Builder a #

mconcat :: [Builder a] -> Builder a #

type Item (Builder a) Source # 
Instance details

Defined in Data.Builder.Catenable

type Item (Builder a) = a

Convenient infix operators

pattern (:<) :: a -> Builder a -> Builder a infixr 5 Source #

pattern (:>) :: Builder a -> a -> Builder a infixl 5 Source #

Run