-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | RON -- -- Replicated Object Notation (RON), data types (RDT), and RON-Schema -- -- Examples: https://github.com/ff-notes/ron/tree/master/examples @package ron @version 0.10 module RON.Prelude -- | Append two lists, i.e., -- --
--   [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
--   [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
--   
-- -- If the first list is not finite, the result is the first list. (++) :: () => [a] -> [a] -> [a] infixr 5 ++ -- | filter, applied to a predicate and a list, returns the list of -- those elements that satisfy the predicate; i.e., -- --
--   filter p xs = [ x | x <- xs, p x]
--   
filter :: () => (a -> Bool) -> [a] -> [a] -- | zip takes two lists and returns a list of corresponding pairs. -- --
--   zip [1, 2] ['a', 'b'] = [(1, 'a'), (2, 'b')]
--   
-- -- If one input list is short, excess elements of the longer list are -- discarded: -- --
--   zip [1] ['a', 'b'] = [(1, 'a')]
--   zip [1, 2] ['a'] = [(1, 'a')]
--   
-- -- zip is right-lazy: -- --
--   zip [] _|_ = []
--   zip _|_ [] = _|_
--   
zip :: () => [a] -> [b] -> [(a, b)] -- | Extract the first component of a pair. fst :: () => (a, b) -> a -- | Extract the second component of a pair. snd :: () => (a, b) -> b -- | otherwise is defined as the value True. It helps to make -- guards more readable. eg. -- --
--   f x | x < 0     = ...
--       | otherwise = ...
--   
otherwise :: Bool -- | map f xs is the list obtained by applying f -- to each element of xs, i.e., -- --
--   map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
--   map f [x1, x2, ...] == [f x1, f x2, ...]
--   
map :: () => (a -> b) -> [a] -> [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 -- | general coercion from integral types fromIntegral :: (Integral a, Num b) => a -> b -- | general coercion to fractional types realToFrac :: (Real a, Fractional b) => a -> b -- | Conditional failure of Alternative computations. Defined by -- --
--   guard True  = pure ()
--   guard False = empty
--   
-- --

Examples

-- -- Common uses of guard include conditionally signaling an error -- in an error monad and conditionally rejecting the current choice in an -- Alternative-based parser. -- -- As an example of signaling an error in the error monad Maybe, -- consider a safe division function safeDiv x y that returns -- Nothing when the denominator y is zero and -- Just (x `div` y) otherwise. For example: -- --
--   >>> 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 Bounded class is used to name the upper and lower limits of -- a type. Ord is not a superclass of Bounded since types -- that are not totally ordered may also have upper and lower bounds. -- -- The Bounded class may be derived for any enumeration type; -- minBound is the first constructor listed in the data -- declaration and maxBound is the last. Bounded may also -- be derived for single-constructor datatypes whose constituent types -- are in Bounded. class Bounded a minBound :: Bounded a => a maxBound :: Bounded a => a -- | Class Enum defines operations on sequentially ordered types. -- -- The enumFrom... methods are used in Haskell's translation of -- arithmetic sequences. -- -- Instances of Enum may be derived for any enumeration type -- (types whose constructors have no fields). The nullary constructors -- are assumed to be numbered left-to-right by fromEnum from -- 0 through n-1. See Chapter 10 of the Haskell -- Report for more details. -- -- For any type that is an instance of class Bounded as well as -- Enum, the following should hold: -- -- -- --
--   enumFrom     x   = enumFromTo     x maxBound
--   enumFromThen x y = enumFromThenTo x y bound
--     where
--       bound | fromEnum y >= fromEnum x = maxBound
--             | otherwise                = minBound
--   
class Enum a -- | the successor of a value. For numeric types, succ adds 1. succ :: Enum a => a -> a -- | the predecessor of a value. For numeric types, pred subtracts -- 1. pred :: Enum a => a -> a -- | Convert from an Int. toEnum :: Enum a => Int -> a -- | Convert to an Int. It is implementation-dependent what -- fromEnum returns when applied to a value that is too large to -- fit in an Int. fromEnum :: Enum a => a -> Int -- | The Eq class defines equality (==) and inequality -- (/=). All the basic datatypes exported by the Prelude -- are instances of Eq, and Eq may be derived for any -- datatype whose constituents are also instances of Eq. -- -- The Haskell Report defines no laws for Eq. However, == -- is customarily expected to implement an equivalence relationship where -- two values comparing equal are indistinguishable by "public" -- functions, with a "public" function being one not allowing to see -- implementation details. For example, for a type representing -- non-normalised natural numbers modulo 100, a "public" function doesn't -- make the difference between 1 and 201. It is expected to have the -- following properties: -- -- -- -- Minimal complete definition: either == or /=. class Eq a (==) :: Eq a => a -> a -> Bool (/=) :: Eq a => a -> a -> Bool infix 4 == infix 4 /= -- | fractional division (/) :: Fractional a => a -> a -> a infixl 7 / -- | Integral numbers, supporting integer division. -- -- The Haskell Report defines no laws for Integral. However, -- Integral instances are customarily expected to define a -- Euclidean domain and have the following properties for the 'div'/'mod' -- and 'quot'/'rem' pairs, given suitable Euclidean functions f -- and g: -- -- -- -- An example of a suitable Euclidean function, for Integer's -- instance, is abs. class (Real a, Enum a) => Integral a -- | integer modulus, satisfying -- --
--   (x `div` y)*y + (x `mod` y) == x
--   
mod :: Integral a => a -> a -> a infixl 7 `mod` -- | 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 infixl 1 >>= infixl 1 >> -- | The Data class comprehends a fundamental primitive -- gfoldl for folding over constructor applications, say terms. -- This primitive can be instantiated in several ways to map over the -- immediate subterms of a term; see the gmap combinators later -- in this class. Indeed, a generic programmer does not necessarily need -- to use the ingenious gfoldl primitive but rather the intuitive -- gmap combinators. The gfoldl primitive is completed by -- means to query top-level constructors, to turn constructor -- representations into proper terms, and to list all possible datatype -- constructors. This completion allows us to serve generic programming -- scenarios like read, show, equality, term generation. -- -- The combinators gmapT, gmapQ, gmapM, etc are all -- provided with default definitions in terms of gfoldl, leaving -- open the opportunity to provide datatype-specific definitions. (The -- inclusion of the gmap combinators as members of class -- Data allows the programmer or the compiler to derive -- specialised, and maybe more efficient code per datatype. Note: -- gfoldl is more higher-order than the gmap combinators. -- This is subject to ongoing benchmarking experiments. It might turn out -- that the gmap combinators will be moved out of the class -- Data.) -- -- Conceptually, the definition of the gmap combinators in terms -- of the primitive gfoldl requires the identification of the -- gfoldl function arguments. Technically, we also need to -- identify the type constructor c for the construction of the -- result type from the folded term type. -- -- In the definition of gmapQx combinators, we use -- phantom type constructors for the c in the type of -- gfoldl because the result type of a query does not involve the -- (polymorphic) type of the term argument. In the definition of -- gmapQl we simply use the plain constant type constructor -- because gfoldl is left-associative anyway and so it is readily -- suited to fold a left-associative binary operation over the immediate -- subterms. In the definition of gmapQr, extra effort is needed. We use -- a higher-order accumulation trick to mediate between left-associative -- constructor application vs. right-associative binary operation (e.g., -- (:)). When the query is meant to compute a value of type -- r, then the result type withing generic folding is r -- -> r. So the result of folding is a function to which we -- finally pass the right unit. -- -- With the -XDeriveDataTypeable option, GHC can generate -- instances of the Data class automatically. For example, given -- the declaration -- --
--   data T a b = C1 a b | C2 deriving (Typeable, Data)
--   
-- -- GHC will generate an instance that is equivalent to -- --
--   instance (Data a, Data b) => Data (T a b) where
--       gfoldl k z (C1 a b) = z C1 `k` a `k` b
--       gfoldl k z C2       = z C2
--   
--       gunfold k z c = case constrIndex c of
--                           1 -> k (k (z C1))
--                           2 -> z C2
--   
--       toConstr (C1 _ _) = con_C1
--       toConstr C2       = con_C2
--   
--       dataTypeOf _ = ty_T
--   
--   con_C1 = mkConstr ty_T "C1" [] Prefix
--   con_C2 = mkConstr ty_T "C2" [] Prefix
--   ty_T   = mkDataType "Module.T" [con_C1, con_C2]
--   
-- -- This is suitable for datatypes that are exported transparently. class Typeable a => Data a -- | 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 <$ -- | Basic numeric class. -- -- The Haskell Report defines no laws for Num. However, '(+)' and -- '(*)' are customarily expected to define a ring and have the following -- properties: -- -- -- -- Note that it isn't customarily expected that a type instance of -- both Num and Ord implement an ordered ring. Indeed, in -- base only Integer and Rational do. class Num a (+) :: Num a => a -> a -> a (-) :: Num a => a -> a -> a (*) :: Num a => a -> a -> a -- | Unary negation. negate :: Num a => a -> a infixl 6 + infixl 7 * infixl 6 - -- | The Ord class is used for totally ordered datatypes. -- -- Instances of Ord can be derived for any user-defined datatype -- whose constituent types are in Ord. The declared order of the -- constructors in the data declaration determines the ordering in -- derived Ord instances. The Ordering datatype allows a -- single comparison to determine the precise ordering of two objects. -- -- The Haskell Report defines no laws for Ord. However, -- <= is customarily expected to implement a non-strict partial -- order and have the following properties: -- -- -- -- Note that the following operator interactions are expected to hold: -- --
    --
  1. x >= y = y <= x
  2. --
  3. x < y = x <= y && x /= y
  4. --
  5. x > y = y < x
  6. --
  7. x < y = compare x y == LT
  8. --
  9. x > y = compare x y == GT
  10. --
  11. x == y = compare x y == EQ
  12. --
  13. min x y == if x <= y then x else y = True
  14. --
  15. max x y == if x >= y then x else y = True
  16. --
-- -- Minimal complete definition: either compare or <=. -- Using compare can be more efficient for complex types. class Eq a => Ord a compare :: Ord a => a -> a -> Ordering (<) :: Ord a => a -> a -> Bool (<=) :: Ord a => a -> a -> Bool (>) :: Ord a => a -> a -> Bool (>=) :: Ord a => a -> a -> Bool max :: Ord a => a -> a -> a min :: Ord a => a -> a -> a infix 4 >= infix 4 > infix 4 < infix 4 <= -- | round x returns the nearest integer to x; the -- even integer if x is equidistant between two integers round :: (RealFrac a, Integral b) => a -> b -- | Conversion of values to readable Strings. -- -- Derived instances of Show have the following properties, which -- are compatible with derived instances of Read: -- -- -- -- For example, given the declarations -- --
--   infixr 5 :^:
--   data Tree a =  Leaf a  |  Tree a :^: Tree a
--   
-- -- the derived instance of Show is equivalent to -- --
--   instance (Show a) => Show (Tree a) where
--   
--          showsPrec d (Leaf m) = showParen (d > app_prec) $
--               showString "Leaf " . showsPrec (app_prec+1) m
--            where app_prec = 10
--   
--          showsPrec d (u :^: v) = showParen (d > up_prec) $
--               showsPrec (up_prec+1) u .
--               showString " :^: "      .
--               showsPrec (up_prec+1) v
--            where up_prec = 5
--   
-- -- Note that right-associativity of :^: is ignored. For example, -- -- class Show a -- | The class Typeable allows a concrete representation of a type -- to be calculated. class Typeable (a :: k) -- | When a value is bound in do-notation, the pattern on the left -- hand side of <- might not match. In this case, this class -- provides a function to recover. -- -- A Monad without a MonadFail instance may only be used in -- conjunction with pattern that always match, such as newtypes, tuples, -- data types with only a single data constructor, and irrefutable -- patterns (~pat). -- -- Instances of MonadFail should satisfy the following law: -- fail s should be a left zero for >>=, -- --
--   fail s >>= f  =  fail s
--   
-- -- If your Monad is also MonadPlus, a popular definition -- is -- --
--   fail _ = mzero
--   
class Monad m => MonadFail (m :: Type -> Type) fail :: MonadFail m => String -> m a -- | A functor with application, providing operations to -- -- -- -- A minimal complete definition must include implementations of -- pure and of either <*> or liftA2. If it -- defines both, then they must behave the same as their default -- definitions: -- --
--   (<*>) = liftA2 id
--   
-- --
--   liftA2 f x y = f <$> x <*> y
--   
-- -- Further, any definition must satisfy the following: -- -- -- -- The other methods have the following default definitions, which may be -- overridden with equivalent specialized implementations: -- -- -- -- As a consequence of these laws, the Functor instance for -- f will satisfy -- -- -- -- It may be useful to note that supposing -- --
--   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 -- | 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 -- | 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 infix 4 `elem` -- | Map each element of a structure to an action, evaluate these actions -- from left to right, and collect the results. For a version that -- ignores the results see traverse_. traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b) -- | Evaluate each action in the structure from left to right, and collect -- the results. For a version that ignores the results see -- sequenceA_. sequenceA :: (Traversable t, Applicative f) => t (f a) -> f (t a) -- | Evaluate each monadic action in the structure from left to right, and -- collect the results. For a version that ignores the results see -- sequence_. sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) -- | Representable types of kind *. This class is derivable in GHC -- with the DeriveGeneric flag on. -- -- A Generic instance must satisfy the following laws: -- --
--   from . toid
--   to . fromid
--   
class Generic a -- | The class of semigroups (types with an associative binary operation). -- -- Instances should satisfy the associativity law: -- -- class Semigroup a -- | An associative operation. (<>) :: Semigroup a => a -> a -> a -- | 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 infixr 6 <> -- | The class of monoids (types with an associative binary operation that -- has an identity). Instances should satisfy the following laws: -- -- -- -- The method names refer to the monoid of lists under concatenation, but -- there are many other instances. -- -- Some types can be viewed as a monoid in more than one way, e.g. both -- addition and multiplication on numbers. In such cases we often define -- newtypes and make those instances of Monoid, e.g. -- Sum and Product. -- -- NOTE: Semigroup is a superclass of Monoid since -- base-4.11.0.0. class Semigroup a => Monoid a -- | Identity of mappend mempty :: Monoid a => a data Bool False :: Bool True :: Bool -- | The character type Char is an enumeration whose values -- represent Unicode (or equivalently ISO/IEC 10646) code points (i.e. -- characters, see http://www.unicode.org/ for details). This set -- extends the ISO 8859-1 (Latin-1) character set (the first 256 -- characters), which is itself an extension of the ASCII character set -- (the first 128 characters). A character literal in Haskell has type -- Char. -- -- To convert a Char to or from the corresponding Int value -- defined by Unicode, use toEnum and fromEnum from the -- Enum class respectively (or equivalently ord and -- chr). data Char -- | Double-precision floating point numbers. It is desirable that this -- type be at least equal in range and precision to the IEEE -- double-precision type. data Double -- | A fixed-precision integer type with at least the range [-2^29 .. -- 2^29-1]. The exact range for a given implementation can be -- determined by using minBound and maxBound from the -- Bounded class. data Int -- | 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 -- | Invariant: Jn# and Jp# are used iff value doesn't fit in -- S# -- -- Useful properties resulting from the invariants: -- -- data Integer -- | 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 data Ordering LT :: Ordering EQ :: Ordering GT :: Ordering -- | A value of type IO a is a computation which, when -- performed, does some I/O before returning a value of type a. -- -- There is really only one way to "perform" an I/O action: bind it to -- Main.main in your program. When your program is run, the I/O -- will be performed. It isn't possible to perform I/O from an arbitrary -- function, unless that function is itself in the IO monad and -- called at some point, directly or indirectly, from Main.main. -- -- IO is a monad, so IO actions can be combined using -- either the do-notation or the >> and >>= -- operations from the Monad class. data IO a -- | A Word is an unsigned integral type, with the same size as -- Int. data Word -- | 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"). -- --

Examples

-- -- The type Either String Int is the type -- of values which can be either a String or an Int. The -- Left constructor can be used only on Strings, and the -- Right constructor can be used only on Ints: -- --
--   >>> 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 -- | 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) -- | 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. -- --

Examples

-- -- Convert from a Maybe Int to a -- Maybe String using show: -- --
--   >>> 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 -- | Like hashWithSalt, but no salt is used. The default -- implementation uses hashWithSalt with some default salt. -- Instances might want to implement this method to provide a more -- efficient implementation than the default implementation. hash :: Hashable a => a -> Int -- | A space efficient, packed, unboxed Unicode text type. data Text -- | 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 -- | Function composition. (.) :: () => (b -> c) -> (a -> b) -> a -> c infixr 9 . -- | Identity function. -- --
--   id x = x
--   
id :: () => a -> a -- | This is the simplest representation of UTC. It consists of the day -- number, and a time offset from midnight. Note that if a day has a leap -- second added to it, it will have 86401 seconds. data UTCTime -- | Convert a letter to the corresponding lower-case letter, if any. Any -- other character is returned unchanged. toLower :: Char -> Char -- | A map from keys to values. A map cannot contain duplicate keys; each -- key can map to at most one value. data HashMap k v -- | A Map from keys k to values a. data Map k a -- | A String is a list of characters. String constants in Haskell -- are values of type String. type String = [Char] -- | A monoid on applicative functors. -- -- If defined, some and many should be the least solutions -- of the equations: -- -- class Applicative f => Alternative (f :: Type -> Type) -- | An associative binary operation (<|>) :: Alternative f => f a -> f a -> f a -- | One or more. some :: Alternative f => f a -> f [a] -- | Zero or more. many :: Alternative f => f a -> f [a] infixl 3 <|> -- | Map over both arguments at the same time. -- --
--   bimap f g ≡ first f . second g
--   
-- --

Examples

-- --
--   >>> bimap toUpper (+1) ('j', 3)
--   ('J',4)
--   
-- --
--   >>> bimap toUpper (+1) (Left 'j')
--   Left 'J'
--   
-- --
--   >>> bimap toUpper (+1) (Right 3)
--   Right 4
--   
bimap :: Bifunctor p => (a -> b) -> (c -> d) -> p a c -> p b d -- | nonEmpty efficiently turns a normal list into a NonEmpty -- stream, producing Nothing if the input is empty. nonEmpty :: () => [a] -> Maybe (NonEmpty a) -- | Monads in which IO computations may be embedded. Any monad -- built by applying a sequence of monad transformers to the IO -- monad will be an instance of this class. -- -- Instances should satisfy the following laws, which state that -- liftIO is a transformer of monads: -- -- class Monad m => MonadIO (m :: Type -> Type) -- | Lift a computation from the IO monad. liftIO :: MonadIO m => IO a -> m a -- | The reverse of when. unless :: Applicative f => Bool -> f () -> f () -- | 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] -- | 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) -- | Identity functor and monad. (a non-strict monad) data Identity a -- | Strict version of atomicModifyIORef. This forces both the value -- stored in the IORef as well as the value returned. atomicModifyIORef' :: () => IORef a -> (a -> (a, b)) -> IO b -- | Write a new value into an IORef writeIORef :: () => IORef a -> a -> IO () -- | Read the value of an IORef readIORef :: () => IORef a -> IO a -- | Build a new IORef newIORef :: () => a -> IO (IORef a) -- | A mutable variable in the IO monad data IORef a -- | Evaluate the argument to weak head normal form. -- -- evaluate is typically used to uncover any exceptions that a -- lazy value may contain, and possibly handle them. -- -- evaluate only evaluates to weak head normal form. If -- deeper evaluation is needed, the force function from -- Control.DeepSeq may be handy: -- --
--   evaluate $ force x
--   
-- -- There is a subtle difference between evaluate x and -- return $! x, analogous to the difference -- between throwIO and throw. If the lazy value x -- throws an exception, return $! x will fail to -- return an IO action and will throw an exception instead. -- evaluate x, on the other hand, always produces an -- IO action; that action will throw an exception upon -- execution iff x throws an exception upon -- evaluation. -- -- The practical implication of this difference is that due to the -- imprecise exceptions semantics, -- --
--   (return $! error "foo") >> error "bar"
--   
-- -- may throw either "foo" or "bar", depending on the -- optimizations performed by the compiler. On the other hand, -- --
--   evaluate (error "foo") >> error "bar"
--   
-- -- is guaranteed to throw "foo". -- -- The rule of thumb is to use evaluate to force or handle -- exceptions in lazy values. If, on the other hand, you are forcing a -- lazy value for efficiency reasons only and do not care about -- exceptions, you may use return $! x. evaluate :: () => a -> IO a -- | A variant of throw that can only be used within the IO -- monad. -- -- Although throwIO has a type that is an instance of the type of -- throw, the two functions are subtly different: -- --
--   throw e   `seq` x  ===> throw e
--   throwIO e `seq` x  ===> x
--   
-- -- The first example will cause the exception e to be raised, -- whereas the second one won't. In fact, throwIO will only cause -- an exception to be raised when it is used within the IO monad. -- The throwIO variant should be used in preference to -- throw to raise an exception within the IO monad because -- it guarantees ordering with respect to other IO operations, -- whereas throw does not. throwIO :: Exception e => e -> IO a -- | This is the simplest of the exception-catching functions. It takes a -- single argument, runs it, and if an exception is raised the "handler" -- is executed, with the value of the exception passed as an argument. -- Otherwise, the result is returned as normal. For example: -- --
--   catch (readFile f)
--         (\e -> do let err = show (e :: IOException)
--                   hPutStr stderr ("Warning: Couldn't open " ++ f ++ ": " ++ err)
--                   return "")
--   
-- -- Note that we have to give a type signature to e, or the -- program will not typecheck as the type is ambiguous. While it is -- possible to catch exceptions of any type, see the section "Catching -- all exceptions" (in Control.Exception) for an explanation of -- the problems with doing so. -- -- For catching exceptions in pure (non-IO) expressions, see the -- function evaluate. -- -- Note that due to Haskell's unspecified evaluation order, an expression -- may throw one of several possible exceptions: consider the expression -- (error "urk") + (1 `div` 0). Does the expression throw -- ErrorCall "urk", or DivideByZero? -- -- The answer is "it might throw either"; the choice is -- non-deterministic. If you are catching any type of exception then you -- might catch either. If you are calling catch with type IO -- Int -> (ArithException -> IO Int) -> IO Int then the -- handler may get run with DivideByZero as an argument, or an -- ErrorCall "urk" exception may be propogated further up. If -- you call it again, you might get a the opposite behaviour. This is ok, -- because catch is an IO computation. catch :: Exception e => IO a -> (e -> IO a) -> IO a -- | File and directory names are values of type String, whose -- precise meaning is operating system dependent. Files can be opened, -- yielding a handle which can then be used to operate on the contents of -- that file. type FilePath = String -- | Any type that you wish to throw or catch as an exception must be an -- instance of the Exception class. The simplest case is a new -- exception type directly below the root: -- --
--   data MyException = ThisException | ThatException
--       deriving Show
--   
--   instance Exception MyException
--   
-- -- The default method definitions in the Exception class do what -- we need in this case. You can now throw and catch -- ThisException and ThatException as exceptions: -- --
--   *Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
--   Caught ThisException
--   
-- -- In more complicated examples, you may wish to define a whole hierarchy -- of exceptions: -- --
--   ---------------------------------------------------------------------
--   -- Make the root exception type for all the exceptions in a compiler
--   
--   data SomeCompilerException = forall e . Exception e => SomeCompilerException e
--   
--   instance Show SomeCompilerException where
--       show (SomeCompilerException e) = show e
--   
--   instance Exception SomeCompilerException
--   
--   compilerExceptionToException :: Exception e => e -> SomeException
--   compilerExceptionToException = toException . SomeCompilerException
--   
--   compilerExceptionFromException :: Exception e => SomeException -> Maybe e
--   compilerExceptionFromException x = do
--       SomeCompilerException a <- fromException x
--       cast a
--   
--   ---------------------------------------------------------------------
--   -- Make a subhierarchy for exceptions in the frontend of the compiler
--   
--   data SomeFrontendException = forall e . Exception e => SomeFrontendException e
--   
--   instance Show SomeFrontendException where
--       show (SomeFrontendException e) = show e
--   
--   instance Exception SomeFrontendException where
--       toException = compilerExceptionToException
--       fromException = compilerExceptionFromException
--   
--   frontendExceptionToException :: Exception e => e -> SomeException
--   frontendExceptionToException = toException . SomeFrontendException
--   
--   frontendExceptionFromException :: Exception e => SomeException -> Maybe e
--   frontendExceptionFromException x = do
--       SomeFrontendException a <- fromException x
--       cast a
--   
--   ---------------------------------------------------------------------
--   -- Make an exception type for a particular frontend compiler exception
--   
--   data MismatchedParentheses = MismatchedParentheses
--       deriving Show
--   
--   instance Exception MismatchedParentheses where
--       toException   = frontendExceptionToException
--       fromException = frontendExceptionFromException
--   
-- -- We can now catch a MismatchedParentheses exception as -- MismatchedParentheses, SomeFrontendException or -- SomeCompilerException, but not other types, e.g. -- IOException: -- --
--   *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
--   Caught MismatchedParentheses
--   *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
--   Caught MismatchedParentheses
--   *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
--   Caught MismatchedParentheses
--   *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException))
--   *** Exception: MismatchedParentheses
--   
class (Typeable e, Show e) => Exception e -- | 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 -- | 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 -- | 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 () -- | Maybe monoid returning the rightmost non-Nothing value. -- -- Last a is isomorphic to Dual (First -- a), and thus to Dual (Alt Maybe a) -- --
--   >>> getLast (Last (Just "hello") <> Last Nothing <> Last (Just "world"))
--   Just "world"
--   
-- -- Use of this type is discouraged. Note the following equivalence: -- --
--   Data.Monoid.Last x === Maybe (Data.Semigroup.Last x)
--   
-- -- In addition to being equivalent in the structural sense, the two also -- have Monoid instances that behave the same. This type will be -- marked deprecated in GHC 8.8, and removed in GHC 8.10. Users are -- advised to use the variant from Data.Semigroup and wrap it in -- Maybe. newtype Last a Last :: Maybe a -> Last a -- | unwords is an inverse operation to words. It joins words -- with separating spaces. -- --
--   >>> unwords ["Lorem", "ipsum", "dolor"]
--   "Lorem ipsum dolor"
--   
unwords :: [String] -> String -- | unlines is an inverse operation to lines. It joins -- lines, after appending a terminating newline to each. -- --
--   >>> unlines ["Hello", "World", "!"]
--   "Hello\nWorld\n!\n"
--   
unlines :: [String] -> String -- | Sort a list by comparing the results of a key function applied to each -- element. sortOn f is equivalent to sortBy (comparing -- f), but has the performance advantage of only evaluating -- f once for each element in the input list. This is called the -- decorate-sort-undecorate paradigm, or Schwartzian transform. -- -- Elements are arranged from from lowest to highest, keeping duplicates -- in the order they appeared in the input. -- --
--   >>> 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 genericLength function is an overloaded version of -- length. In particular, instead of returning an Int, it -- returns any type which is an instance of Num. It is, however, -- less efficient than length. genericLength :: Num i => [a] -> i -- | 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]) -- | intercalate xs xss is equivalent to (concat -- (intersperse xs xss)). It inserts the list xs in -- between the lists in xss and concatenates the result. -- --
--   >>> intercalate ", " ["Lorem", "ipsum", "dolor"]
--   "Lorem, ipsum, dolor"
--   
intercalate :: () => [a] -> [[a]] -> [a] -- | The isSuffixOf function takes two lists and returns True -- iff the first list is a suffix of the second. The second list must be -- finite. -- --
--   >>> "ld!" `isSuffixOf` "Hello World!"
--   True
--   
-- --
--   >>> "World" `isSuffixOf` "Hello World!"
--   False
--   
isSuffixOf :: Eq a => [a] -> [a] -> Bool -- | The isPrefixOf function takes two lists and returns True -- iff the first list is a prefix of the second. -- --
--   >>> "Hello" `isPrefixOf` "Hello World!"
--   True
--   
-- --
--   >>> "Hello" `isPrefixOf` "Wello Horld!"
--   False
--   
isPrefixOf :: Eq a => [a] -> [a] -> Bool -- | Parse a string using the Read instance. Succeeds if there is -- exactly one valid result. -- --
--   >>> readMaybe "123" :: Maybe Int
--   Just 123
--   
-- --
--   >>> readMaybe "hello" :: Maybe Int
--   Nothing
--   
readMaybe :: Read a => String -> Maybe 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. -- --

