Copyright | (c) 2021 Xy Ren |
---|---|
License | BSD3 |
Maintainer | xy.r@outlook.com |
Stability | unstable |
Portability | non-portable (GHC only) |
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]) = Rec !Int !Int !(SmallArray Any)
- type family xs ++ ys where ...
- empty :: Rec f '[]
- cons :: f e -> Rec f es -> Rec f (e ': es)
- concat :: Rec f es -> Rec f es' -> Rec f (es ++ es')
- class KnownList (es :: [k])
- head :: Rec f (e ': es) -> f e
- take :: forall es es' f. KnownList es => Rec f (es ++ es') -> Rec f es
- tail :: Rec f (e ': es) -> Rec f es
- drop :: forall es es' f. KnownList es => Rec f (es ++ es') -> Rec f es'
- class Elem (e :: k) (es :: [k])
- class KnownList es => Subset (es :: [k]) (es' :: [k])
- index :: forall e es f. Elem e es => Rec f es -> f e
- pick :: forall es es' f. Subset es es' => Rec f es' -> Rec f es
- update :: forall e es f. Elem e es => f e -> Rec f es -> Rec f es
- newArr :: Int -> ST s (SmallMutableArray s Any)
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).
Rec | |
|
Construction
Deconstruction
class KnownList (es :: [k]) Source #
means the list KnownList
eses
is concrete, i.e. is of the form '[a1, a2, ..., an]
instead of a type
variable.
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) \).
tail :: Rec f (e ': es) -> Rec f es Source #
Slice off one entry from the top of the record. \( O(1) \).
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 and updating
class Elem (e :: k) (es :: [k]) Source #
The element e
is present in the list es
.
Instances
(TypeError (ElemNotFound e) :: Constraint) => Elem (e :: k) ('[] :: [k]) Source # | |
Defined in Cleff.Internal.Rec reifyIndex :: Int | |
Elem e es => Elem (e :: a) (e' ': es :: [a]) Source # | |
Defined in Cleff.Internal.Rec reifyIndex :: Int | |
Elem (e :: a) (e ': es :: [a]) Source # | The element closer to the head takes priority. |
Defined in Cleff.Internal.Rec reifyIndex :: Int |
class KnownList es => Subset (es :: [k]) (es' :: [k]) Source #
es
is a subset of es'
, i.e. all elements of es
are in es'
.
Instances
Subset ('[] :: [k]) (es :: [k]) Source # | |
Defined in Cleff.Internal.Rec reifyIndices :: [Int] | |
(Subset es es', Elem e es') => Subset (e ': es :: [k]) (es' :: [k]) Source # | |
Defined in Cleff.Internal.Rec reifyIndices :: [Int] |
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) \).
update :: forall e es f. Elem e es => f e -> Rec f es -> Rec f es Source #
Update an entry in the record. \( O(n) \).
Helpers
newArr :: Int -> ST s (SmallMutableArray s Any) Source #
Create a new SmallMutableArray
with no contents.