Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines an immutable extensible record type, similar to vinyl
and data-diverse
. However this
implementation focuses on fast reads, hence has very different performance characteristics from other libraries:
- Lookup: Amortized \( O(1) \).
- Update: \( O(n) \).
- Shrink: \( O(1) \).
- Append: \( O(n) \).
This is an internal module and its API may change even between minor versions. Therefore you should be extra careful if you're to depend on this module.
Synopsis
- data Rec (f :: k -> Type) (es :: [k])
- length :: Rec f es -> Int
- empty :: Rec f '[]
- singleton :: f e -> Rec f '[e]
- cons :: f e -> Rec f es -> Rec f (e ': es)
- pattern (:~:) :: f e -> Rec f es -> Rec f (e ': es)
- type family xs ++ ys where ...
- concat :: Rec f es -> Rec f es' -> Rec f (es ++ es')
- pattern (:++:) :: forall es es' f. KnownList es => Rec f es -> Rec f es' -> Rec f (es ++ es')
- tail :: Rec f (e ': es) -> Rec f es
- class KnownList (es :: [k])
- drop :: forall es es' f. KnownList es => Rec f (es ++ es') -> Rec f es'
- head :: Rec f (e ': es) -> f e
- take :: forall es es' f. KnownList es => Rec f (es ++ es') -> Rec f es
- class Elem (e :: k) (es :: [k])
- index :: forall e es f. Elem e es => Rec f es -> f e
- class KnownList es => Subset (es :: [k]) (es' :: [k])
- pick :: forall es es' f. Subset es es' => Rec f es' -> Rec f es
- modify :: forall e es f. Elem e es => f e -> Rec f es -> Rec f es
- (/~/) :: Elem e es => f e -> Rec f es -> Rec f es
- batch :: forall es es' f. Subset es es' => Rec f es -> Rec f es' -> Rec f es'
- (/++/) :: Subset es es' => Rec f es -> Rec f es' -> Rec f es'
- type (~>) f g = forall a. f a -> g a
- natural :: (f ~> g) -> Rec f es -> Rec g es
- (<#>) :: (f ~> g) -> Rec f es -> Rec g es
- zipWith :: (forall x. f x -> g x -> h x) -> Rec f es -> Rec g es -> Rec h es
- all :: (forall x. f x -> Bool) -> Rec f es -> Bool
- any :: (forall x. f x -> Bool) -> Rec f es -> Bool
- degenerate :: Rec (Const a) es -> [a]
- extract :: (forall x. f x -> a) -> Rec f es -> [a]
- invariant :: Rec f es -> Rec f es
- sizeInvariant :: Rec f es -> Rec f es
- allAccessible :: Rec f es -> Rec f es
Documentation
data Rec (f :: k -> Type) (es :: [k]) Source #
Extensible record type supporting efficient \( O(1) \) reads. The underlying implementation is SmallArray
slices, therefore suits small numbers of entries (i.e. less than 128).
Instances
(forall (x :: k). Eq (f x)) => Eq (Rec f xs) Source # | |
(Eq (Rec f xs), Eq (f x)) => Eq (Rec f (x ': xs)) Source # | |
Eq (Rec f ('[] :: [k])) Source # | |
(Read (f x), Read (Rec f xs)) => Read (Rec f (x ': xs)) Source # |
|
Read (Rec f ('[] :: [k])) Source # |
|
(forall (x :: k). Show (f x)) => Show (Rec f xs) Source # |
|
(Show (f x), Show (Rec f xs)) => Show (Rec f (x ': xs)) Source # |
|
Show (Rec f ('[] :: [k])) Source # |
|
(forall (x :: k). Semigroup (f x)) => Semigroup (Rec f xs) Source # | |
(Semigroup (f x), Semigroup (Rec f xs)) => Semigroup (Rec f (x ': xs)) Source # | One-by-one semigroup operation instead of concatenation. (x |
Semigroup (Rec f ('[] :: [k])) Source # | |
(Monoid (f x), Monoid (Rec f xs)) => Monoid (Rec f (x ': xs)) Source # | The unit of a record type are the units of its element types:
|
Monoid (Rec f ('[] :: [k])) Source # |
|
Construction
Addition
pattern (:~:) :: f e -> Rec f es -> Rec f (e ': es) infixr 5 Source #
Infix version of cons
that also supports destructuring.
pattern (:++:) :: forall es es' f. KnownList es => Rec f es -> Rec f es' -> Rec f (es ++ es') infixr 5 Source #
Infix version of concat
that also supports destructuring.
Deletion
tail :: Rec f (e ': es) -> Rec f es Source #
Slice off one entry from the top of the record. \( O(1) \).
class KnownList (es :: [k]) Source #
The list es
list is concrete, i.e. is of the form '[a1, a2, ..., an]
, i.e. is not a type variable.
drop :: forall es es' f. KnownList es => Rec f (es ++ es') -> Rec f es' Source #
Slice off several entries from the top of the record. \( O(1) \).
Retrieval
take :: forall es es' f. KnownList es => Rec f (es ++ es') -> Rec f es Source #
Take elements from the top of the record. \( O(m) \).
index :: forall e es f. Elem e es => Rec f es -> f e Source #
Get an element in the record. Amortized \( O(1) \).
pick :: forall es es' f. Subset es es' => Rec f es' -> Rec f es Source #
Get a subset of the record. Amortized \( O(m) \).
Modification
modify :: forall e es f. Elem e es => f e -> Rec f es -> Rec f es Source #
Modify an entry in the record. \( O(n) \).
batch :: forall es es' f. Subset es es' => Rec f es -> Rec f es' -> Rec f es' Source #
Merge a subset into the original record, updating several entries at once. \( O(m+n) \).
(/++/) :: Subset es es' => Rec f es -> Rec f es' -> Rec f es' infixl 9 Source #
Infix version of batch
.
Mapping
type (~>) f g = forall a. f a -> g a infixr 0 Source #
The type of natural transformations from functor f
to g
.
natural :: (f ~> g) -> Rec f es -> Rec g es Source #
Apply a natural transformation to the record. \( O(n) \).
zipWith :: (forall x. f x -> g x -> h x) -> Rec f es -> Rec g es -> Rec h es Source #
Zip two records with a natural transformation. \( O(n) \).
all :: (forall x. f x -> Bool) -> Rec f es -> Bool Source #
Check if a predicate is true on all elements. \( O(n) \).
any :: (forall x. f x -> Bool) -> Rec f es -> Bool Source #
Check if a predicate is true on at least one element. \( O(n) \).
degenerate :: Rec (Const a) es -> [a] Source #
Convert a record that effectively contains a fixed type into a list of the fixed type. \( O(n) \).
extract :: (forall x. f x -> a) -> Rec f es -> [a] Source #
Map each element to a fixed type. \( O(n) \).