Examples

-- -- We create two values of type Either String -- Int, one using the Left constructor and another -- using the Right constructor. Then we apply "either" the -- length function (if we have a String) or the -- "times-two" function (if we have an Int): -- --
--   >>> 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 -- |
--   comparing p x y = compare (p x) (p y)
--   
-- -- Useful combinator for use in conjunction with the xxxBy -- family of functions from Data.List, for example: -- --
--   ... sortBy (comparing fst) ...
--   
comparing :: Ord a => (b -> a) -> b -> b -> Ordering -- | The Down type allows you to reverse sort order conveniently. A -- value of type Down a contains a value of type -- a (represented as Down a). If a has -- an Ord instance associated with it then comparing two -- values thus wrapped will give you the opposite of their normal sort -- order. This is particularly useful when sorting in generalised list -- comprehensions, as in: then sortWith by Down x newtype Down a Down :: a -> Down 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 -- | Convert a letter to the corresponding upper-case letter, if any. Any -- other character is returned unchanged. toUpper :: Char -> Char -- | & 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 :: () => (b -> b -> c) -> (a -> b) -> a -> a -> c infixl 0 `on` -- | void value discards or ignores the result of -- evaluation, such as the return value of an IO action. -- --

Examples

-- -- Replace the contents of a Maybe Int with -- unit: -- --
--   >>> 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 <$. -- --

