Safe Haskell | Safe-Inferred |
---|
Tables of values and keys for that tables.
Each value in the table may be accompanied with references to other tables.
- type MS = MaybeT STM
- class Binary u => Multitude u
- data Single
- data Multiple
- data Table t r a
- data Key t a i u
- data TableVarU t a u
- type TableVar t a = TableVarU t a Single
- type TableVars t a = TableVarU t a Multiple
- fromList :: [TableVar t a] -> TableVars t a
- toList :: TableVars t a -> [TableVar t a]
- readVar :: Table t r a -> TableVar t a -> MS a
- readRefs :: Table t r a -> TableVar t a -> MS (r TableVarU)
- data TableRef t a u
- only :: Table t r a -> TableRef t a Single
- some :: Table t r a -> TableRef t a Multiple
- data KeySpec r a i u
- single :: (a -> i) -> KeySpec r a i Single
- multiple :: (a -> i) -> KeySpec r a i Multiple
- single_ :: (a -> r TableVarU -> i) -> KeySpec r a i Single
- multiple_ :: (a -> r TableVarU -> i) -> KeySpec r a i Multiple
- class RefsC r
- data Refs f = Refs
- class RefsComponent r
- data Ref t a u
- data (rs :&: r) f where
- class KeysC k
- data Keys f = Keys
- class KeysComponent k
- data KeyRef i u
- data (ks :+: k) f where
- data Spec r k a = Spec {}
- data Created t r k a = Created {}
- createTable :: (KeysC k, Monad m, MonadSTM m, RefsC r) => Spec r k a -> (forall t. Created t r k a -> m b) -> m b
- select :: Ord i => Key t a i Single -> i -> MS (TableVar t a)
- select_ :: (Multitude u, Ord i) => Key t a i u -> i -> (forall o. Ord o => o -> o -> Bool) -> STM [TableVar t a]
- insert :: Table t r a -> a -> r TableVarU -> MS (TableVar t a)
- update :: Table t r a -> TableVar t a -> a -> MS ()
- update_ :: Table t r a -> TableVar t a -> a -> r TableVarU -> MS ()
- delete :: Table t r a -> TableVar t a -> MS ()
- getTable :: Binary a => Table t r a -> Get (STM ())
- getTable_ :: Get a -> Table t r a -> Get (STM ())
- getTable__ :: (Monad m, MonadSTM m) => Get (m a) -> Table t r a -> Get (m ())
- putTable :: Binary a => Table t r a -> STM Put
- putTable_ :: (a -> Put) -> Table t r a -> STM Put
- putTable__ :: (Monad m, MonadSTM m) => (a -> m Put) -> Table t r a -> m Put
Documentation
STM
that can fail.
Note that it doesn't revert the transaction on failure.
class Binary u => Multitude u Source
Closed class. It's instances allow us to choose whether we want to get a single value or multiple ones.
This type specifies that we want multiple values.
Abstract type, which represents a collection of values of type a
,
possibly accompanied with some references to other Table
s.
The type t
is an abstract type, used to ensure that we don't confuse
different tables with values of the same type.
r
is a type of references accompanying each value.
Abstract type, which allows us to select
one or many values from the Table
.
Type t
is an abstract type, same as in the Table
.
Type a
is a type of values, also same as in the Table
.
Type i
is a type of index values, used by this key.
Type u
is either Multiple
or Single
, depending on whether this key
allows different values to have the same index, or not.
fromList :: [TableVar t a] -> TableVars t aSource
Function that converts a list of single-value references
to a single multiple-value reference.
Normally it should only be used in cInsert
statments.
toList :: TableVars t a -> [TableVar t a]Source
Function that converts a multiple-value reference
to a list of single-value references.
Should be used with multiple-value references accompanying values in the Table
.
readRefs :: Table t r a -> TableVar t a -> MS (r TableVarU)Source
Function that reads all references accompanying the value.
Type that is a template for references to another table. Used only in Spec
s.
Type t
is an abstract type, same as in the Table
.
Type a
is a type of values in that Table
.
Type u
is either Single
or Multiple
,
depending on whether the reference, accompanying the value,
should be single-value or multiple-value
only :: Table t r a -> TableRef t a SingleSource
Each value in the table-to-be should be accompanied with a single-value reference.
some :: Table t r a -> TableRef t a MultipleSource
Each value in the table-to-be should be accompanied with a multiple-value reference.
Type that is a template for the key. Used only in Spec
s.
Type t
is an abstract type, same as in the Table
.
Type a
is a type of values in that Table
.
Type i
is a type of index values, used by this key.
Type u
is either Multiple
or Single
, depending on whether this key
allows different values to have the same index, or not.
single :: (a -> i) -> KeySpec r a i SingleSource
This key will provide access to a single value within a Table
.
It's index will be calculated, based on this value alone.
multiple :: (a -> i) -> KeySpec r a i MultipleSource
This key will provide access to multiple values in the same Table
.
Their indices will be calculated based on the value alone.
single_ :: (a -> r TableVarU -> i) -> KeySpec r a i SingleSource
This is a more generic version of single
.
The difference is that value index will be calculated based on both the value
and it's accompanying references.
multiple_ :: (a -> r TableVarU -> i) -> KeySpec r a i MultipleSource
This is a more generic version of multiple
.
The difference is that value index will be calculated based on both the value
and it's accompanying references.
Empty reference specification. It doesn't specify any reference whatsoever.
class RefsComponent r Source
Class of the part of reference specification, corresponding to one reference.
Multitude u => RefsComponent (Ref t a u) |
One table reference specification.
Note that it can't be used in the sRefs
field by itself,
but rather should be combined with Refs
with the :&:
operator.
Multitude u => RefsComponent (Ref t a u) |
Combining operator for reference specifications.
(RefsC rs, RefsComponent r) => RefsC (:&: rs r) |
class KeysComponent k Source
Class of the part of key specification, corresponding to one key.
(Multitude u, Ord i) => KeysComponent (KeyRef i u) |
One key specification.
Note that it can't be used in the sKeys
field by itself,
but rather should be combined with Keys
with the :+:
operator.
(Multitude u, Ord i) => KeysComponent (KeyRef i u) |
Combining operator for key specifications.
(KeysC ks, KeysComponent k) => KeysC (:+: ks k) |
Type of table specifications.
Output of the createTable
function.
createTable :: (KeysC k, Monad m, MonadSTM m, RefsC r) => Spec r k a -> (forall t. Created t r k a -> m b) -> m bSource
select_ :: (Multitude u, Ord i) => Key t a i u -> i -> (forall o. Ord o => o -> o -> Bool) -> STM [TableVar t a]Source
A more generic version of select
. Instead of one value, it returns multiple ones.
It can also select values with indices that are smaller or greater to the provided one,
depending on the third argument, which could be anything like (>)
, (<=)
, (/=)
,
or even return True
.
insert :: Table t r a -> a -> r TableVarU -> MS (TableVar t a)Source
Function that lets one to insert a new value to the Table
.
Of course, we have to provide accompanying references as well.
This function can fail if some key clashes with an already existing one.
update_ :: Table t r a -> TableVar t a -> a -> r TableVarU -> MS ()Source
More generic version of update
.
It allows changing accompanying references as well as the value.
delete :: Table t r a -> TableVar t a -> MS ()Source
Function that removes the value (along with accompanying references)
from the Table
. It only fails if the value was already removed.
getTable :: Binary a => Table t r a -> Get (STM ())Source
Function that makes it possible to read the table from the file or other source. Table should be created beforehand, as specifications are not serializable.
getTable_ :: Get a -> Table t r a -> Get (STM ())Source
More generic version of getTable
that allows to change the way values are serialized.
putTable :: Binary a => Table t r a -> STM PutSource
Function that makes it possible to write the table to the file or other storage.
putTable_ :: (a -> Put) -> Table t r a -> STM PutSource
More generic version of putTable
that allows to change the way values are serialized.