-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | RON, RON-RDT, and RON-Schema -- -- Replicated Object Notation (RON), data types (RDT), and RON-Schema -- -- Typical usage: -- --
-- import RON.Data
-- import RON.Schema.TH
-- import RON.Storage.IO as Storage
--
-- $(let note = StructLww "Note"
-- [ ("active", field boole)
-- , ("text", field rgaString) ]
-- def{saHaskellDeriving = ["Eq", "Show"]}
-- in mkReplicated [DStructLww note])
--
-- instance Collection Note where
-- collectionName = "note"
--
-- main :: IO ()
-- main = do
-- let dataDir = "./data/"
-- h <- Storage.newHandle dataDir
-- runStorage h $ do
-- obj <- newObject
-- Note{active = True, text = "Выступить на FProg SPb"}
-- createDocument obj
--
@package ron
@version 0.2
module RON.Internal.Prelude
-- | Instance
data I c
I :: a -> I c
newtype MaxOnFst a b
MaxOnFst :: (a, b) -> MaxOnFst a b
type ByteStringL = ByteString
maxOn :: Ord b => (a -> b) -> a -> a -> a
minOn :: Ord b => (a -> b) -> a -> a -> a
listSingleton :: a -> [a]
(-:) :: a -> b -> (a, b)
infixr 0 -:
-- | Extract the first component of a pair.
fst :: () => (a, b) -> a
-- | Extract the second component of a pair.
snd :: () => (a, b) -> b
-- | Application operator. This operator is redundant, since ordinary
-- application (f x) means the same as (f $ x).
-- However, $ has low, right-associative binding precedence, so it
-- sometimes allows parentheses to be omitted; for example:
--
-- -- f $ g $ h x = f (g (h x)) ---- -- It is also useful in higher-order situations, such as map -- ($ 0) xs, or zipWith ($) fs xs. -- -- Note that ($) is levity-polymorphic in its result type, so -- that foo $ True where foo :: Bool -> Int# is well-typed ($) :: () => (a -> b) -> a -> b infixr 0 $ -- | The function coerce allows you to safely convert between -- values of types that have the same representation with no run-time -- overhead. In the simplest case you can use it instead of a newtype -- constructor, to go from the newtype's concrete type to the abstract -- type. But it also works in more complicated settings, e.g. converting -- a list of newtypes to a list of concrete types. coerce :: Coercible a b => a -> b -- | Conditional failure of Alternative computations. Defined by -- --
-- guard True = pure () -- guard False = empty ---- --
-- >>> safeDiv 4 0 -- Nothing -- >>> safeDiv 4 2 -- Just 2 ---- -- A definition of safeDiv using guards, but not guard: -- --
-- safeDiv :: Int -> Int -> Maybe Int -- safeDiv x y | y /= 0 = Just (x `div` y) -- | otherwise = Nothing ---- -- A definition of safeDiv using guard and Monad -- do-notation: -- --
-- safeDiv :: Int -> Int -> Maybe Int -- safeDiv x y = do -- guard (y /= 0) -- return (x `div` y) --guard :: Alternative f => Bool -> f () -- | The join function is the conventional monad join operator. It -- is used to remove one level of monadic structure, projecting its bound -- argument into the outer level. -- --
-- atomically :: STM a -> IO a ---- -- is used to run STM transactions atomically. So, by specializing -- the types of atomically and join to -- --
-- atomically :: STM (IO b) -> IO (IO b) -- join :: IO (IO b) -> IO b ---- -- we can compose them as -- --
-- join . atomically :: STM (IO b) -> IO b ---- -- to run an STM transaction and the IO action it returns. join :: Monad m => m (m a) -> m a -- | The Monad class defines the basic operations over a -- monad, a concept from a branch of mathematics known as -- category theory. From the perspective of a Haskell programmer, -- however, it is best to think of a monad as an abstract datatype -- of actions. Haskell's do expressions provide a convenient -- syntax for writing monadic expressions. -- -- Instances of Monad should satisfy the following laws: -- -- -- -- Furthermore, the Monad and Applicative operations should -- relate as follows: -- -- -- -- The above laws imply: -- -- -- -- and that pure and (<*>) satisfy the applicative -- functor laws. -- -- The instances of Monad for lists, Maybe and IO -- defined in the Prelude satisfy these laws. class Applicative m => Monad (m :: Type -> Type) -- | Sequentially compose two actions, passing any value produced by the -- first as an argument to the second. (>>=) :: Monad m => m a -> (a -> m b) -> m b -- | Sequentially compose two actions, discarding any value produced by the -- first, like sequencing operators (such as the semicolon) in imperative -- languages. (>>) :: Monad m => m a -> m b -> m b -- | Inject a value into the monadic type. return :: Monad m => a -> m a -- | Fail with a message. This operation is not part of the mathematical -- definition of a monad, but is invoked on pattern-match failure in a -- do expression. -- -- As part of the MonadFail proposal (MFP), this function is moved to its -- own class MonadFail (see Control.Monad.Fail for more -- details). The definition here will be removed in a future release. fail :: Monad m => String -> m a infixl 1 >>= infixl 1 >> -- | The Functor class is used for types that can be mapped over. -- Instances of Functor should satisfy the following laws: -- --
-- fmap id == id -- fmap (f . g) == fmap f . fmap g ---- -- The instances of Functor for lists, Maybe and IO -- satisfy these laws. class Functor (f :: Type -> Type) fmap :: Functor f => (a -> b) -> f a -> f b -- | Replace all locations in the input with the same value. The default -- definition is fmap . const, but this may be -- overridden with a more efficient version. (<$) :: Functor f => a -> f b -> f a infixl 4 <$ -- | A functor with application, providing operations to -- --
-- (<*>) = liftA2 id ---- --
-- liftA2 f x y = f <$> x <*> y ---- -- Further, any definition must satisfy the following: -- --
pure id <*> -- v = v
pure (.) <*> u -- <*> v <*> w = u <*> (v -- <*> w)
pure f <*> -- pure x = pure (f x)
u <*> pure y = -- pure ($ y) <*> u
-- forall x y. p (q x y) = f x . g y ---- -- it follows from the above that -- --
-- liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g v ---- -- If f is also a Monad, it should satisfy -- -- -- -- (which implies that pure and <*> satisfy the -- applicative functor laws). class Functor f => Applicative (f :: Type -> Type) -- | Lift a value. pure :: Applicative f => a -> f a -- | Sequential application. -- -- A few functors support an implementation of <*> that is -- more efficient than the default one. (<*>) :: Applicative f => f (a -> b) -> f a -> f b -- | Lift a binary function to actions. -- -- Some functors support an implementation of liftA2 that is more -- efficient than the default one. In particular, if fmap is an -- expensive operation, it is likely better to use liftA2 than to -- fmap over the structure and then use <*>. liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c -- | Sequence actions, discarding the value of the first argument. (*>) :: Applicative f => f a -> f b -> f b -- | Sequence actions, discarding the value of the second argument. (<*) :: Applicative f => f a -> f b -> f a infixl 4 <*> infixl 4 *> infixl 4 <* -- | Data structures that can be folded. -- -- For example, given a data type -- --
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) ---- -- a suitable instance would be -- --
-- instance Foldable Tree where -- foldMap f Empty = mempty -- foldMap f (Leaf x) = f x -- foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r ---- -- This is suitable even for abstract types, as the monoid is assumed to -- satisfy the monoid laws. Alternatively, one could define -- foldr: -- --
-- instance Foldable Tree where -- foldr f z Empty = z -- foldr f z (Leaf x) = f x z -- foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l ---- -- Foldable instances are expected to satisfy the following -- laws: -- --
-- foldr f z t = appEndo (foldMap (Endo . f) t ) z ---- --
-- foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z ---- --
-- fold = foldMap id ---- --
-- length = getSum . foldMap (Sum . const 1) ---- -- sum, product, maximum, and minimum -- should all be essentially equivalent to foldMap forms, such -- as -- --
-- sum = getSum . foldMap Sum ---- -- but may be less defined. -- -- If the type is also a Functor instance, it should satisfy -- --
-- foldMap f = fold . fmap f ---- -- which implies that -- --
-- foldMap f . fmap g = foldMap (f . g) --class Foldable (t :: Type -> Type) -- | Combine the elements of a structure using a monoid. fold :: (Foldable t, Monoid m) => t m -> m -- | Map each element of the structure to a monoid, and combine the -- results. foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m -- | Right-associative fold of a structure. -- -- In the case of lists, foldr, when applied to a binary operator, -- a starting value (typically the right-identity of the operator), and a -- list, reduces the list using the binary operator, from right to left: -- --
-- foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...) ---- -- Note that, since the head of the resulting expression is produced by -- an application of the operator to the first element of the list, -- foldr can produce a terminating expression from an infinite -- list. -- -- For a general Foldable structure this should be semantically -- identical to, -- --
-- foldr f z = foldr f z . toList --foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b -- | Right-associative fold of a structure, but with strict application of -- the operator. foldr' :: Foldable t => (a -> b -> b) -> b -> t a -> b -- | Left-associative fold of a structure. -- -- In the case of lists, foldl, when applied to a binary operator, -- a starting value (typically the left-identity of the operator), and a -- list, reduces the list using the binary operator, from left to right: -- --
-- foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn ---- -- Note that to produce the outermost application of the operator the -- entire input list must be traversed. This means that foldl' -- will diverge if given an infinite list. -- -- Also note that if you want an efficient left-fold, you probably want -- to use foldl' instead of foldl. The reason for this is -- that latter does not force the "inner" results (e.g. z f -- x1 in the above example) before applying them to the operator -- (e.g. to (f x2)). This results in a thunk chain -- O(n) elements long, which then must be evaluated from the -- outside-in. -- -- For a general Foldable structure this should be semantically -- identical to, -- --
-- foldl f z = foldl f z . toList --foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b -- | Left-associative fold of a structure but with strict application of -- the operator. -- -- This ensures that each step of the fold is forced to weak head normal -- form before being applied, avoiding the collection of thunks that -- would otherwise occur. This is often what you want to strictly reduce -- a finite list to a single, monolithic result (e.g. length). -- -- For a general Foldable structure this should be semantically -- identical to, -- --
-- foldl f z = foldl' f z . toList --foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b -- | A variant of foldr that has no base case, and thus may only be -- applied to non-empty structures. -- --
-- foldr1 f = foldr1 f . toList --foldr1 :: Foldable t => (a -> a -> a) -> t a -> a -- | A variant of foldl that has no base case, and thus may only be -- applied to non-empty structures. -- --
-- foldl1 f = foldl1 f . toList --foldl1 :: Foldable t => (a -> a -> a) -> t a -> a -- | List of elements of a structure, from left to right. toList :: Foldable t => t a -> [a] -- | Test whether the structure is empty. The default implementation is -- optimized for structures that are similar to cons-lists, because there -- is no general way to do better. null :: Foldable t => t a -> Bool -- | Returns the size/length of a finite structure as an Int. The -- default implementation is optimized for structures that are similar to -- cons-lists, because there is no general way to do better. length :: Foldable t => t a -> Int -- | Does the element occur in the structure? elem :: (Foldable t, Eq a) => a -> t a -> Bool -- | The largest element of a non-empty structure. maximum :: (Foldable t, Ord a) => t a -> a -- | The least element of a non-empty structure. minimum :: (Foldable t, Ord a) => t a -> a -- | The sum function computes the sum of the numbers of a -- structure. sum :: (Foldable t, Num a) => t a -> a -- | The product function computes the product of the numbers of a -- structure. product :: (Foldable t, Num a) => t a -> a infix 4 `elem` -- | Functors representing data structures that can be traversed from left -- to right. -- -- A definition of traverse must satisfy the following laws: -- --
-- t :: (Applicative f, Applicative g) => f a -> g a ---- -- preserving the Applicative operations, i.e. -- -- -- -- and the identity functor Identity and composition of functors -- Compose are defined as -- --
-- newtype Identity a = Identity a -- -- instance Functor Identity where -- fmap f (Identity x) = Identity (f x) -- -- instance Applicative Identity where -- pure x = Identity x -- Identity f <*> Identity x = Identity (f x) -- -- newtype Compose f g a = Compose (f (g a)) -- -- instance (Functor f, Functor g) => Functor (Compose f g) where -- fmap f (Compose x) = Compose (fmap (fmap f) x) -- -- instance (Applicative f, Applicative g) => Applicative (Compose f g) where -- pure x = Compose (pure (pure x)) -- Compose f <*> Compose x = Compose ((<*>) <$> f <*> x) ---- -- (The naturality law is implied by parametricity.) -- -- Instances are similar to Functor, e.g. given a data type -- --
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) ---- -- a suitable instance would be -- --
-- instance Traversable Tree where -- traverse f Empty = pure Empty -- traverse f (Leaf x) = Leaf <$> f x -- traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r ---- -- This is suitable even for abstract types, as the laws for -- <*> imply a form of associativity. -- -- The superclass instances should satisfy the following: -- --
-- from . to ≡ id -- to . from ≡ id --class Generic a where { -- | Generic representation type type family Rep a :: Type -> Type; } -- | Convert from the datatype to its representation from :: Generic a => a -> Rep a x -- | Convert from the representation to the datatype to :: Generic a => Rep a x -> a -- | Representable types of kind * -> * (or kind k -> -- *, when PolyKinds is enabled). This class is derivable -- in GHC with the DeriveGeneric flag on. -- -- A Generic1 instance must satisfy the following laws: -- --
-- from1 . to1 ≡ id -- to1 . from1 ≡ id --class Generic1 (f :: k -> Type) where { -- | Generic representation type type family Rep1 (f :: k -> Type) :: k -> Type; } -- | Convert from the datatype to its representation from1 :: Generic1 f => f a -> Rep1 f a -- | Convert from the representation to the datatype to1 :: Generic1 f => Rep1 f a -> f a -- | Class for datatypes that represent datatypes class Datatype (d :: k) -- | The name of the datatype (unqualified) datatypeName :: Datatype d => t d f a -> [Char] -- | The fully-qualified name of the module where the type is declared moduleName :: Datatype d => t d f a -> [Char] -- | The package name of the module where the type is declared packageName :: Datatype d => t d f a -> [Char] -- | Marks if the datatype is actually a newtype isNewtype :: Datatype d => t d f a -> Bool -- | Class for datatypes that represent data constructors class Constructor (c :: k) -- | The name of the constructor conName :: Constructor c => t c f a -> [Char] -- | The fixity of the constructor conFixity :: Constructor c => t c f a -> Fixity -- | Marks if this constructor is a record conIsRecord :: Constructor c => t c f a -> Bool -- | Class for datatypes that represent records class Selector (s :: k) -- | The name of the selector selName :: Selector s => t s f a -> [Char] -- | The selector's unpackedness annotation (if any) selSourceUnpackedness :: Selector s => t s f a -> SourceUnpackedness -- | The selector's strictness annotation (if any) selSourceStrictness :: Selector s => t s f a -> SourceStrictness -- | The strictness that the compiler inferred for the selector selDecidedStrictness :: Selector s => t s f a -> DecidedStrictness -- | This class gives the integer associated with a type-level natural. -- There are instances of the class for every concrete literal: 0, 1, 2, -- etc. class KnownNat (n :: Nat) -- | This class gives the string associated with a type-level symbol. There -- are instances of the class for every concrete literal: "hello", etc. class KnownSymbol (n :: Symbol) -- | An associative operation. (<>) :: Semigroup a => a -> a -> a infixr 6 <> -- | Reduce a non-empty list with <> -- -- The default definition should be sufficient, but this can be -- overridden for efficiency. sconcat :: Semigroup a => NonEmpty a -> a -- | 8-bit signed integer type data Int8 -- | 16-bit signed integer type data Int16 -- | 32-bit signed integer type data Int32 -- | 64-bit signed integer type data Int64 -- | The Maybe type encapsulates an optional value. A value of type -- Maybe a either contains a value of type a -- (represented as Just a), or it is empty (represented -- as Nothing). Using Maybe is a good way to deal with -- errors or exceptional cases without resorting to drastic measures such -- as error. -- -- The Maybe type is also a monad. It is a simple kind of error -- monad, where all errors are represented by Nothing. A richer -- error monad can be built using the Either type. data Maybe a Nothing :: Maybe a Just :: a -> Maybe a -- | 8-bit unsigned integer type data Word8 -- | 16-bit unsigned integer type data Word16 -- | 32-bit unsigned integer type data Word32 -- | 64-bit unsigned integer type data Word64 -- | The Either type represents values with two possibilities: a -- value of type Either a b is either Left -- a or Right b. -- -- The Either type is sometimes used to represent a value which is -- either correct or an error; by convention, the Left constructor -- is used to hold an error value and the Right constructor is -- used to hold a correct value (mnemonic: "right" also means "correct"). -- --
-- >>> let s = Left "foo" :: Either String Int -- -- >>> s -- Left "foo" -- -- >>> let n = Right 3 :: Either String Int -- -- >>> n -- Right 3 -- -- >>> :type s -- s :: Either String Int -- -- >>> :type n -- n :: Either String Int ---- -- The fmap from our Functor instance will ignore -- Left values, but will apply the supplied function to values -- contained in a Right: -- --
-- >>> let s = Left "foo" :: Either String Int -- -- >>> let n = Right 3 :: Either String Int -- -- >>> fmap (*2) s -- Left "foo" -- -- >>> fmap (*2) n -- Right 6 ---- -- The Monad instance for Either allows us to chain -- together multiple actions which may fail, and fail overall if any of -- the individual steps failed. First we'll write a function that can -- either parse an Int from a Char, or fail. -- --
-- >>> import Data.Char ( digitToInt, isDigit )
--
-- >>> :{
-- let parseEither :: Char -> Either String Int
-- parseEither c
-- | isDigit c = Right (digitToInt c)
-- | otherwise = Left "parse error"
--
-- >>> :}
--
--
-- The following should work, since both '1' and '2'
-- can be parsed as Ints.
--
--
-- >>> :{
-- let parseMultiple :: Either String Int
-- parseMultiple = do
-- x <- parseEither '1'
-- y <- parseEither '2'
-- return (x + y)
--
-- >>> :}
--
--
-- -- >>> parseMultiple -- Right 3 ---- -- But the following should fail overall, since the first operation where -- we attempt to parse 'm' as an Int will fail: -- --
-- >>> :{
-- let parseMultiple :: Either String Int
-- parseMultiple = do
-- x <- parseEither 'm'
-- y <- parseEither '2'
-- return (x + y)
--
-- >>> :}
--
--
-- -- >>> parseMultiple -- Left "parse error" --data Either a b Left :: a -> Either a b Right :: b -> Either a b -- | Void: used for datatypes without constructors data V1 (p :: k) :: forall k. () => k -> Type -- | Unit: used for constructors without arguments data U1 (p :: k) :: forall k. () => k -> Type U1 :: U1 -- | Used for marking occurrences of the parameter newtype Par1 p Par1 :: p -> Par1 p [unPar1] :: Par1 p -> p -- | Recursive calls of kind * -> * (or kind k -> -- *, when PolyKinds is enabled) newtype Rec1 (f :: k -> Type) (p :: k) :: forall k. () => k -> Type -> k -> Type Rec1 :: f p -> Rec1 [unRec1] :: Rec1 -> f p -- | Constants, additional parameters and recursion of kind * newtype K1 i c (p :: k) :: forall k. () => Type -> Type -> k -> Type K1 :: c -> K1 i c [unK1] :: K1 i c -> c -- | Meta-information (constructor names, etc.) newtype M1 i (c :: Meta) (f :: k -> Type) (p :: k) :: forall k. () => Type -> Meta -> k -> Type -> k -> Type M1 :: f p -> M1 i [unM1] :: M1 i -> f p -- | Sums: encode choice between constructors data (:+:) (f :: k -> Type) (g :: k -> Type) (p :: k) :: forall k. () => k -> Type -> k -> Type -> k -> Type L1 :: f p -> (:+:) R1 :: g p -> (:+:) infixr 5 :+: -- | Products: encode multiple arguments to constructors data (:*:) (f :: k -> Type) (g :: k -> Type) (p :: k) :: forall k. () => k -> Type -> k -> Type -> k -> Type (:*:) :: f p -> g p -> (:*:) infixr 6 :*: infixr 6 :*: -- | Composition of functors newtype (:.:) (f :: k2 -> Type) (g :: k1 -> k2) (p :: k1) :: forall k2 k1. () => k2 -> Type -> k1 -> k2 -> k1 -> Type Comp1 :: f (g p) -> (:.:) [unComp1] :: (:.:) -> f (g p) infixr 7 :.: -- | Tag for K1: recursion (of kind Type) data R -- | Tag for M1: datatype data D -- | Tag for M1: constructor data C -- | Tag for M1: record selector data S -- | Type synonym for encoding recursion (of kind Type) type Rec0 = (K1 R :: Type -> k -> Type) -- | Type synonym for encoding meta-information for datatypes type D1 = (M1 D :: Meta -> k -> Type -> k -> Type) -- | Type synonym for encoding meta-information for constructors type C1 = (M1 C :: Meta -> k -> Type -> k -> Type) -- | Type synonym for encoding meta-information for record selectors type S1 = (M1 S :: Meta -> k -> Type -> k -> Type) -- | Constants of unlifted kinds data family URec a (p :: k) :: Type -- | Type synonym for URec Addr# type UAddr = (URec Ptr () :: k -> Type) -- | Type synonym for URec Char# type UChar = (URec Char :: k -> Type) -- | Type synonym for URec Double# type UDouble = (URec Double :: k -> Type) -- | Type synonym for URec Float# type UFloat = (URec Float :: k -> Type) -- | Type synonym for URec Int# type UInt = (URec Int :: k -> Type) -- | Type synonym for URec Word# type UWord = (URec Word :: k -> Type) -- | (Kind) This is the kind of type-level natural numbers. data Nat -- | (Kind) This is the kind of type-level symbols. Declared here because -- class IP needs it data Symbol -- | Addition of type-level naturals. type family (+) (a :: Nat) (b :: Nat) :: Nat infixl 6 + -- | Multiplication of type-level naturals. type family (*) (a :: Nat) (b :: Nat) :: Nat infixl 7 * -- | Exponentiation of type-level naturals. type family (^) (a :: Nat) (b :: Nat) :: Nat infixr 8 ^ -- | Comparison of type-level naturals, as a function. NOTE: The -- functionality for this function should be subsumed by CmpNat, -- so this might go away in the future. Please let us know, if you -- encounter discrepancies between the two. type family (<=?) (a :: Nat) (b :: Nat) :: Bool infix 4 <=? -- | Subtraction of type-level naturals. type family (-) (a :: Nat) (b :: Nat) :: Nat infixl 6 - -- | Comparison of type-level symbols, as a function. type family CmpSymbol (a :: Symbol) (b :: Symbol) :: Ordering -- | Comparison of type-level naturals, as a function. type family CmpNat (a :: Nat) (b :: Nat) :: Ordering -- | Division (round down) of natural numbers. Div x 0 is -- undefined (i.e., it cannot be reduced). type family Div (a :: Nat) (b :: Nat) :: Nat infixl 7 `Div` -- | Modulus of natural numbers. Mod x 0 is undefined (i.e., it -- cannot be reduced). type family Mod (a :: Nat) (b :: Nat) :: Nat infixl 7 `Mod` -- | Log base 2 (round down) of natural numbers. Log 0 is -- undefined (i.e., it cannot be reduced). type family Log2 (a :: Nat) :: Nat -- | The type-level equivalent of error. -- -- The polymorphic kind of this type allows it to be used in several -- settings. For instance, it can be used as a constraint, e.g. to -- provide a better error message for a non-existent instance, -- --
-- -- in a context -- instance TypeError (Text "Cannot Show functions." :$$: -- Text "Perhaps there is a missing argument?") -- => Show (a -> b) where -- showsPrec = error "unreachable" ---- -- It can also be placed on the right-hand side of a type-level function -- to provide an error for an invalid case, -- --
-- type family ByteSize x where -- ByteSize Word16 = 2 -- ByteSize Word8 = 1 -- ByteSize a = TypeError (Text "The type " :<>: ShowType a :<>: -- Text " is not exportable.") --type family TypeError (a :: ErrorMessage) :: b -- | Coercible is a two-parameter class that has instances for -- types a and b if the compiler can infer that they -- have the same representation. This class does not have regular -- instances; instead they are created on-the-fly during type-checking. -- Trying to manually declare an instance of Coercible is an -- error. -- -- Nevertheless one can pretend that the following three kinds of -- instances exist. First, as a trivial base-case: -- --
-- instance Coercible a a ---- -- Furthermore, for every type constructor there is an instance that -- allows to coerce under the type constructor. For example, let -- D be a prototypical type constructor (data or -- newtype) with three type arguments, which have roles -- nominal, representational resp. phantom. -- Then there is an instance of the form -- --
-- instance Coercible b b' => Coercible (D a b c) (D a b' c') ---- -- Note that the nominal type arguments are equal, the -- representational type arguments can differ, but need to have -- a Coercible instance themself, and the phantom type -- arguments can be changed arbitrarily. -- -- The third kind of instance exists for every newtype NT = MkNT -- T and comes in two variants, namely -- --
-- instance Coercible a T => Coercible a NT ---- --
-- instance Coercible T b => Coercible NT b ---- -- This instance is only usable if the constructor MkNT is in -- scope. -- -- If, as a library author of a type constructor like Set a, you -- want to prevent a user of your module to write coerce :: Set T -- -> Set NT, you need to set the role of Set's type -- parameter to nominal, by writing -- --
-- type role Set nominal ---- -- For more details about this feature, please refer to Safe -- Coercions by Joachim Breitner, Richard A. Eisenberg, Simon Peyton -- Jones and Stephanie Weirich. class a ~R# b => Coercible (a :: k0) (b :: k0) -- | Concatenation of type-level symbols. type family AppendSymbol (a :: Symbol) (b :: Symbol) :: Symbol -- | A space-efficient representation of a Word8 vector, supporting -- many efficient operations. -- -- A ByteString contains 8-bit bytes, or by using the operations -- from Data.ByteString.Char8 it can be interpreted as containing -- 8-bit characters. data ByteString -- | An infix synonym for fmap. -- -- The name of this operator is an allusion to $. Note the -- similarities between their types: -- --
-- ($) :: (a -> b) -> a -> b -- (<$>) :: Functor f => (a -> b) -> f a -> f b ---- -- Whereas $ is function application, <$> is -- function application lifted over a Functor. -- --
-- >>> show <$> Nothing -- Nothing -- -- >>> show <$> Just 3 -- Just "3" ---- -- Convert from an Either Int Int to -- an Either Int String using -- show: -- --
-- >>> show <$> Left 17 -- Left 17 -- -- >>> show <$> Right 17 -- Right "17" ---- -- Double each element of a list: -- --
-- >>> (*2) <$> [1,2,3] -- [2,4,6] ---- -- Apply even to the second element of a pair: -- --
-- >>> even <$> (2,2) -- (2,True) --(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 <$> -- | The class of types that can be converted to a hash value. -- -- Minimal implementation: hashWithSalt. class Hashable a -- | Return a hash value for the argument, using the given salt. -- -- The general contract of hashWithSalt is: -- --
-- mzero >>= f = mzero -- v >> mzero = mzero ---- -- The default definition is -- --
-- mzero = empty --mzero :: MonadPlus m => m a -- | An associative operation. The default definition is -- --
-- mplus = (<|>) --mplus :: MonadPlus m => m a -> m a -> m a -- | nonEmpty efficiently turns a normal list into a NonEmpty -- stream, producing Nothing if the input is empty. nonEmpty :: () => [a] -> Maybe (NonEmpty a) -- | Direct MonadPlus equivalent of filter. -- --
-- filter = ( mfilter :: (a -> Bool) -> [a] -> [a] ) ---- -- An example using mfilter with the Maybe monad: -- --
-- >>> mfilter odd (Just 1) -- Just 1 -- >>> mfilter odd (Just 2) -- Nothing --mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a -- | Strict version of <$>. (<$!>) :: Monad m => (a -> b) -> m a -> m b infixl 4 <$!> -- | The reverse of when. unless :: Applicative f => Bool -> f () -> f () -- | Like replicateM, but discards the result. replicateM_ :: Applicative m => Int -> m a -> m () -- | replicateM n act performs the action n times, -- gathering the results. replicateM :: Applicative m => Int -> m a -> m [a] -- | Like foldM, but discards the result. foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () -- | The foldM function is analogous to foldl, except that -- its result is encapsulated in a monad. Note that foldM works -- from left-to-right over the list arguments. This could be an issue -- where (>>) and the `folded function' are not -- commutative. -- --
-- foldM f a1 [x1, x2, ..., xm] -- -- == -- -- do -- a2 <- f a1 x1 -- a3 <- f a2 x2 -- ... -- f am xm ---- -- If right-to-left evaluation is required, the input list should be -- reversed. -- -- Note: foldM is the same as foldlM foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b -- | zipWithM_ is the extension of zipWithM which ignores the -- final result. zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () -- | The zipWithM function generalizes zipWith to arbitrary -- applicative functors. zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] -- | The mapAndUnzipM function maps its first argument over a list, -- returning the result as a pair of lists. This function is mainly used -- with complicated data structures or a state-transforming monad. mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) -- | Repeat an action indefinitely. -- --
-- echoServer :: Socket -> IO () -- echoServer socket = forever $ do -- client <- accept socket -- forkFinally (echo client) (\_ -> hClose client) -- where -- echo :: Handle -> IO () -- echo client = forever $ -- hGetLine client >>= hPutStrLn client --forever :: Applicative f => f a -> f b -- | Right-to-left composition of Kleisli arrows. -- (>=>), with the arguments flipped. -- -- Note how this operator resembles function composition -- (.): -- --
-- (.) :: (b -> c) -> (a -> b) -> a -> c -- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c --(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c infixr 1 <=< -- | Left-to-right composition of Kleisli arrows. (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 >=> -- | This generalizes the list-based filter function. filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] -- | This function may be used as a value for foldMap in a -- Foldable instance. -- --
-- foldMapDefault f ≡ getConst . traverse (Const . f) --foldMapDefault :: (Traversable t, Monoid m) => (a -> m) -> t a -> m -- | This function may be used as a value for fmap in a -- Functor instance, provided that traverse is defined. -- (Using fmapDefault with a Traversable instance defined -- only by sequenceA will result in infinite recursion.) -- --
-- fmapDefault f ≡ runIdentity . traverse (Identity . f) --fmapDefault :: Traversable t => (a -> b) -> t a -> t b -- | The mapAccumR function behaves like a combination of -- fmap and foldr; it applies a function to each element -- of a structure, passing an accumulating parameter from right to left, -- and returning a final value of this accumulator together with the new -- structure. mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) -- | The mapAccumL function behaves like a combination of -- fmap and foldl; it applies a function to each element -- of a structure, passing an accumulating parameter from left to right, -- and returning a final value of this accumulator together with the new -- structure. mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) -- | forM is mapM with its arguments flipped. For a version -- that ignores the results see forM_. forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) -- | for is traverse with its arguments flipped. For a -- version that ignores the results see for_. for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) -- | One or none. optional :: Alternative f => f a -> f (Maybe a) newtype WrappedMonad (m :: Type -> Type) a WrapMonad :: m a -> WrappedMonad a [unwrapMonad] :: WrappedMonad a -> m a newtype WrappedArrow (a :: Type -> Type -> Type) b c WrapArrow :: a b c -> WrappedArrow b c [unwrapArrow] :: WrappedArrow b c -> a b c -- | Lists, but with an Applicative functor based on zipping. newtype ZipList a ZipList :: [a] -> ZipList a [getZipList] :: ZipList a -> [a] -- | Identity functor and monad. (a non-strict monad) newtype Identity a Identity :: a -> Identity a [runIdentity] :: Identity a -> a -- | The Const functor. newtype Const a (b :: k) :: forall k. () => Type -> k -> Type Const :: a -> Const a [getConst] :: Const a -> a -- | The find function takes a predicate and a structure and returns -- the leftmost element of the structure matching the predicate, or -- Nothing if there is no such element. find :: Foldable t => (a -> Bool) -> t a -> Maybe a -- | notElem is the negation of elem. notElem :: (Foldable t, Eq a) => a -> t a -> Bool infix 4 `notElem` -- | The least element of a non-empty structure with respect to the given -- comparison function. minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a -- | The largest element of a non-empty structure with respect to the given -- comparison function. maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a -- | Determines whether all elements of the structure satisfy the -- predicate. all :: Foldable t => (a -> Bool) -> t a -> Bool -- | Determines whether any element of the structure satisfies the -- predicate. any :: Foldable t => (a -> Bool) -> t a -> Bool -- | or returns the disjunction of a container of Bools. For the -- result to be False, the container must be finite; True, -- however, results from a True value finitely far from the left -- end. or :: Foldable t => t Bool -> Bool -- | and returns the conjunction of a container of Bools. For the -- result to be True, the container must be finite; False, -- however, results from a False value finitely far from the left -- end. and :: Foldable t => t Bool -> Bool -- | Map a function over all the elements of a container and concatenate -- the resulting lists. concatMap :: Foldable t => (a -> [b]) -> t a -> [b] -- | The concatenation of all the elements of a container of lists. concat :: Foldable t => t [a] -> [a] -- | The sum of a collection of actions, generalizing concat. As of -- base 4.8.0.0, msum is just asum, specialized to -- MonadPlus. msum :: (Foldable t, MonadPlus m) => t (m a) -> m a -- | The sum of a collection of actions, generalizing concat. -- -- asum [Just Hello, Nothing, Just World] Just Hello asum :: (Foldable t, Alternative f) => t (f a) -> f a -- | Evaluate each monadic action in the structure from left to right, and -- ignore the results. For a version that doesn't ignore the results see -- sequence. -- -- As of base 4.8.0.0, sequence_ is just sequenceA_, -- specialized to Monad. sequence_ :: (Foldable t, Monad m) => t (m a) -> m () -- | Evaluate each action in the structure from left to right, and ignore -- the results. For a version that doesn't ignore the results see -- sequenceA. sequenceA_ :: (Foldable t, Applicative f) => t (f a) -> f () -- | forM_ is mapM_ with its arguments flipped. For a version -- that doesn't ignore the results see forM. -- -- As of base 4.8.0.0, forM_ is just for_, specialized to -- Monad. forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m () -- | Map each element of a structure to a monadic action, evaluate these -- actions from left to right, and ignore the results. For a version that -- doesn't ignore the results see mapM. -- -- As of base 4.8.0.0, mapM_ is just traverse_, specialized -- to Monad. mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m () -- | for_ is traverse_ with its arguments flipped. For a -- version that doesn't ignore the results see for. -- --
-- >>> for_ [1..4] print -- 1 -- 2 -- 3 -- 4 --for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () -- | Map each element of a structure to an action, evaluate these actions -- from left to right, and ignore the results. For a version that doesn't -- ignore the results see traverse. traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f () -- | Monadic fold over the elements of a structure, associating to the -- left, i.e. from left to right. foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b -- | Monadic fold over the elements of a structure, associating to the -- right, i.e. from right to left. foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b -- | Get the precedence of a fixity value. prec :: Fixity -> Int -- | Datatype to represent the fixity of a constructor. An infix | -- declaration directly corresponds to an application of Infix. data Fixity Prefix :: Fixity Infix :: Associativity -> Int -> Fixity -- | This variant of Fixity appears at the type level. data FixityI PrefixI :: FixityI InfixI :: Associativity -> Nat -> FixityI -- | Datatype to represent the associativity of a constructor data Associativity LeftAssociative :: Associativity RightAssociative :: Associativity NotAssociative :: Associativity -- | The unpackedness of a field as the user wrote it in the source code. -- For example, in the following data type: -- --
-- data E = ExampleConstructor Int
-- {-# NOUNPACK #-} Int
-- {-# UNPACK #-} Int
--
--
-- The fields of ExampleConstructor have
-- NoSourceUnpackedness, SourceNoUnpack, and
-- SourceUnpack, respectively.
data SourceUnpackedness
NoSourceUnpackedness :: SourceUnpackedness
SourceNoUnpack :: SourceUnpackedness
SourceUnpack :: SourceUnpackedness
-- | The strictness of a field as the user wrote it in the source code. For
-- example, in the following data type:
--
-- -- data E = ExampleConstructor Int ~Int !Int ---- -- The fields of ExampleConstructor have -- NoSourceStrictness, SourceLazy, and SourceStrict, -- respectively. data SourceStrictness NoSourceStrictness :: SourceStrictness SourceLazy :: SourceStrictness SourceStrict :: SourceStrictness -- | The strictness that GHC infers for a field during compilation. Whereas -- there are nine different combinations of SourceUnpackedness and -- SourceStrictness, the strictness that GHC decides will -- ultimately be one of lazy, strict, or unpacked. What GHC decides is -- affected both by what the user writes in the source code and by GHC -- flags. As an example, consider this data type: -- --
-- data E = ExampleConstructor {-# UNPACK #-} !Int !Int Int
--
--
-- -- >>> sortOn fst [(2, "world"), (4, "!"), (1, "Hello")] -- [(1,"Hello"),(2,"world"),(4,"!")] --sortOn :: Ord b => (a -> b) -> [a] -> [a] -- | The sortBy function is the non-overloaded version of -- sort. -- --
-- >>> sortBy (\(a,_) (b,_) -> compare a b) [(2, "world"), (4, "!"), (1, "Hello")] -- [(1,"Hello"),(2,"world"),(4,"!")] --sortBy :: () => (a -> a -> Ordering) -> [a] -> [a] -- | The sort function implements a stable sorting algorithm. It is -- a special case of sortBy, which allows the programmer to supply -- their own comparison function. -- -- Elements are arranged from from lowest to highest, keeping duplicates -- in the order they appeared in the input. -- --
-- >>> sort [1,6,4,3,2,5] -- [1,2,3,4,5,6] --sort :: Ord a => [a] -> [a] -- | The partition function takes a predicate a list and returns the -- pair of lists of elements which do and do not satisfy the predicate, -- respectively; i.e., -- --
-- partition p xs == (filter p xs, filter (not . p) xs) ---- --
-- >>> partition (`elem` "aeiou") "Hello World!"
-- ("eoo","Hll Wrld!")
--
partition :: () => (a -> Bool) -> [a] -> ([a], [a])
-- | Return the contents of a Right-value or a default value
-- otherwise.
--
-- -- >>> fromRight 1 (Right 3) -- 3 -- -- >>> fromRight 1 (Left "foo") -- 1 --fromRight :: () => b -> Either a b -> b -- | Return the contents of a Left-value or a default value -- otherwise. -- --
-- >>> fromLeft 1 (Left 3) -- 3 -- -- >>> fromLeft 1 (Right "foo") -- 1 --fromLeft :: () => a -> Either a b -> a -- | Return True if the given value is a Right-value, -- False otherwise. -- --
-- >>> isRight (Left "foo") -- False -- -- >>> isRight (Right 3) -- True ---- -- Assuming a Left value signifies some sort of error, we can use -- isRight to write a very simple reporting function that only -- outputs "SUCCESS" when a computation has succeeded. -- -- This example shows how isRight might be used to avoid pattern -- matching when one does not care about the value contained in the -- constructor: -- --
-- >>> import Control.Monad ( when ) -- -- >>> let report e = when (isRight e) $ putStrLn "SUCCESS" -- -- >>> report (Left "parse error") -- -- >>> report (Right 1) -- SUCCESS --isRight :: () => Either a b -> Bool -- | Return True if the given value is a Left-value, -- False otherwise. -- --
-- >>> isLeft (Left "foo") -- True -- -- >>> isLeft (Right 3) -- False ---- -- Assuming a Left value signifies some sort of error, we can use -- isLeft to write a very simple error-reporting function that -- does absolutely nothing in the case of success, and outputs "ERROR" if -- any error occurred. -- -- This example shows how isLeft might be used to avoid pattern -- matching when one does not care about the value contained in the -- constructor: -- --
-- >>> import Control.Monad ( when ) -- -- >>> let report e = when (isLeft e) $ putStrLn "ERROR" -- -- >>> report (Right 1) -- -- >>> report (Left "parse error") -- ERROR --isLeft :: () => Either a b -> Bool -- | Partitions a list of Either into two lists. All the Left -- elements are extracted, in order, to the first component of the -- output. Similarly the Right elements are extracted to the -- second component of the output. -- --
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ] -- -- >>> partitionEithers list -- (["foo","bar","baz"],[3,7]) ---- -- The pair returned by partitionEithers x should be the -- same pair as (lefts x, rights x): -- --
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ] -- -- >>> partitionEithers list == (lefts list, rights list) -- True --partitionEithers :: () => [Either a b] -> ([a], [b]) -- | Extracts from a list of Either all the Right elements. -- All the Right elements are extracted in order. -- --
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ] -- -- >>> rights list -- [3,7] --rights :: () => [Either a b] -> [b] -- | Extracts from a list of Either all the Left elements. -- All the Left elements are extracted in order. -- --
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ] -- -- >>> lefts list -- ["foo","bar","baz"] --lefts :: () => [Either a b] -> [a] -- | Case analysis for the Either type. If the value is -- Left a, apply the first function to a; if it -- is Right b, apply the second function to b. -- --
-- >>> let s = Left "foo" :: Either String Int -- -- >>> let n = Right 3 :: Either String Int -- -- >>> either length (*2) s -- 3 -- -- >>> either length (*2) n -- 6 --either :: () => (a -> c) -> (b -> c) -> Either a b -> c -- | asProxyTypeOf is a type-restricted version of const. It -- is usually used as an infix operator, and its typing forces its first -- argument (which is usually overloaded) to have the same type as the -- tag of the second. -- --
-- >>> import Data.Word -- -- >>> :type asProxyTypeOf 123 (Proxy :: Proxy Word8) -- asProxyTypeOf 123 (Proxy :: Proxy Word8) :: Word8 ---- -- Note the lower-case proxy in the definition. This allows any -- type constructor with just one argument to be passed to the function, -- for example we could also write -- --
-- >>> import Data.Word -- -- >>> :type asProxyTypeOf 123 (Just (undefined :: Word8)) -- asProxyTypeOf 123 (Just (undefined :: Word8)) :: Word8 --asProxyTypeOf :: () => a -> proxy a -> a -- | Proxy is a type that holds no data, but has a phantom parameter -- of arbitrary type (or even kind). Its use is to provide type -- information, even though there is no value available of that type (or -- it may be too costly to create one). -- -- Historically, Proxy :: Proxy a is a safer -- alternative to the 'undefined :: a' idiom. -- --
-- >>> Proxy :: Proxy (Void, Int -> Int) -- Proxy ---- -- Proxy can even hold types of higher kinds, -- --
-- >>> Proxy :: Proxy Either -- Proxy ---- --
-- >>> Proxy :: Proxy Functor -- Proxy ---- --
-- >>> Proxy :: Proxy complicatedStructure -- Proxy --data Proxy (t :: k) :: forall k. () => k -> Type Proxy :: Proxy -- | A concrete, promotable proxy type, for use at the kind level There are -- no instances for this because it is intended at the kind level only data KProxy t KProxy :: KProxy t -- | & is a reverse application operator. This provides -- notational convenience. Its precedence is one higher than that of the -- forward application operator $, which allows & to be -- nested in $. -- --
-- >>> 5 & (+1) & show -- "6" --(&) :: () => a -> (a -> b) -> b infixl 1 & -- | on b u x y runs the binary function b -- on the results of applying unary function u to two -- arguments x and y. From the opposite perspective, it -- transforms two inputs and combines the outputs. -- --
-- ((+) `on` f) x y = f x + f y ---- -- Typical usage: sortBy (compare `on` -- fst). -- -- Algebraic properties: -- --
(*) `on` id = (*) -- (if (*) ∉ {⊥, const -- ⊥})
((*) `on` f) `on` g = (*) `on` (f . g)
flip on f . flip on g = flip on (g . -- f)
-- >>> let fac n = if n <= 1 then 1 else n * fac (n-1) in fac 5 -- 120 ---- -- This uses the fact that Haskell’s let introduces recursive -- bindings. We can rewrite this definition using fix, -- --
-- >>> fix (\rec n -> if n <= 1 then 1 else n * rec (n-1)) 5 -- 120 ---- -- Instead of making a recursive call, we introduce a dummy parameter -- rec; when used within fix, this parameter then refers -- to fix' argument, hence the recursion is reintroduced. fix :: () => (a -> a) -> a -- | void value discards or ignores the result of -- evaluation, such as the return value of an IO action. -- --
-- >>> void Nothing -- Nothing -- -- >>> void (Just 3) -- Just () ---- -- Replace the contents of an Either Int -- Int with unit, resulting in an Either -- Int '()': -- --
-- >>> void (Left 8675309) -- Left 8675309 -- -- >>> void (Right 8675309) -- Right () ---- -- Replace every element of a list with unit: -- --
-- >>> void [1,2,3] -- [(),(),()] ---- -- Replace the second element of a pair with unit: -- --
-- >>> void (1,2) -- (1,()) ---- -- Discard the result of an IO action: -- --
-- >>> mapM print [1,2] -- 1 -- 2 -- [(),()] -- -- >>> void $ mapM print [1,2] -- 1 -- 2 --void :: Functor f => f a -> f () -- | Flipped version of <$. -- --
-- >>> Nothing $> "foo" -- Nothing -- -- >>> Just 90210 $> "foo" -- Just "foo" ---- -- Replace the contents of an Either Int -- Int with a constant String, resulting in an -- Either Int String: -- --
-- >>> Left 8675309 $> "foo" -- Left 8675309 -- -- >>> Right 8675309 $> "foo" -- Right "foo" ---- -- Replace each element of a list with a constant String: -- --
-- >>> [1,2,3] $> "foo" -- ["foo","foo","foo"] ---- -- Replace the second element of a pair with a constant String: -- --
-- >>> (1,2) $> "foo" -- (1,"foo") --($>) :: Functor f => f a -> b -> f b infixl 4 $> -- | Flipped version of <$>. -- --
-- (<&>) = flip fmap ---- --
-- >>> Just 2 <&> (+1) -- Just 3 ---- --
-- >>> [1,2,3] <&> (+1) -- [2,3,4] ---- --
-- >>> Right 3 <&> (+1) -- Right 4 --(<&>) :: Functor f => f a -> (a -> b) -> f b infixl 1 <&> -- | The mapMaybe function is a version of map which can -- throw out elements. In particular, the functional argument returns -- something of type Maybe b. If this is Nothing, -- no element is added on to the result list. If it is Just -- b, then b is included in the result list. -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> let readMaybeInt = readMaybe :: String -> Maybe Int -- -- >>> mapMaybe readMaybeInt ["1", "Foo", "3"] -- [1,3] -- -- >>> catMaybes $ map readMaybeInt ["1", "Foo", "3"] -- [1,3] ---- -- If we map the Just constructor, the entire list should be -- returned: -- --
-- >>> mapMaybe Just [1,2,3] -- [1,2,3] --mapMaybe :: () => (a -> Maybe b) -> [a] -> [b] -- | The catMaybes function takes a list of Maybes and -- returns a list of all the Just values. -- --
-- >>> catMaybes [Just 1, Nothing, Just 3] -- [1,3] ---- -- When constructing a list of Maybe values, catMaybes can -- be used to return all of the "success" results (if the list is the -- result of a map, then mapMaybe would be more -- appropriate): -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ] -- [Just 1,Nothing,Just 3] -- -- >>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ] -- [1,3] --catMaybes :: () => [Maybe a] -> [a] -- | The listToMaybe function returns Nothing on an empty -- list or Just a where a is the first element -- of the list. -- --
-- >>> listToMaybe [] -- Nothing ---- --
-- >>> listToMaybe [9] -- Just 9 ---- --
-- >>> listToMaybe [1,2,3] -- Just 1 ---- -- Composing maybeToList with listToMaybe should be the -- identity on singleton/empty lists: -- --
-- >>> maybeToList $ listToMaybe [5] -- [5] -- -- >>> maybeToList $ listToMaybe [] -- [] ---- -- But not on lists with more than one element: -- --
-- >>> maybeToList $ listToMaybe [1,2,3] -- [1] --listToMaybe :: () => [a] -> Maybe a -- | The maybeToList function returns an empty list when given -- Nothing or a singleton list when not given Nothing. -- --
-- >>> maybeToList (Just 7) -- [7] ---- --
-- >>> maybeToList Nothing -- [] ---- -- One can use maybeToList to avoid pattern matching when combined -- with a function that (safely) works on lists: -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> sum $ maybeToList (readMaybe "3") -- 3 -- -- >>> sum $ maybeToList (readMaybe "") -- 0 --maybeToList :: () => Maybe a -> [a] -- | The fromMaybe function takes a default value and and -- Maybe value. If the Maybe is Nothing, it returns -- the default values; otherwise, it returns the value contained in the -- Maybe. -- --
-- >>> fromMaybe "" (Just "Hello, World!") -- "Hello, World!" ---- --
-- >>> fromMaybe "" Nothing -- "" ---- -- Read an integer from a string using readMaybe. If we fail to -- parse an integer, we want to return 0 by default: -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> fromMaybe 0 (readMaybe "5") -- 5 -- -- >>> fromMaybe 0 (readMaybe "") -- 0 --fromMaybe :: () => a -> Maybe a -> a -- | The fromJust function extracts the element out of a Just -- and throws an error if its argument is Nothing. -- --
-- >>> fromJust (Just 1) -- 1 ---- --
-- >>> 2 * (fromJust (Just 10)) -- 20 ---- --
-- >>> 2 * (fromJust Nothing) -- *** Exception: Maybe.fromJust: Nothing --fromJust :: () => Maybe a -> a -- | The isNothing function returns True iff its argument is -- Nothing. -- --
-- >>> isNothing (Just 3) -- False ---- --
-- >>> isNothing (Just ()) -- False ---- --
-- >>> isNothing Nothing -- True ---- -- Only the outer constructor is taken into consideration: -- --
-- >>> isNothing (Just Nothing) -- False --isNothing :: () => Maybe a -> Bool -- | The isJust function returns True iff its argument is of -- the form Just _. -- --
-- >>> isJust (Just 3) -- True ---- --
-- >>> isJust (Just ()) -- True ---- --
-- >>> isJust Nothing -- False ---- -- Only the outer constructor is taken into consideration: -- --
-- >>> isJust (Just Nothing) -- True --isJust :: () => Maybe a -> Bool -- | The maybe function takes a default value, a function, and a -- Maybe value. If the Maybe value is Nothing, the -- function returns the default value. Otherwise, it applies the function -- to the value inside the Just and returns the result. -- --
-- >>> maybe False odd (Just 3) -- True ---- --
-- >>> maybe False odd Nothing -- False ---- -- Read an integer from a string using readMaybe. If we succeed, -- return twice the integer; that is, apply (*2) to it. If -- instead we fail to parse an integer, return 0 by default: -- --
-- >>> import Text.Read ( readMaybe ) -- -- >>> maybe 0 (*2) (readMaybe "5") -- 10 -- -- >>> maybe 0 (*2) (readMaybe "") -- 0 ---- -- Apply show to a Maybe Int. If we have Just -- n, we want to show the underlying Int n. But if -- we have Nothing, we return the empty string instead of (for -- example) "Nothing": -- --
-- >>> maybe "" show (Just 5) -- "5" -- -- >>> maybe "" show Nothing -- "" --maybe :: () => b -> (a -> b) -> Maybe a -> b -- | Swap the components of a pair. swap :: () => (a, b) -> (b, a) -- | uncurry converts a curried function to a function on pairs. -- --
-- >>> uncurry (+) (1,2) -- 3 ---- --
-- >>> uncurry ($) (show, 1) -- "1" ---- --
-- >>> map (uncurry max) [(1,2), (3,4), (6,8)] -- [2,4,8] --uncurry :: () => (a -> b -> c) -> (a, b) -> c -- | curry converts an uncurried function to a curried function. -- --
-- >>> curry fst 1 2 -- 1 --curry :: () => ((a, b) -> c) -> a -> b -> c -- | flip f takes its (first) two arguments in the reverse -- order of f. -- --
-- >>> flip (++) "hello" "world" -- "worldhello" --flip :: () => (a -> b -> c) -> b -> a -> c -- | Function composition. (.) :: () => (b -> c) -> (a -> b) -> a -> c infixr 9 . -- | const x is a unary function which evaluates to x for -- all inputs. -- --
-- >>> const 42 "hello" -- 42 ---- --
-- >>> map (const 42) [0..3] -- [42,42,42,42] --const :: () => a -> b -> a -- | Identity function. -- --
-- id x = x --id :: () => a -> a -- | In many situations, the liftM operations can be replaced by -- uses of ap, which promotes function application. -- --
-- return f `ap` x1 `ap` ... `ap` xn ---- -- is equivalent to -- --
-- liftMn f x1 x2 ... xn --ap :: Monad m => m (a -> b) -> m a -> m b -- | Promote a function to a monad, scanning the monadic arguments from -- left to right (cf. liftM2). liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right (cf. liftM2). liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right (cf. liftM2). liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right. For example, -- --
-- liftM2 (+) [0,1] [0,2] = [0,2,1,3] -- liftM2 (+) (Just 1) Nothing = Nothing --liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r -- | Promote a function to a monad. liftM :: Monad m => (a1 -> r) -> m a1 -> m r -- | Conditional execution of Applicative expressions. For example, -- --
-- when debug (putStrLn "Debugging") ---- -- will output the string Debugging if the Boolean value -- debug is True, and otherwise do nothing. when :: Applicative f => Bool -> f () -> f () -- | Same as >>=, but with the arguments interchanged. (=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 =<< -- | Lift a ternary function to actions. liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d -- | Lift a function to actions. This function may be used as a value for -- fmap in a Functor instance. liftA :: Applicative f => (a -> b) -> f a -> f b -- | A variant of <*> with the arguments reversed. (<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 <**> -- | Non-empty (and non-strict) list type. data NonEmpty a (:|) :: a -> [a] -> NonEmpty a infixr 5 :| -- | A set of values a. data Set a -- | Converts a curried function to a function on a triple. uncurry3 :: () => (a -> b -> c -> d) -> (a, b, c) -> d -- | Converts an uncurried function to a curried function. curry3 :: () => ((a, b, c) -> d) -> a -> b -> c -> d -- | Extract the final element of a triple. thd3 :: () => (a, b, c) -> c -- | Extract the snd of a triple. snd3 :: () => (a, b, c) -> b -- | Extract the fst of a triple. fst3 :: () => (a, b, c) -> a -- | Apply a single function to both components of a pair. -- --
-- both succ (1,2) == (2,3) --both :: () => (a -> b) -> (a, a) -> (b, b) -- | Duplicate a single value into a pair. -- --
-- dupe 12 == (12, 12) --dupe :: () => a -> (a, a) -- | Given two functions, apply both to a single argument to form a pair. A -- specialised version of &&&. -- --
-- (succ &&& pred) 1 == (2,0) --(&&&) :: () => (a -> b) -> (a -> c) -> a -> (b, c) infixr 3 &&& -- | Given two functions, apply one to the first component and one to the -- second. A specialised version of ***. -- --
-- (succ *** reverse) (1,"test") == (2,"tset") --(***) :: () => (a -> a') -> (b -> b') -> (a, b) -> (a', b') infixr 3 *** -- | Update the second component of a pair. -- --
-- second reverse (1,"test") == (1,"tset") --second :: () => (b -> b') -> (a, b) -> (a, b') -- | Update the first component of a pair. -- --
-- first succ (1,"test") == (2,"test") --first :: () => (a -> a') -> (a, b) -> (a', b) -- | Is used within a monadic computation to begin exception processing. throwError :: MonadError e m => e -> m a findJustSafe :: (Monoid m, Foldable t) => (m -> Bool) -> t m -> m foldr1Safe :: (Monoid m, Foldable t) => (m -> m -> m) -> t m -> m foldl1Safe :: (Monoid m, Foldable t) => (m -> m -> m) -> t m -> m findJustNote :: (Partial, Foldable t) => String -> (a -> Bool) -> t a -> a findJustDef :: Foldable t => a -> (a -> Bool) -> t a -> a -- |
-- findJust op = fromJust . find op --findJust :: (Partial, Foldable t) => (a -> Bool) -> t a -> a maximumByNote :: (Partial, Foldable t) => String -> (a -> a -> Ordering) -> t a -> a minimumByNote :: (Partial, Foldable t) => String -> (a -> a -> Ordering) -> t a -> a maximumByDef :: Foldable t => a -> (a -> a -> Ordering) -> t a -> a minimumByDef :: Foldable t => a -> (a -> a -> Ordering) -> t a -> a maximumByMay :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a minimumByMay :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a maximumNote :: (Partial, Foldable t, Ord a) => String -> t a -> a minimumNote :: (Partial, Foldable t, Ord a) => String -> t a -> a maximumDef :: (Foldable t, Ord a) => a -> t a -> a minimumDef :: (Foldable t, Ord a) => a -> t a -> a maximumMay :: (Foldable t, Ord a) => t a -> Maybe a minimumMay :: (Foldable t, Ord a) => t a -> Maybe a foldr1Def :: Foldable t => a -> (a -> a -> a) -> t a -> a foldl1Def :: Foldable t => a -> (a -> a -> a) -> t a -> a foldr1Note :: (Partial, Foldable t) => String -> (a -> a -> a) -> t a -> a foldl1Note :: (Partial, Foldable t) => String -> (a -> a -> a) -> t a -> a foldr1May :: Foldable t => (a -> a -> a) -> t a -> Maybe a foldl1May :: Foldable t => (a -> a -> a) -> t a -> Maybe a -- | A set of values. A set cannot contain duplicate values. data HashSet a -- | Boxed vectors, supporting efficient slicing. data Vector a instance GHC.Classes.Ord a => GHC.Base.Semigroup (RON.Internal.Prelude.MaxOnFst a b) -- | Common types for binary format (parser and serializer) module RON.Binary.Types type Size = Word32 -- | Data block descriptor data Desc DOpRaw :: Desc DOpReduced :: Desc DOpHeader :: Desc DOpQueryHeader :: Desc DUuidType :: Desc DUuidObject :: Desc DUuidEvent :: Desc DUuidRef :: Desc DAtomUuidZip :: Desc DUuidZipObject :: Desc DUuidZipEvent :: Desc DUuidZipRef :: Desc DAtomUuid :: Desc DAtomInteger :: Desc DAtomString :: Desc DAtomFloat :: Desc -- | Does the descriptor refer to an op descIsOp :: Desc -> Bool instance GHC.Show.Show RON.Binary.Types.Desc instance GHC.Classes.Eq RON.Binary.Types.Desc instance GHC.Enum.Enum RON.Binary.Types.Desc module RON.Internal.Word data Word2 b00 :: Word2 b01 :: Word2 b10 :: Word2 b11 :: Word2 -- | Word2 smart constructor dropping upper bits leastSignificant2 :: Integral integral => integral -> Word2 data Word4 b0000 :: Word4 b0001 :: Word4 b0010 :: Word4 b0011 :: Word4 b0100 :: Word4 b0101 :: Word4 b0110 :: Word4 b0111 :: Word4 b1000 :: Word4 b1001 :: Word4 b1010 :: Word4 b1011 :: Word4 b1100 :: Word4 b1101 :: Word4 b1110 :: Word4 b1111 :: Word4 -- | Word4 smart constructor dropping upper bits leastSignificant4 :: Integral integral => integral -> Word4 newtype Word6 W6 :: Word8 -> Word6 -- | Word6 smart constructor dropping upper bits leastSignificant6 :: Integral integral => integral -> Word6 -- | leastSignificant6 specialized for Word8 ls6 :: Word8 -> Word6 -- | 8-bit unsigned integer type data Word8 data Word12 -- | Word12 smart constructor dropping upper bits leastSignificant12 :: Integral integral => integral -> Word12 -- | leastSignificant12 specialized for Word16 ls12 :: Word16 -> Word12 -- | 16-bit unsigned integer type data Word16 data Word24 -- | Word24 smart constructor dropping upper bits leastSignificant24 :: Integral integral => integral -> Word24 -- | leastSignificant24 specialized for Word32 ls24 :: Word32 -> Word24 -- | 32-bit unsigned integer type data Word32 data Word60 -- | Word60 smart constructor dropping upper bits leastSignificant60 :: Integral integral => integral -> Word60 -- | leastSignificant60 specialized for Word64 ls60 :: Word64 -> Word60 -- | Word60 smart constructor checking domain toWord60 :: Word64 -> Maybe Word60 word60add :: Word60 -> Word60 -> Word60 -- | 64-bit unsigned integer type data Word64 class SafeCast v w safeCast :: SafeCast v w => v -> w instance GHC.Show.Show RON.Internal.Word.Word60 instance GHC.Classes.Ord RON.Internal.Word.Word60 instance GHC.Classes.Eq RON.Internal.Word.Word60 instance GHC.Enum.Enum RON.Internal.Word.Word60 instance GHC.Show.Show RON.Internal.Word.Word24 instance GHC.Classes.Ord RON.Internal.Word.Word24 instance GHC.Classes.Eq RON.Internal.Word.Word24 instance GHC.Show.Show RON.Internal.Word.Word12 instance GHC.Classes.Ord RON.Internal.Word.Word12 instance GHC.Classes.Eq RON.Internal.Word.Word12 instance GHC.Show.Show RON.Internal.Word.Word6 instance GHC.Classes.Ord RON.Internal.Word.Word6 instance GHC.Classes.Eq RON.Internal.Word.Word6 instance GHC.Show.Show RON.Internal.Word.Word4 instance GHC.Classes.Ord RON.Internal.Word.Word4 instance GHC.Classes.Eq RON.Internal.Word.Word4 instance GHC.Show.Show RON.Internal.Word.Word2 instance GHC.Classes.Ord RON.Internal.Word.Word2 instance GHC.Classes.Eq RON.Internal.Word.Word2 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word2 GHC.Types.Int instance RON.Internal.Word.SafeCast RON.Internal.Word.Word2 RON.Internal.Word.Word4 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word2 GHC.Word.Word8 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word2 GHC.Word.Word64 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word4 GHC.Types.Int instance RON.Internal.Word.SafeCast RON.Internal.Word.Word4 GHC.Word.Word64 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word4 GHC.Word.Word8 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word6 GHC.Types.Int instance RON.Internal.Word.SafeCast RON.Internal.Word.Word6 GHC.Word.Word8 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word6 RON.Internal.Word.Word60 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word6 GHC.Word.Word64 instance RON.Internal.Word.SafeCast GHC.Word.Word8 GHC.Word.Word32 instance RON.Internal.Word.SafeCast GHC.Word.Word8 GHC.Word.Word64 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word12 GHC.Word.Word64 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word24 GHC.Word.Word64 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word24 GHC.Word.Word32 instance RON.Internal.Word.SafeCast RON.Internal.Word.Word60 GHC.Word.Word64 instance RON.Internal.Word.SafeCast GHC.Word.Word64 GHC.Integer.Type.Integer instance Data.Fixed.HasResolution e => RON.Internal.Word.SafeCast GHC.Word.Word64 (Data.Fixed.Fixed e) instance GHC.Enum.Bounded RON.Internal.Word.Word60 instance Data.Hashable.Class.Hashable RON.Internal.Word.Word60 -- | RON version of Base64 encoding module RON.Base64 -- | Base64 alphabet alphabet :: ByteString -- | Decode a blob from a Base64 string decode :: ByteStringL -> Maybe ByteStringL -- | Decode a 60-bit number from a Base64 string decode60 :: ByteString -> Maybe Word60 -- | Decode a 60-bit number from a Base32 string decode60base32 :: ByteString -> Maybe Word60 -- | Decode a 64-bit number from a Base64 string decode64 :: ByteString -> Maybe Word64 -- | Decode a 64-bit number from a Base32 string decode64base32 :: ByteString -> Maybe Word64 -- | Convert a Base64 letter to a number [0-63] decodeLetter :: Word8 -> Maybe Word6 -- | Convert a subset [0-F] of Base64 letters to a number [0-15] decodeLetter4 :: Word8 -> Maybe Word4 -- | Encode a blob to a Base64 string encode :: ByteStringL -> ByteStringL -- | Encode a 60-bit number to a Base64 string encode60 :: Word60 -> ByteString -- | Encode a 60-bit number to a Base64 string, dropping trailing zeroes encode60short :: Word60 -> ByteString -- | Encode a 64-bit number to a Base64 string encode64 :: Word64 -> ByteString -- | Encode a 64-bit number to a Base32 string, dropping trailing zeroes encode64base32short :: Word64 -> ByteString -- | Convert a number from [0..63] to a single letter encodeLetter :: Word6 -> Word8 -- | Convert a number from [0..15] to a single letter encodeLetter4 :: Word4 -> Word8 -- | Check if a character is in the Base64 alphabet. isLetter :: Word8 -> Bool module RON.Schema newtype Declaration DStructLww :: StructLww -> Declaration data Field Field :: RonType -> FieldAnnotations -> Field [fieldType] :: Field -> RonType [fieldAnnotations] :: Field -> FieldAnnotations data FieldAnnotations FieldAnnotations :: FieldAnnotations newtype OpaqueAnnotations OpaqueAnnotations :: Maybe Text -> OpaqueAnnotations [oaHaskellType] :: OpaqueAnnotations -> Maybe Text data RonType TAtom :: TAtom -> RonType TComposite :: TComposite -> RonType TObject :: TObject -> RonType TOpaque :: TOpaque -> RonType type Schema = [Declaration] data StructAnnotations StructAnnotations :: Set Text -> Text -> StructAnnotations [saHaskellDeriving] :: StructAnnotations -> Set Text [saHaskellFieldPrefix] :: StructAnnotations -> Text data StructLww StructLww :: Text -> Map Text Field -> StructAnnotations -> StructLww [structName] :: StructLww -> Text [structFields] :: StructLww -> Map Text Field [structAnnotations] :: StructLww -> StructAnnotations data TAtom TAInteger :: TAtom TAString :: TAtom newtype TComposite TOption :: RonType -> TComposite data TObject TORSet :: RonType -> TObject TRga :: RonType -> TObject TStructLww :: StructLww -> TObject TVersionVector :: TObject data TOpaque Opaque :: Bool -> OpaqueAnnotations -> TOpaque [opaqueIsObject] :: TOpaque -> Bool [opaqueAnnotations] :: TOpaque -> OpaqueAnnotations atomInteger :: RonType atomString :: RonType boole :: RonType char :: RonType -- | The default value for this type. def :: Default a => a field :: RonType -> Field opaqueAtoms :: OpaqueAnnotations -> RonType opaqueObject :: OpaqueAnnotations -> RonType option :: RonType -> RonType orSet :: RonType -> RonType rgaString :: RonType structLww :: StructLww -> RonType versionVector :: RonType instance GHC.Show.Show RON.Schema.TComposite instance GHC.Show.Show RON.Schema.Field instance GHC.Show.Show RON.Schema.StructLww instance GHC.Show.Show RON.Schema.TObject instance GHC.Show.Show RON.Schema.RonType instance GHC.Show.Show RON.Schema.TOpaque instance GHC.Show.Show RON.Schema.OpaqueAnnotations instance Data.Default.Class.Default RON.Schema.OpaqueAnnotations instance GHC.Show.Show RON.Schema.FieldAnnotations instance GHC.Show.Show RON.Schema.StructAnnotations instance GHC.Show.Show RON.Schema.TAtom instance Data.Default.Class.Default RON.Schema.FieldAnnotations instance Data.Default.Class.Default RON.Schema.StructAnnotations module RON.UUID -- | Universally unique identifier of anything data UUID UUID :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> UUID -- | UUID split in parts data UuidFields UuidFields :: !Word4 -> !Word60 -> !Word2 -> !Word2 -> !Word60 -> UuidFields [uuidVariety] :: UuidFields -> !Word4 [uuidValue] :: UuidFields -> !Word60 [uuidVariant] :: UuidFields -> !Word2 [uuidVersion] :: UuidFields -> !Word2 [uuidOrigin] :: UuidFields -> !Word60 -- | Build UUID from parts build :: UuidFields -> UUID -- | Build former 64 bits of UUID from parts buildX :: Word4 -> Word60 -> Word64 -- | Build latter 64 bits of UUID from parts buildY :: Word2 -> Word2 -> Word60 -> Word64 -- | Split UUID into parts split :: UUID -> UuidFields -- | Increment field uuidValue of a UUID succValue :: UUID -> UUID -- | UUID with all zero fields zero :: UUID -- | UUID with all zero fields -- | Convert UUID to a name getName :: UUID -> Maybe (ByteString, ByteString) -- | Make an unscoped (unqualified) name mkName :: Monad m => ByteString -> m UUID -- | Make a scoped (qualified) name mkScopedName :: Monad m => ByteString -> ByteString -> m UUID -- | Decode a UUID from a Base32 string decodeBase32 :: FilePath -> Maybe UUID -- | Encode a UUID to a Base32 string encodeBase32 :: UUID -> FilePath instance GHC.Show.Show RON.UUID.UuidFields instance GHC.Classes.Eq RON.UUID.UuidFields instance GHC.Classes.Ord RON.UUID.UUID instance Control.DeepSeq.NFData RON.UUID.UUID instance Data.Hashable.Class.Hashable RON.UUID.UUID instance GHC.Generics.Generic RON.UUID.UUID instance GHC.Classes.Eq RON.UUID.UUID instance Data.Data.Data RON.UUID.UUID instance GHC.Show.Show RON.UUID.UUID -- | RON model types module RON.Types -- | Atom — a payload element data Atom AFloat :: Double -> Atom AInteger :: Int64 -> Atom AString :: Text -> Atom AUuid :: UUID -> Atom -- | Reference to an object inside a frame. data Object a Object :: UUID -> StateFrame -> Object a [objectId] :: Object a -> UUID [objectFrame] :: Object a -> StateFrame -- | A pair of (type, object) type ObjectId = (UUID, UUID) -- | Specific field or item in an object, identified by UUID. data ObjectPart obj part ObjectPart :: UUID -> UUID -> StateFrame -> ObjectPart obj part [partObject] :: ObjectPart obj part -> UUID [partLocation] :: ObjectPart obj part -> UUID [partFrame] :: ObjectPart obj part -> StateFrame -- | “Reduced” op (op from reduced chunk) data Op Op :: UUID -> UUID -> [Atom] -> Op -- | event id (usually timestamp) [opEvent] :: Op -> UUID -- | reference to other op; actual semantics depends on the type [opRef] :: Op -> UUID -- | payload [opPayload] :: Op -> [Atom] -- | Op terminator data OpTerm TRaw :: OpTerm TReduced :: OpTerm THeader :: OpTerm TQuery :: OpTerm -- | Raw op data RawOp RawOp :: UUID -> UUID -> Op -> RawOp -- | type [opType] :: RawOp -> UUID -- | object id [opObject] :: RawOp -> UUID -- | other keys and payload, that are common with reduced op [op] :: RawOp -> Op -- | Reduced chunk representing an object state (i. e. high-level value) data StateChunk StateChunk :: UUID -> [Op] -> StateChunk [stateVersion] :: StateChunk -> UUID [stateBody] :: StateChunk -> [Op] -- | Frame containing only state chunks type StateFrame = Map ObjectId StateChunk -- | Universally unique identifier of anything data UUID UUID :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> UUID -- | Common chunk data WireChunk Raw :: RawOp -> WireChunk Value :: WireReducedChunk -> WireChunk Query :: WireReducedChunk -> WireChunk -- | Common frame type WireFrame = [WireChunk] -- | Common reduced chunk data WireReducedChunk WireReducedChunk :: RawOp -> [Op] -> WireReducedChunk [wrcHeader] :: WireReducedChunk -> RawOp [wrcBody] :: WireReducedChunk -> [Op] instance GHC.Show.Show (RON.Types.Object a) instance GHC.Classes.Eq (RON.Types.Object a) instance GHC.Show.Show RON.Types.StateChunk instance GHC.Classes.Eq RON.Types.StateChunk instance GHC.Show.Show RON.Types.OpTerm instance GHC.Classes.Eq RON.Types.OpTerm instance GHC.Show.Show RON.Types.WireChunk instance Control.DeepSeq.NFData RON.Types.WireChunk instance GHC.Generics.Generic RON.Types.WireChunk instance GHC.Classes.Eq RON.Types.WireChunk instance Data.Data.Data RON.Types.WireChunk instance GHC.Show.Show RON.Types.WireReducedChunk instance Control.DeepSeq.NFData RON.Types.WireReducedChunk instance GHC.Generics.Generic RON.Types.WireReducedChunk instance GHC.Classes.Eq RON.Types.WireReducedChunk instance Data.Data.Data RON.Types.WireReducedChunk instance Control.DeepSeq.NFData RON.Types.RawOp instance GHC.Generics.Generic RON.Types.RawOp instance GHC.Classes.Eq RON.Types.RawOp instance Data.Data.Data RON.Types.RawOp instance GHC.Show.Show RON.Types.Op instance Control.DeepSeq.NFData RON.Types.Op instance Data.Hashable.Class.Hashable RON.Types.Op instance GHC.Generics.Generic RON.Types.Op instance GHC.Classes.Eq RON.Types.Op instance Data.Data.Data RON.Types.Op instance GHC.Show.Show RON.Types.Atom instance Control.DeepSeq.NFData RON.Types.Atom instance Data.Hashable.Class.Hashable RON.Types.Atom instance GHC.Generics.Generic RON.Types.Atom instance GHC.Classes.Eq RON.Types.Atom instance Data.Data.Data RON.Types.Atom instance GHC.Show.Show RON.Types.RawOp -- | Binary serializer elements module RON.Binary.Serialize -- | Serialize a frame serialize :: WireFrame -> Either String ByteStringL -- | Serialize an Atom serializeAtom :: Atom -> Either String ByteStringL -- | Serialize a string atom serializeString :: Text -> ByteStringL -- | Binary parser elements module RON.Binary.Parse -- | Parse frame parse :: ByteStringL -> Either String WireFrame -- | Parse an Atom parseAtom :: ByteStringL -> Either String Atom -- | Parse a string atom parseString :: ByteStringL -> Either String Text -- | RON-Binary wire format module RON.Binary -- | Parse frame parse :: ByteStringL -> Either String WireFrame -- | Serialize a frame serialize :: WireFrame -> Either String ByteStringL module RON.Text.Serialize.UUID -- | Serialize UUID without context (used for test) serializeUuid :: UUID -> ByteStringL -- | Serialize UUID in op value (atom) context serializeUuidAtom :: UUID -> UUID -> ByteStringL -- | Serialize UUID in op key context serializeUuidKey :: UUID -> UUID -> UUID -> ByteStringL -- | RON-Text serialization module RON.Text.Serialize -- | Serialize a context-free atom serializeAtom :: Atom -> ByteStringL -- | Serialize an object. Return object id that must be stored separately. serializeObject :: Object a -> (UUID, ByteStringL) -- | Serialize a context-free raw op serializeRawOp :: RawOp -> ByteStringL -- | Serialize a state frame serializeStateFrame :: StateFrame -> ByteStringL -- | Serialize a string atom serializeString :: Text -> ByteStringL -- | Serialize UUID without context (used for test) serializeUuid :: UUID -> ByteStringL -- | Serialize a common frame serializeWireFrame :: WireFrame -> ByteStringL -- | Serialize a sequence of common frames serializeWireFrames :: [WireFrame] -> ByteStringL -- | RON-Text parsing module RON.Text.Parse -- | Parse an atom parseAtom :: ByteStringL -> Either String Atom -- | Parse a state frame as an object parseObject :: UUID -> ByteStringL -> Either String (Object a) -- | Parse a single context-free op parseOp :: ByteStringL -> Either String RawOp -- | Parse a state frame parseStateFrame :: ByteStringL -> Either String StateFrame -- | Parse a string atom parseString :: ByteStringL -> Either String Text -- | Parse a single context-free UUID parseUuid :: ByteStringL -> Either String UUID -- | Parse a UUID in key position parseUuidKey :: UUID -> UUID -> ByteStringL -> Either String UUID -- | Parse a UUID in value (atom) position parseUuidAtom :: UUID -> ByteStringL -> Either String UUID -- | Parse a common frame parseWireFrame :: ByteStringL -> Either String WireFrame -- | Parse a sequence of common frames parseWireFrames :: ByteStringL -> Either String [WireFrame] -- | RON-Text wire format module RON.Text -- | Parse a state frame as an object parseObject :: UUID -> ByteStringL -> Either String (Object a) -- | Parse a state frame parseStateFrame :: ByteStringL -> Either String StateFrame -- | Parse a common frame parseWireFrame :: ByteStringL -> Either String WireFrame -- | Parse a sequence of common frames parseWireFrames :: ByteStringL -> Either String [WireFrame] -- | Serialize an object. Return object id that must be stored separately. serializeObject :: Object a -> (UUID, ByteStringL) -- | Serialize a state frame serializeStateFrame :: StateFrame -> ByteStringL -- | Serialize a common frame serializeWireFrame :: WireFrame -> ByteStringL -- | Serialize a sequence of common frames serializeWireFrames :: [WireFrame] -> ByteStringL module RON.Event -- | Calendar format. See https://github.com/gritzko/ron/issues/19. -- Year range is 2010—2350. Precision is 100 ns. data CalendarTime CalendarTime :: Word12 -> Word6 -> Word6 -> Word6 -> Word6 -> Word24 -> CalendarTime [months] :: CalendarTime -> Word12 [days] :: CalendarTime -> Word6 [hours] :: CalendarTime -> Word6 [minutes] :: CalendarTime -> Word6 [seconds] :: CalendarTime -> Word6 [nanosecHundreds] :: CalendarTime -> Word24 -- | Calendar-based Lamport time event, specific case of Event. data CalendarEvent CalendarEvent :: !CalendarTime -> !ReplicaId -> CalendarEvent -- | Epoch-based Lamport time event, specific case of Event. data EpochEvent EpochEvent :: !EpochTime -> !ReplicaId -> EpochEvent -- | RFC 4122 epoch, hundreds of nanoseconds since 1582. Year range is -- 1582—5235. type EpochTime = Word60 -- | Generic Lamport time event. Cannot be Ord because we can't -- compare different types of clocks. If you want comparable events, use -- specific EpochEvent. data Event Event :: !LocalTime -> !ReplicaId -> Event -- | Clock type is encoded in 2 higher bits of variety, value in uuidValue data LocalTime TCalendar :: !CalendarTime -> LocalTime -- | https://en.wikipedia.org/wiki/Logical_clock TLogical :: !Word60 -> LocalTime TEpoch :: !EpochTime -> LocalTime TUnknown :: !Word60 -> LocalTime -- | Replica id assignment style data Naming TrieForked :: Naming CryptoForked :: Naming RecordForked :: Naming ApplicationSpecific :: Naming class Monad m => ReplicaClock m -- | Get current replica id getPid :: ReplicaClock m => m ReplicaId -- | Get sequential timestamps. -- -- Laws: -- --
t <- getEvents n (t !! i) == head t + i
t1 <- getEvent t2 <- getEvent t2 >= -- t1 + 1
getEvents 0 == getEvents 1
-- runNetworkSim $ do -- runReplicaSim r1 $ do -- actions... -- runReplicaSim r2 $ do -- actions... -- runReplicaSim r1 $ ... ---- -- Each runNetworkSim starts its own networks. One shouldn't use -- in one network events generated in another. runNetworkSim :: NetworkSim a -> a runNetworkSimT :: Monad m => NetworkSimT m a -> m a runReplicaSim :: ReplicaId -> ReplicaSim a -> NetworkSim a runReplicaSimT :: ReplicaId -> ReplicaSimT m a -> NetworkSimT m a instance GHC.Base.Monad m => GHC.Base.Monad (RON.Event.Simulation.ReplicaSimT m) instance GHC.Base.Functor m => GHC.Base.Functor (RON.Event.Simulation.ReplicaSimT m) instance GHC.Base.Monad m => GHC.Base.Applicative (RON.Event.Simulation.ReplicaSimT m) instance GHC.Base.Monad m => GHC.Base.Monad (RON.Event.Simulation.NetworkSimT m) instance GHC.Base.Functor m => GHC.Base.Functor (RON.Event.Simulation.NetworkSimT m) instance GHC.Base.Monad m => GHC.Base.Applicative (RON.Event.Simulation.NetworkSimT m) instance Control.Monad.Trans.Class.MonadTrans RON.Event.Simulation.ReplicaSimT instance GHC.Base.Monad m => RON.Event.ReplicaClock (RON.Event.Simulation.ReplicaSimT m) instance Control.Monad.Trans.Class.MonadTrans RON.Event.Simulation.NetworkSimT module RON.Epoch -- | Real epoch clock. Uses kind of global variable to ensure strict -- monotonicity. data EpochClock a -- | Get current time in EpochTime format (with 100 ns resolution). -- Monotonicity is not guaranteed. getCurrentEpochTime :: IO EpochTime -- | Convert unix time in hundreds of milliseconds to RFC 4122 time. localEpochTimeFromUnix :: Integral int => int -> LocalTime -- | Run EpochClock action with explicit time variable. runEpochClock :: ReplicaId -> IORef EpochTime -> EpochClock a -> IO a -- | Like runEpochClock, but initialize time variable with current -- wall time. runEpochClockFromCurrentTime :: ReplicaId -> EpochClock a -> IO a instance Control.Monad.IO.Class.MonadIO RON.Epoch.EpochClock instance GHC.Base.Monad RON.Epoch.EpochClock instance GHC.Base.Functor RON.Epoch.EpochClock instance GHC.Base.Applicative RON.Epoch.EpochClock instance RON.Event.ReplicaClock RON.Epoch.EpochClock module RON.Data.Internal -- | Reduce all chunks of specific type and object in the frame type WireReducer = UUID -> NonEmpty WireChunk -> [WireChunk] data Reducer Reducer :: WireReducer -> (StateChunk -> StateChunk -> StateChunk) -> Reducer [wireReducer] :: Reducer -> WireReducer [stateReducer] :: Reducer -> StateChunk -> StateChunk -> StateChunk -- | Unapplied patches and raw ops type Unapplied = ([ReducedChunk], [Op]) -- | Untyped-reducible types. Untyped means if this type is a container -- then the types of data contained in it is not considered. class (Eq a, Monoid a) => Reducible a -- | UUID of the type reducibleOpType :: Reducible a => UUID -- | Load a state from a state chunk stateFromChunk :: Reducible a => [Op] -> a -- | Store a state to a state chunk stateToChunk :: Reducible a => a -> StateChunk -- | Merge a state with patches and raw ops applyPatches :: Reducible a => a -> Unapplied -> (a, Unapplied) -- | Merge patches and raw ops into bigger patches or throw obsolete ops reduceUnappliedPatches :: Reducible a => Unapplied -> Unapplied data ReducedChunk ReducedChunk :: UUID -> UUID -> [Op] -> ReducedChunk [rcVersion] :: ReducedChunk -> UUID [rcRef] :: ReducedChunk -> UUID [rcBody] :: ReducedChunk -> [Op] mkChunkVersion :: [Op] -> UUID mkRC :: UUID -> [Op] -> ReducedChunk mkStateChunk :: [Op] -> StateChunk data Patch a Patch :: UUID -> a -> Patch a [patchRef] :: Patch a -> UUID [patchValue] :: Patch a -> a patchFromRawOp :: Reducible a => Op -> Patch a patchFromChunk :: Reducible a => ReducedChunk -> Patch a patchToChunk :: Reducible a => Patch a -> ReducedChunk -- | Base class for typed encoding class Replicated a -- | Instances SHOULD implement encoding either as -- objectEncoding or as payloadEncoding encoding :: Replicated a => Encoding a data Encoding a Encoding :: (forall m. ReplicaClock m => a -> WriterT StateFrame m [Atom]) -> ([Atom] -> StateFrame -> Either String a) -> Encoding a [encodingNewRon] :: Encoding a -> forall m. ReplicaClock m => a -> WriterT StateFrame m [Atom] [encodingFromRon] :: Encoding a -> [Atom] -> StateFrame -> Either String a -- | Encode typed data to a payload with possible addition objects newRon :: (Replicated a, ReplicaClock m) => a -> WriterT StateFrame m [Atom] -- | Decode typed data from a payload. The implementation may use other -- objects in the frame to resolve references. fromRon :: Replicated a => [Atom] -> StateFrame -> Either String a -- | Standard implementation of Replicated for -- ReplicatedAsObject types. objectEncoding :: ReplicatedAsObject a => Encoding a -- | Standard implementation of Replicated for -- ReplicatedAsPayload types. payloadEncoding :: ReplicatedAsPayload a => Encoding a -- | Instances of this class are encoded as payload only. class ReplicatedAsPayload a -- | Encode data toPayload :: ReplicatedAsPayload a => a -> [Atom] -- | Decode data fromPayload :: ReplicatedAsPayload a => [Atom] -> Either String a -- | Instances of this class are encoded as objects. An enclosing object's -- payload will be filled with this object's id. class ReplicatedAsObject a -- | UUID of the type objectOpType :: ReplicatedAsObject a => UUID -- | Encode data newObject :: (ReplicatedAsObject a, ReplicaClock m) => a -> m (Object a) -- | Decode data getObject :: ReplicatedAsObject a => Object a -> Either String a objectFromRon :: (Object a -> Either String a) -> [Atom] -> StateFrame -> Either String a -- | Helper to build an object frame using arbitrarily nested serializers. collectFrame :: Functor m => WriterT StateFrame m UUID -> m (Object a) getObjectStateChunk :: forall a. ReplicatedAsObject a => Object a -> Either String StateChunk eqRef :: Object a -> [Atom] -> Bool eqPayload :: ReplicatedAsPayload a => a -> [Atom] -> Bool instance GHC.Show.Show RON.Data.Internal.ReducedChunk instance RON.Data.Internal.ReplicatedAsPayload GHC.Int.Int64 instance RON.Data.Internal.ReplicatedAsPayload RON.UUID.UUID instance RON.Data.Internal.ReplicatedAsPayload Data.Text.Internal.Text instance RON.Data.Internal.ReplicatedAsPayload GHC.Types.Char instance RON.Data.Internal.ReplicatedAsPayload a => RON.Data.Internal.ReplicatedAsPayload (GHC.Maybe.Maybe a) instance RON.Data.Internal.ReplicatedAsPayload GHC.Types.Bool instance RON.Data.Internal.Replicated GHC.Int.Int64 instance RON.Data.Internal.Replicated RON.UUID.UUID instance RON.Data.Internal.Replicated Data.Text.Internal.Text instance RON.Data.Internal.Replicated GHC.Types.Char instance RON.Data.Internal.Replicated a => RON.Data.Internal.Replicated (GHC.Maybe.Maybe a) instance RON.Data.Internal.Replicated GHC.Types.Bool instance GHC.Base.Semigroup a => GHC.Base.Semigroup (RON.Data.Internal.Patch a) -- | Version Vector module RON.Data.VersionVector -- | Version Vector type. May be used both in typed and untyped contexts. data VersionVector instance GHC.Show.Show RON.Data.VersionVector.VersionVector instance GHC.Classes.Eq RON.Data.VersionVector.VersionVector instance Data.Hashable.Class.Hashable RON.Data.VersionVector.VersionVector instance GHC.Base.Semigroup RON.Data.VersionVector.VersionVector instance GHC.Base.Monoid RON.Data.VersionVector.VersionVector instance RON.Data.Internal.Reducible RON.Data.VersionVector.VersionVector instance RON.Data.Internal.Replicated RON.Data.VersionVector.VersionVector instance RON.Data.Internal.ReplicatedAsObject RON.Data.VersionVector.VersionVector -- | Replicated Growable Array (RGA) module RON.Data.RGA -- | Typed RGA newtype RGA a RGA :: [a] -> RGA a -- | Untyped RGA data RgaRaw -- | Speciaization of RGA to Char. This is the recommended -- way to store a string. type RgaString = RGA Char -- | Replace content of the RGA throug introducing changes detected by -- getGroupedDiffBy. edit :: (Replicated a, ReplicatedAsPayload a, ReplicaClock m, MonadError String m, MonadState (Object (RGA a)) m) => [a] -> m () -- | Speciaization of edit for ErrorMessage editText :: (ReplicaClock m, MonadError String m, MonadState (Object RgaString) m) => Text -> m () -- | Read elements from RGA getList :: Replicated a => Object (RGA a) -> Either String [a] -- | Read characters from RgaString getText :: Object RgaString -> Either String Text -- | Create an RGA from a list newFromList :: (Replicated a, ReplicaClock m) => [a] -> m (Object (RGA a)) -- | Create an RgaString from a text newFromText :: ReplicaClock m => Text -> m (Object RgaString) -- | Name-UUID to use as RGA type marker. rgaType :: UUID instance GHC.Classes.Eq a => GHC.Classes.Eq (RON.Data.RGA.RGA a) instance GHC.Show.Show RON.Data.RGA.PatchSet instance GHC.Classes.Eq RON.Data.RGA.PatchSet instance GHC.Show.Show RON.Data.RGA.RgaRaw instance GHC.Base.Semigroup RON.Data.RGA.RgaRaw instance GHC.Base.Monoid RON.Data.RGA.RgaRaw instance GHC.Classes.Eq RON.Data.RGA.RgaRaw instance GHC.Show.Show RON.Data.RGA.VertexList instance GHC.Classes.Eq RON.Data.RGA.VertexList instance GHC.Show.Show RON.Data.RGA.VertexListItem instance GHC.Classes.Eq RON.Data.RGA.VertexListItem instance RON.Data.Internal.Replicated a => RON.Data.Internal.Replicated (RON.Data.RGA.RGA a) instance RON.Data.Internal.Replicated a => RON.Data.Internal.ReplicatedAsObject (RON.Data.RGA.RGA a) instance GHC.Base.Semigroup RON.Data.RGA.PatchSet instance GHC.Base.Monoid RON.Data.RGA.PatchSet instance RON.Data.Internal.Reducible RON.Data.RGA.RgaRaw instance GHC.Base.Semigroup RON.Data.RGA.VertexList -- | Observed-Remove Set (OR-Set) module RON.Data.ORSet -- | Type-directing wrapper for typed OR-Set of atomic values newtype ORSet a ORSet :: [a] -> ORSet a -- | Type-directing wrapper for typed OR-Set of objects newtype ObjectORSet a ObjectORSet :: [a] -> ObjectORSet a -- | Untyped OR-Set. Implementation: a map from the last change (creation -- or deletion) to the original op. data ORSetRaw -- | Encode an object and add a reference to it to the OR-Set addNewRef :: forall a m. (ReplicatedAsObject a, ReplicaClock m, MonadError String m) => a -> StateT (Object (ObjectORSet a)) m () -- | Add a reference to the object to the OR-Set addRef :: (ReplicatedAsObject a, ReplicaClock m, MonadError String m) => Object a -> StateT (Object (ObjectORSet a)) m () -- | Add atomic value to the OR-Set addValue :: (ReplicatedAsPayload a, ReplicaClock m, MonadError String m) => a -> StateT (Object (ORSet a)) m () -- | Remove an object reference from the OR-Set removeRef :: Object a -> StateT (Object (ORSet a)) m () -- | Remove an atomic value from the OR-Set removeValue :: ReplicatedAsPayload a => a -> StateT (Object (ORSet a)) m () instance GHC.Show.Show RON.Data.ORSet.ORSetRaw instance GHC.Classes.Eq RON.Data.ORSet.ORSetRaw instance GHC.Show.Show RON.Data.ORSet.SetItem instance GHC.Classes.Eq RON.Data.ORSet.SetItem instance RON.Data.Internal.ReplicatedAsObject a => RON.Data.Internal.Replicated (RON.Data.ORSet.ObjectORSet a) instance RON.Data.Internal.ReplicatedAsObject a => RON.Data.Internal.ReplicatedAsObject (RON.Data.ORSet.ObjectORSet a) instance RON.Data.Internal.ReplicatedAsPayload a => RON.Data.Internal.Replicated (RON.Data.ORSet.ORSet a) instance RON.Data.Internal.ReplicatedAsPayload a => RON.Data.Internal.ReplicatedAsObject (RON.Data.ORSet.ORSet a) instance GHC.Base.Semigroup RON.Data.ORSet.ORSetRaw instance GHC.Base.Monoid RON.Data.ORSet.ORSetRaw instance RON.Data.Internal.Reducible RON.Data.ORSet.ORSetRaw instance GHC.Base.Semigroup RON.Data.ORSet.SetItem -- | LWW-per-field RDT module RON.Data.LWW -- | Untyped LWW. Implementation: a map from opRef to the original -- op. newtype LwwPerField LwwPerField :: Map UUID Op -> LwwPerField -- | Assign a value to a field assignField :: forall a b m. (ReplicatedAsObject a, Replicated b, ReplicaClock m, MonadError String m, MonadState (Object a) m) => UUID -> b -> m () -- | Name-UUID to use as LWW type marker. lwwType :: UUID -- | Create LWW object from a list of named fields. newObject :: ReplicaClock m => [(UUID, I Replicated)] -> m (Object a) -- | Decode field value readField :: (MonadError String m, MonadState (Object a) m, ReplicatedAsObject a, Replicated b) => UUID -> m b -- | Decode field value viewField :: Replicated a => UUID -> StateChunk -> StateFrame -> Either String a -- | Anti-lens to an object inside a specified field zoomField :: (ReplicatedAsObject outer, MonadError String m) => UUID -> StateT (Object inner) m a -> StateT (Object outer) m a instance GHC.Show.Show RON.Data.LWW.LwwPerField instance GHC.Base.Monoid RON.Data.LWW.LwwPerField instance GHC.Classes.Eq RON.Data.LWW.LwwPerField instance GHC.Base.Semigroup RON.Data.LWW.LwwPerField instance RON.Data.Internal.Reducible RON.Data.LWW.LwwPerField -- | Typed and untyped RON tools module RON.Data -- | Untyped-reducible types. Untyped means if this type is a container -- then the types of data contained in it is not considered. class (Eq a, Monoid a) => Reducible a -- | UUID of the type reducibleOpType :: Reducible a => UUID -- | Load a state from a state chunk stateFromChunk :: Reducible a => [Op] -> a -- | Store a state to a state chunk stateToChunk :: Reducible a => a -> StateChunk -- | Merge a state with patches and raw ops applyPatches :: Reducible a => a -> Unapplied -> (a, Unapplied) -- | Merge patches and raw ops into bigger patches or throw obsolete ops reduceUnappliedPatches :: Reducible a => Unapplied -> Unapplied -- | Base class for typed encoding class Replicated a -- | Instances SHOULD implement encoding either as -- objectEncoding or as payloadEncoding encoding :: Replicated a => Encoding a -- | Instances of this class are encoded as objects. An enclosing object's -- payload will be filled with this object's id. class ReplicatedAsObject a -- | UUID of the type objectOpType :: ReplicatedAsObject a => UUID -- | Encode data newObject :: (ReplicatedAsObject a, ReplicaClock m) => a -> m (Object a) -- | Decode data getObject :: ReplicatedAsObject a => Object a -> Either String a -- | Instances of this class are encoded as payload only. class ReplicatedAsPayload a -- | Encode data toPayload :: ReplicatedAsPayload a => a -> [Atom] -- | Decode data fromPayload :: ReplicatedAsPayload a => [Atom] -> Either String a -- | Decode typed data from a payload. The implementation may use other -- objects in the frame to resolve references. fromRon :: Replicated a => [Atom] -> StateFrame -> Either String a -- | Encode typed data to a payload with possible addition objects newRon :: (Replicated a, ReplicaClock m) => a -> WriterT StateFrame m [Atom] -- | Standard implementation of Replicated for -- ReplicatedAsObject types. objectEncoding :: ReplicatedAsObject a => Encoding a -- | Standard implementation of Replicated for -- ReplicatedAsPayload types. payloadEncoding :: ReplicatedAsPayload a => Encoding a -- | Reduce object with frame from another version of the same object. reduceObject :: Object a -> Object a -> Either String (Object a) reduceStateFrame :: StateFrame -> StateFrame -> Either String StateFrame reduceWireFrame :: WireFrame -> WireFrame -- | RON File Storage. For usage, see RON.Storage.IO. module RON.Storage -- | A type that intended to be put in a separate collection must define a -- Collection instance. class ReplicatedAsObject a => Collection a collectionName :: Collection a => CollectionName -- | Called when RON parser fails. fallbackParse :: Collection a => UUID -> ByteString -> Either String (Object a) -- | Collection (directory name) type CollectionName = FilePath -- | Document identifier (directory name), should be a RON-Base32-encoded -- RON-UUID. newtype DocId a DocId :: FilePath -> DocId a -- | Result of DB reading, loaded document with information about its -- versions data Document a Document :: Object a -> NonEmpty DocVersion -> IsTouched -> Document a -- | Merged value. [value] :: Document a -> Object a [versions] :: Document a -> NonEmpty DocVersion [isTouched] :: Document a -> IsTouched -- | Document version identifier (file name) type DocVersion = FilePath -- | Storage backend interface class (ReplicaClock m, MonadError String m) => MonadStorage m getCollections :: MonadStorage m => m [CollectionName] -- | Must return [] for non-existent collection getDocuments :: (MonadStorage m, Collection a) => m [DocId a] -- | Must return [] for non-existent document getDocumentVersions :: (MonadStorage m, Collection a) => DocId a -> m [DocVersion] -- | Must create collection and document if not exist saveVersionContent :: (MonadStorage m, Collection a) => DocId a -> DocVersion -> ByteString -> m () loadVersionContent :: (MonadStorage m, Collection a) => DocId a -> DocVersion -> m ByteString deleteVersion :: (MonadStorage m, Collection a) => DocId a -> DocVersion -> m () changeDocId :: (MonadStorage m, Collection a) => DocId a -> DocId a -> m () -- | Create document assuming it doesn't exist yet. createDocument :: (Collection a, MonadStorage m) => Object a -> m () -- | Create new version of an object/document. If the document doesn't -- exist yet, it will be created. createVersion :: forall a m. (Collection a, MonadStorage m) => Maybe (DocId a, Document a) -> Object a -> m () -- | Try decode UUID from a file name decodeDocId :: DocId a -> Maybe (Bool, UUID) -- | Load all versions of a document loadDocument :: (Collection a, MonadStorage m) => DocId a -> m (Document a) -- | Load document, apply changes and put it back to storage modify :: (Collection a, MonadStorage m) => DocId a -> StateT (Object a) m () -> m (Object a) -- | Load document version as an object readVersion :: MonadStorage m => Collection a => DocId a -> DocVersion -> m (Object a, IsTouched) instance GHC.Show.Show (RON.Storage.Document a) instance GHC.Show.Show RON.Storage.IsTouched instance RON.Storage.Collection a => GHC.Show.Show (RON.Storage.DocId a) module RON.Storage.Test type TestDB = Map CollectionName (Map DocumentId (Map DocVersion Document)) runStorageSim :: TestDB -> StorageSim a -> Either String (a, TestDB) instance RON.Event.ReplicaClock RON.Storage.Test.StorageSim instance Control.Monad.Error.Class.MonadError GHC.Base.String RON.Storage.Test.StorageSim instance GHC.Base.Monad RON.Storage.Test.StorageSim instance GHC.Base.Functor RON.Storage.Test.StorageSim instance GHC.Base.Applicative RON.Storage.Test.StorageSim instance RON.Storage.MonadStorage RON.Storage.Test.StorageSim -- | A real-world file storage. -- -- Typical usage: -- --
-- import RON.Storage.IO as Storage
--
-- main = do
-- let dataDir = "./data/"
-- h <- Storage.newHandle dataDir
-- runStorage h $ do
-- obj <- newObject Note{active = True, text = "Write an example"}
-- createDocument obj
--
module RON.Storage.IO
-- | Storage handle (uses the “Handle pattern”).
data Handle
-- | Environment is the dataDir
data Storage a
-- | Create new storage handle
newHandle :: FilePath -> IO Handle
-- | Run a Storage action
runStorage :: Handle -> Storage a -> IO a
instance Control.Monad.IO.Class.MonadIO RON.Storage.IO.Storage
instance Control.Monad.Error.Class.MonadError GHC.Base.String RON.Storage.IO.Storage
instance GHC.Base.Monad RON.Storage.IO.Storage
instance GHC.Base.Functor RON.Storage.IO.Storage
instance GHC.Base.Applicative RON.Storage.IO.Storage
instance RON.Event.ReplicaClock RON.Storage.IO.Storage
instance RON.Storage.MonadStorage RON.Storage.IO.Storage
module RON.Schema.TH
-- | Generate Haskell types from RON-Schema
mkReplicated :: Schema -> DecsQ
-- | Day instances
module RON.Data.Time
-- | The Modified Julian Day is a standard count of days, with zero being
-- the day 1858-11-17.
data Day
-- | RON-Schema type for Day
day :: RonType
instance RON.Data.Internal.Replicated Data.Time.Calendar.Days.Day
instance RON.Data.Internal.ReplicatedAsPayload Data.Time.Calendar.Days.Day