Examples

-- -- Replace the contents of a Maybe Int with a -- constant String: -- --
--   >>> 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
--   
-- --

Examples

-- -- Apply (+1) to a list, a Just and a Right: -- --
--   >>> 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 <&> -- | raise a number to an integral power (^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 ^^ -- | raise a number to a non-negative integral power (^) :: (Num a, Integral b) => a -> b -> a infixr 8 ^ -- | Forms the ratio of two integral numbers. (%) :: Integral a => a -> a -> Ratio a infixl 7 % -- | The toEnum method restricted to the type Char. chr :: Int -> Char -- | zipWith generalises zip by zipping with the function -- given as the first argument, instead of a tupling function. For -- example, zipWith (+) is applied to two lists to -- produce the list of corresponding sums. -- -- zipWith is right-lazy: -- --
--   zipWith f [] _|_ = []
--   
zipWith :: () => (a -> b -> c) -> [a] -> [b] -> [c] -- | lookup key assocs looks up a key in an association -- list. lookup :: Eq a => a -> [(a, b)] -> Maybe b -- | span, applied to a predicate p and a list xs, -- returns a tuple where first element is longest prefix (possibly empty) -- of xs of elements that satisfy p and second element -- is the remainder of the list: -- --
--   span (< 3) [1,2,3,4,1,2,3,4] == ([1,2],[3,4,1,2,3,4])
--   span (< 9) [1,2,3] == ([1,2,3],[])
--   span (< 0) [1,2,3] == ([],[1,2,3])
--   
-- -- span p xs is equivalent to (takeWhile p xs, -- dropWhile p xs) span :: () => (a -> Bool) -> [a] -> ([a], [a]) -- | splitAt n xs returns a tuple where first element is -- xs prefix of length n and second element is the -- remainder of the list: -- --
--   splitAt 6 "Hello World!" == ("Hello ","World!")
--   splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5])
--   splitAt 1 [1,2,3] == ([1],[2,3])
--   splitAt 3 [1,2,3] == ([1,2,3],[])
--   splitAt 4 [1,2,3] == ([1,2,3],[])
--   splitAt 0 [1,2,3] == ([],[1,2,3])
--   splitAt (-1) [1,2,3] == ([],[1,2,3])
--   
-- -- It is equivalent to (take n xs, drop n xs) when -- n is not _|_ (splitAt _|_ xs = _|_). -- splitAt is an instance of the more general -- genericSplitAt, in which n may be of any integral -- type. splitAt :: () => Int -> [a] -> ([a], [a]) -- | drop n xs returns the suffix of xs after the -- first n elements, or [] if n > length -- xs: -- --
--   drop 6 "Hello World!" == "World!"
--   drop 3 [1,2,3,4,5] == [4,5]
--   drop 3 [1,2] == []
--   drop 3 [] == []
--   drop (-1) [1,2] == [1,2]
--   drop 0 [1,2] == [1,2]
--   
-- -- It is an instance of the more general genericDrop, in which -- n may be of any integral type. drop :: () => Int -> [a] -> [a] -- | take n, applied to a list xs, returns the -- prefix of xs of length n, or xs itself if -- n > length xs: -- --
--   take 5 "Hello World!" == "Hello"
--   take 3 [1,2,3,4,5] == [1,2,3]
--   take 3 [1,2] == [1,2]
--   take 3 [] == []
--   take (-1) [1,2] == []
--   take 0 [1,2] == []
--   
-- -- It is an instance of the more general genericTake, in which -- n may be of any integral type. take :: () => Int -> [a] -> [a] -- | takeWhile, applied to a predicate p and a list -- xs, returns the longest prefix (possibly empty) of -- xs of elements that satisfy p: -- --
--   takeWhile (< 3) [1,2,3,4,1,2,3,4] == [1,2]
--   takeWhile (< 9) [1,2,3] == [1,2,3]
--   takeWhile (< 0) [1,2,3] == []
--   
takeWhile :: () => (a -> Bool) -> [a] -> [a] -- | replicate n x is a list of length n with -- x the value of every element. It is an instance of the more -- general genericReplicate, in which n may be of any -- integral type. replicate :: () => Int -> a -> [a] -- | repeat x is an infinite list, with x the -- value of every element. repeat :: () => a -> [a] -- | 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. -- --

Examples

-- -- Using mapMaybe f x is a shortcut for -- catMaybes $ map f x in most cases: -- --
--   >>> 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. -- --

Examples

-- -- Basic usage: -- --
--   >>> 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. -- --

Examples

-- -- Basic usage: -- --
--   >>> 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. -- --

Examples

-- -- Basic usage: -- --
--   >>> 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. -- --

Examples

-- -- Basic usage: -- --
--   >>> 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 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. -- --

Examples

-- -- Basic usage: -- --
--   >>> 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 -- | uncurry converts a curried function to a function on pairs. -- --

Examples

-- --
--   >>> 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 -- | the same as flip (-). -- -- Because - is treated specially in the Haskell grammar, -- (- e) is not a section, but an application of -- prefix negation. However, (subtract -- exp) is equivalent to the disallowed section. subtract :: Num a => a -> a -> a -- | flip f takes its (first) two arguments in the reverse -- order of f. -- --
--   >>> flip (++) "hello" "world"
--   "worldhello"
--   
flip :: () => (a -> b -> c) -> b -> a -> c -- | The fromEnum method restricted to the type Char. ord :: Char -> Int -- | 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 =<< -- | Non-empty (and non-strict) list type. data NonEmpty a (:|) :: a -> [a] -> NonEmpty a infixr 5 :| -- | A special case of error. It is expected that compilers will -- recognize this and insert error messages which are more appropriate to -- the context in which undefined appears. undefined :: HasCallStack => a -- | error stops execution and displays an error message. error :: HasCallStack => [Char] -> a -- | Request a CallStack. -- -- NOTE: The implicit parameter ?callStack :: CallStack is an -- implementation detail and should not be considered part of the -- CallStack API, we may decide to change the implementation in -- the future. type HasCallStack = ?callStack :: CallStack -- | Boolean "and" (&&) :: Bool -> Bool -> Bool infixr 3 && -- | Boolean "or" (||) :: Bool -> Bool -> Bool infixr 2 || -- | Boolean "not" not :: Bool -> Bool -- | The class of monad transformers. Instances should satisfy the -- following laws, which state that lift is a monad -- transformation: -- -- class MonadTrans (t :: Type -> Type -> Type -> Type) -- | Lift a computation from the argument monad to the constructed monad. lift :: (MonadTrans t, Monad m) => m a -> t m a -- | tell w is an action that produces the output -- w. tell :: MonadWriter w m => w -> m () -- | Gets specific component of the state, using a projection function -- supplied. gets :: MonadState s m => (s -> a) -> m a -- | A variant of modify in which the computation is strict in the -- new state. modify' :: MonadState s m => (s -> s) -> m () -- | Minimal definition is either both of get and put or -- just state class Monad m => MonadState s (m :: Type -> Type) | m -> s -- | Return the state from the internals of the monad. get :: MonadState s m => m s -- | Replace the state inside the monad. put :: MonadState s m => s -> m () -- | See examples in Control.Monad.Reader. Note, the partially -- applied function type (->) r is a simple reader monad. See -- the instance declaration below. class Monad m => MonadReader r (m :: Type -> Type) | m -> r -- | Retrieves the monad environment. ask :: MonadReader r m => m r -- | Retrieves a function of the current environment. reader :: MonadReader r m => (r -> a) -> m a -- | Lifts an Either e into any MonadError -- e. -- --
--   do { val <- liftEither =<< action1; action2 }
--   
-- -- where action1 returns an Either to represent errors. liftEither :: MonadError e m => Either e a -> m a -- | The strategy of combining computations that can throw exceptions by -- bypassing bound functions from the point an exception is thrown to the -- point that it is handled. -- -- Is parameterized over the type of error information and the monad type -- constructor. It is common to use Either String as the -- monad type constructor for an error monad in which error descriptions -- take the form of strings. In that case and many other common cases the -- resulting monad is already defined as an instance of the -- MonadError class. You can also define your own error type -- and/or use a monad type constructor other than Either -- String or Either IOError. In -- these cases you will have to explicitly define instances of the -- MonadError class. (If you are using the deprecated -- Control.Monad.Error or Control.Monad.Trans.Error, you -- may also have to define an Error instance.) class Monad m => MonadError e (m :: Type -> Type) | m -> e -- | Is used within a monadic computation to begin exception processing. throwError :: MonadError e m => e -> m a -- | A handler function to handle previous errors and return to normal -- execution. A common idiom is: -- --
--   do { action1; action2; action3 } `catchError` handler
--   
-- -- where the action functions can call throwError. Note -- that handler and the do-block must have the same return type. catchError :: MonadError e m => m a -> (e -> m a) -> m a -- | A monad transformer that adds exceptions to other monads. -- -- ExceptT constructs a monad parameterized over two things: -- -- -- -- The return function yields a computation that produces the -- given value, while >>= sequences two subcomputations, -- exiting on the first exception. newtype ExceptT e (m :: Type -> Type) a ExceptT :: m (Either e a) -> ExceptT e a -- | The inverse of ExceptT. runExceptT :: () => ExceptT e m a -> m (Either e a) -- | The reader monad transformer, which adds a read-only environment to -- the given monad. -- -- The return function ignores the environment, while -- >>= passes the inherited environment to both -- subcomputations. newtype ReaderT r (m :: k -> Type) (a :: k) :: forall k. () => Type -> k -> Type -> k -> Type ReaderT :: (r -> m a) -> ReaderT r [runReaderT] :: ReaderT r -> r -> m a -- | A state transformer monad parameterized by: -- -- -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as -- the initial state of the second. data StateT s (m :: Type -> Type) a -- | A state monad parameterized by the type s of the state to -- carry. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as -- the initial state of the second. type State s = StateT s Identity -- | Unwrap a state monad computation as a function. (The inverse of -- state.) runState :: () => State s a -> s -> (a, s) -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- -- evalState :: () => State s a -> s -> a -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- -- evalStateT :: Monad m => StateT s m a -> s -> m a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- -- execStateT :: Monad m => StateT s m a -> s -> m s -- | A writer monad parameterized by: -- -- -- -- The return function produces the output mempty, while -- >>= combines the outputs of the subcomputations using -- mappend. data WriterT w (m :: Type -> Type) a fmapL :: (a -> b) -> Either a c -> Either b c foldr1 :: (a -> a -> a) -> NonEmpty a -> a headMay :: [a] -> Maybe a lastDef :: a -> [a] -> a maximumDef :: Ord a => a -> [a] -> a maximumMay :: Ord a => [a] -> Maybe a maximumMayOn :: Ord b => (a -> b) -> [a] -> Maybe a maxOn :: Ord b => (a -> b) -> a -> a -> a minimumDef :: Ord a => a -> [a] -> a minimumMay :: Ord a => [a] -> Maybe a minimumMayOn :: Ord b => (a -> b) -> [a] -> Maybe a minOn :: Ord b => (a -> b) -> a -> a -> a note :: e -> Maybe a -> Either e a replicateM2 :: Applicative m => m a -> m (a, a) replicateM3 :: Applicative m => m a -> m (a, a, a) show :: (Show a, IsString s) => a -> s whenJust :: Applicative m => Maybe a -> (a -> m ()) -> m () (!!) :: [a] -> Int -> Maybe a -- | An infix form of fromMaybe with arguments flipped. (?:) :: Maybe a -> a -> a infixr 0 ?: module RON.Error data Error Error :: Text -> [Error] -> Error type MonadE = MonadError Error correct :: MonadError e m => a -> m a -> m a errorContext :: MonadE m => Text -> m a -> m a -- | Lifts an Either e into any MonadError -- e. -- --
--   do { val <- liftEither =<< action1; action2 }
--   
-- -- where action1 returns an Either to represent errors. liftEither :: MonadError e m => Either e a -> m a liftEitherString :: (MonadError e m, IsString e) => Either String a -> m a liftMaybe :: MonadE m => Text -> Maybe a -> m a throwErrorString :: (MonadError e m, IsString e) => String -> m a throwErrorText :: MonadE m => Text -> m a instance GHC.Show.Show RON.Error.Error instance GHC.Classes.Eq RON.Error.Error instance GHC.Exception.Type.Exception RON.Error.Error instance Data.String.IsString RON.Error.Error -- | Common types for binary format (parser and serializer) module RON.Binary.Types type Size = Word32 -- | Data block descriptor data Desc DOpClosed :: Desc DOpReduced :: Desc DOpHeader :: Desc DOpQueryHeader :: Desc DUuidReducer :: Desc DUuidObject :: Desc DUuidOp :: Desc DUuidRef :: Desc DAtomUuidZip :: Desc DUuidZipObject :: Desc DUuidZipOp :: 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.Semilattice -- | A semilattice. -- -- It may be a join-semilattice, or meet-semilattice, it doesn't matter. -- -- If it matters for you, use package lattices. -- -- In addition to Semigroup, Semilattice defines these laws: -- -- class Semigroup a => Semilattice a -- | A bounded semilattice. -- -- Bounded semilattice laws are already defined by Monoid and -- Semilattice, so we don't define an explicit class here. type BoundedSemilattice a = (Monoid a, Semilattice a) instance GHC.Classes.Ord a => RON.Semilattice.Semilattice (Data.Semigroup.Max a) instance GHC.Classes.Ord a => RON.Semilattice.Semilattice (Data.Set.Internal.Set a) instance RON.Semilattice.Semilattice a => RON.Semilattice.Semilattice (GHC.Maybe.Maybe a) module RON.Util type ByteStringL = ByteString data Instance c Instance :: a -> Instance c module RON.Util.Word data Word2 b00 :: Word2 b01 :: Word2 b10 :: Word2 b11 :: Word2 pattern B00 :: Word2 pattern B01 :: Word2 pattern B10 :: Word2 pattern 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 pattern B0000 :: 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.Util.Word.Word60 instance GHC.Classes.Ord RON.Util.Word.Word60 instance GHC.Classes.Eq RON.Util.Word.Word60 instance GHC.Enum.Enum RON.Util.Word.Word60 instance GHC.Show.Show RON.Util.Word.Word24 instance GHC.Classes.Ord RON.Util.Word.Word24 instance GHC.Classes.Eq RON.Util.Word.Word24 instance GHC.Show.Show RON.Util.Word.Word12 instance GHC.Classes.Ord RON.Util.Word.Word12 instance GHC.Classes.Eq RON.Util.Word.Word12 instance GHC.Show.Show RON.Util.Word.Word6 instance GHC.Classes.Ord RON.Util.Word.Word6 instance GHC.Classes.Eq RON.Util.Word.Word6 instance GHC.Show.Show RON.Util.Word.Word4 instance GHC.Classes.Ord RON.Util.Word.Word4 instance GHC.Classes.Eq RON.Util.Word.Word4 instance GHC.Show.Show RON.Util.Word.Word2 instance GHC.Classes.Ord RON.Util.Word.Word2 instance GHC.Classes.Eq RON.Util.Word.Word2 instance RON.Util.Word.SafeCast RON.Util.Word.Word2 GHC.Types.Int instance RON.Util.Word.SafeCast RON.Util.Word.Word2 RON.Util.Word.Word4 instance RON.Util.Word.SafeCast RON.Util.Word.Word2 GHC.Word.Word8 instance RON.Util.Word.SafeCast RON.Util.Word.Word2 GHC.Word.Word64 instance RON.Util.Word.SafeCast RON.Util.Word.Word4 GHC.Types.Int instance RON.Util.Word.SafeCast RON.Util.Word.Word4 GHC.Word.Word64 instance RON.Util.Word.SafeCast RON.Util.Word.Word4 GHC.Word.Word8 instance RON.Util.Word.SafeCast RON.Util.Word.Word6 GHC.Types.Int instance RON.Util.Word.SafeCast RON.Util.Word.Word6 GHC.Word.Word8 instance RON.Util.Word.SafeCast RON.Util.Word.Word6 RON.Util.Word.Word60 instance RON.Util.Word.SafeCast RON.Util.Word.Word6 GHC.Word.Word64 instance RON.Util.Word.SafeCast GHC.Word.Word8 GHC.Word.Word32 instance RON.Util.Word.SafeCast GHC.Word.Word8 GHC.Word.Word64 instance RON.Util.Word.SafeCast RON.Util.Word.Word12 GHC.Word.Word64 instance RON.Util.Word.SafeCast RON.Util.Word.Word24 GHC.Word.Word64 instance RON.Util.Word.SafeCast RON.Util.Word.Word24 GHC.Word.Word32 instance RON.Util.Word.SafeCast RON.Util.Word.Word60 GHC.Word.Word64 instance RON.Util.Word.SafeCast GHC.Word.Word64 GHC.Integer.Type.Integer instance Data.Fixed.HasResolution e => RON.Util.Word.SafeCast GHC.Word.Word64 (Data.Fixed.Fixed e) instance GHC.Enum.Bounded RON.Util.Word.Word60 instance Data.Hashable.Class.Hashable RON.Util.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.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 pattern Zero :: UUID -- | Convert UUID to a name getName :: UUID -> Maybe (ByteString, ByteString) -- | Contruct a UUID name in compile-time liftName :: ByteString -> Q Exp -- | Make an unscoped (unqualified) name mkName :: MonadFail m => ByteString -> m UUID -- | Make a scoped (qualified) name mkScopedName :: MonadFail 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 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 -- | Closed op data ClosedOp ClosedOp :: UUID -> UUID -> Op -> ClosedOp -- | type [$sel:reducerId:ClosedOp] :: ClosedOp -> UUID -- | object id [$sel:objectId:ClosedOp] :: ClosedOp -> UUID -- | other keys and payload, that are common with reduced op [$sel:op:ClosedOp] :: ClosedOp -> Op -- | Reference to an object newtype ObjectRef a ObjectRef :: UUID -> ObjectRef a -- | Object reference accompanied with a frame data ObjectFrame a ObjectFrame :: UUID -> StateFrame -> ObjectFrame a [$sel:uuid:ObjectFrame] :: ObjectFrame a -> UUID [$sel:frame:ObjectFrame] :: ObjectFrame a -> StateFrame -- | Open op (operation) data Op Op :: UUID -> UUID -> Payload -> Op -- | event id (usually timestamp) [$sel:opId:Op] :: Op -> UUID -- | reference to other op; actual semantics depends on the type [$sel:refId:Op] :: Op -> UUID -- | payload [$sel:payload:Op] :: Op -> Payload -- | Op terminator data OpTerm TClosed :: OpTerm TReduced :: OpTerm THeader :: OpTerm TQuery :: OpTerm type Payload = [Atom] -- | Type-tagged version of WireStateChunk newtype StateChunk a StateChunk :: [Op] -> StateChunk a -- | Frame containing only state chunks. Must contain one main object and -- any number of other objects that are part of the main one. type StateFrame = Map UUID WireStateChunk -- | Universally unique identifier of anything data UUID UUID :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> UUID -- | Common chunk data WireChunk Closed :: ClosedOp -> WireChunk Value :: WireReducedChunk -> WireChunk Query :: WireReducedChunk -> WireChunk -- | Common frame type WireFrame = [WireChunk] -- | Common reduced chunk data WireReducedChunk WireReducedChunk :: ClosedOp -> [Op] -> WireReducedChunk [$sel:wrcHeader:WireReducedChunk] :: WireReducedChunk -> ClosedOp [$sel:wrcBody:WireReducedChunk] :: WireReducedChunk -> [Op] -- | Reduced chunk representing an object state (i. e. high-level value) data WireStateChunk WireStateChunk :: UUID -> [Op] -> WireStateChunk [$sel:stateType:WireStateChunk] :: WireStateChunk -> UUID [$sel:stateBody:WireStateChunk] :: WireStateChunk -> [Op] data OpPattern Regular :: OpPattern Delete :: OpPattern Undelete :: OpPattern Create :: OpPattern Ack :: OpPattern Annotation :: OpPattern AnnotationDerived :: OpPattern opPattern :: Op -> Maybe OpPattern pattern AckP :: (Word2, Word2) pattern AnnotationDerivedP :: (Word2, Word2) pattern AnnotationP :: (Word2, Word2) pattern CreateP :: (Word2, Word2) pattern DeleteP :: (Word2, Word2) pattern RegularP :: (Word2, Word2) pattern UndeleteP :: (Word2, Word2) instance GHC.Show.Show (RON.Types.ObjectFrame a) instance GHC.Classes.Eq (RON.Types.ObjectFrame a) instance GHC.Generics.Generic (RON.Types.ObjectRef a) instance Data.Hashable.Class.Hashable (RON.Types.ObjectRef a) instance GHC.Classes.Eq (RON.Types.ObjectRef a) instance GHC.Show.Show RON.Types.WireStateChunk instance GHC.Classes.Eq RON.Types.WireStateChunk instance GHC.Show.Show RON.Types.OpTerm instance GHC.Classes.Eq RON.Types.OpTerm instance GHC.Show.Show 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 GHC.Generics.Generic RON.Types.WireReducedChunk instance GHC.Classes.Eq RON.Types.WireReducedChunk instance Data.Data.Data RON.Types.WireReducedChunk instance GHC.Generics.Generic RON.Types.ClosedOp instance GHC.Classes.Eq RON.Types.ClosedOp instance Data.Data.Data RON.Types.ClosedOp instance GHC.Show.Show 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 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 Data.Typeable.Internal.Typeable a => GHC.Show.Show (RON.Types.ObjectRef a) instance GHC.Show.Show RON.Types.ClosedOp -- | 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.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: -- --
    --
  1.  t <- getEvents n (t !! i) == head t + i 
  2. --
  3.  t1 <- getEvent t2 <- getEvent t2 >=
    --   t1 + 1 
  4. --
  5. getEvents 0 == getEvents 1
  6. --
getEvents :: ReplicaClock m => EpochTime -> m [EpochEvent] -- | Make local time not less than this advance :: ReplicaClock m => EpochTime -> m () -- | Replica identifier data ReplicaId ReplicaId :: !Naming -> !Word60 -> ReplicaId -- | advance variant for any UUID advanceToUuid :: ReplicaClock clock => UUID -> clock () -- | Make an ApplicationSpecific replica id from arbitrary number applicationSpecific :: Word64 -> ReplicaId decodeEvent :: UUID -> Event encodeEvent :: Event -> UUID fromCalendarEvent :: CalendarEvent -> Event fromEpochEvent :: EpochEvent -> Event -- | Get a single event getEvent :: (HasCallStack, ReplicaClock m) => m EpochEvent -- | Get a single event as UUID getEventUuid :: ReplicaClock m => m UUID -- | Get event sequence as UUIDs getEventUuids :: ReplicaClock m => Word60 -> m [UUID] -- | Make a calendar timestamp from a date mkCalendarDate :: (Word16, Word16, Word8) -> Maybe CalendarTime -- | Make a calendar timestamp from a date and a day time mkCalendarDateTime :: (Word16, Word16, Word8) -> (Word8, Word8, Word8) -> Maybe CalendarTime -- | Make a calendar timestamp from a date, a day time, and a second -- fraction mkCalendarDateTimeNano :: (Word16, Word16, Word8) -> (Word8, Word8, Word8) -> Word32 -> Maybe CalendarTime toEpochEvent :: Event -> Maybe EpochEvent instance GHC.Show.Show RON.Event.EpochEvent instance GHC.Classes.Eq RON.Event.EpochEvent instance GHC.Show.Show RON.Event.CalendarEvent instance GHC.Classes.Eq RON.Event.CalendarEvent instance GHC.Show.Show RON.Event.Event instance GHC.Classes.Eq RON.Event.Event instance Data.Hashable.Class.Hashable RON.Event.ReplicaId instance GHC.Generics.Generic RON.Event.ReplicaId instance GHC.Show.Show RON.Event.ReplicaId instance GHC.Classes.Eq RON.Event.ReplicaId instance GHC.Show.Show RON.Event.Naming instance GHC.Classes.Eq RON.Event.Naming instance GHC.Enum.Enum RON.Event.Naming instance GHC.Enum.Bounded RON.Event.Naming instance GHC.Show.Show RON.Event.LocalTime instance GHC.Classes.Eq RON.Event.LocalTime instance GHC.Show.Show RON.Event.CalendarTime instance GHC.Classes.Ord RON.Event.CalendarTime instance GHC.Classes.Eq RON.Event.CalendarTime instance RON.Event.ReplicaClock m => RON.Event.ReplicaClock (Control.Monad.Trans.Except.ExceptT e m) instance RON.Event.ReplicaClock m => RON.Event.ReplicaClock (Control.Monad.Trans.Reader.ReaderT r m) instance RON.Event.ReplicaClock m => RON.Event.ReplicaClock (Control.Monad.Trans.State.Strict.StateT s m) instance (GHC.Base.Monoid s, RON.Event.ReplicaClock m) => RON.Event.ReplicaClock (Control.Monad.Trans.Writer.Strict.WriterT s m) instance GHC.Classes.Ord RON.Event.EpochEvent instance GHC.Classes.Ord RON.Event.CalendarEvent instance Data.Hashable.Class.Hashable RON.Event.Naming -- | Lamport clock network simulation. ReplicaSim provides -- Replica and Clock instances, replicas may -- interchange data while they are connected in a NetworkSim. module RON.Event.Simulation -- | Lamport clock simulation. Key is ReplicaId. Non-present value -- is equivalent to (0, initial). data NetworkSimT m a -- | ReplicaSim inside Lamport clock simulation. data ReplicaSimT m a -- | Execute network simulation -- -- Usage: -- --
--   runExceptT . runNetworkSimT $ do
--       runReplicaSimT r1 $ do
--           actions...
--       runReplicaSimT r2 $ do
--           actions...
--       runReplicaSimT r1 $ ...
--   
-- -- Each runNetworkSimT starts its own networks. One shouldn't use -- in one network events generated in another. runNetworkSimT :: Monad m => NetworkSimT m a -> m a runReplicaSimT :: ReplicaId -> ReplicaSimT m a -> NetworkSimT m a instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (RON.Event.Simulation.ReplicaSimT m) 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 Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (RON.Event.Simulation.NetworkSimT 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.Fail.MonadFail m => Control.Monad.Fail.MonadFail (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 -- | Decode date and time from UUID epoch timestamp decode :: EpochTime -> UTCTime encode :: POSIXTime -> EpochTime -- | 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 :: Word64 -> 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.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 :: ObjectFrame a -> (UUID, ByteStringL) -- | Serialize a context-free raw op serializeRawOp :: ClosedOp -> 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 (ObjectFrame a) -- | Parse a single context-free op parseOp :: ByteStringL -> Either String ClosedOp -- | 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 (ObjectFrame 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 :: ObjectFrame 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