-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple Data Processing -- -- SDP provides generalized interface for simple data operations. @package sdp @version 0.2 -- | Control.Exception.SDP - service module that provide some useful -- exceptions. Note that SDP.SafePrelude doesn't export this -- module. module Control.Exception.SDP -- | A UnreachableException is used as an exception that should -- never be thrown. -- --
-- import Prelude () -- import SDP.SafePrelude -- --module SDP.SafePrelude -- | Ternary operator. -- --
-- (odd 1 ? "is True" $ "is False") == "is True" --(?) :: Bool -> a -> a -> a infixr 1 ? -- | p ?+ f $ a returns Just (f a) if (p -- a) and Nothing otherwise. (?+) :: (a -> Bool) -> (a -> b) -> a -> Maybe b infixl 8 ?+ -- | p ?- f $ a returns Nothing if (p a) and -- Just (f a) otherwise. (?-) :: (a -> Bool) -> (a -> b) -> a -> Maybe b infixl 8 ?- -- | Prepends Maybe to list. (?:) :: Maybe a -> [a] -> [a] -- | Short version of fromMaybe. (+?) :: a -> Maybe a -> a -- | (...) = (.) . (.). (...) :: (c -> d) -> (a -> b -> c) -> a -> b -> d infixr 0 ... -- | Lifted (?). (?^) :: Monad m => m Bool -> m a -> m a -> m a infixr 1 ?^ -- | Monadic version of (...). (<=<<) :: Monad m => (c -> m d) -> (a -> b -> m c) -> a -> b -> m d -- | Monadic vesion of (...) with reversed arguments. (>>=>) :: Monad m => (a -> b -> m c) -> (c -> m d) -> a -> b -> m d -- | ma >>=<< mb is composition of join and -- liftM2. (>>=<<) :: Monad m => m a -> m b -> (a -> b -> m c) -> m c -- | Very useful combinator. liftA4 :: Applicative t => (a -> b -> c -> d -> e) -> t a -> t b -> t c -> t d -> t e -- | Very very useful combinator liftA5 :: Applicative t => (a -> b -> c -> d -> e -> f) -> t a -> t b -> t c -> t d -> t e -> t f -- | An even more useful combinator. liftA6 :: Applicative t => (a -> b -> c -> d -> e -> f -> g) -> t a -> t b -> t c -> t d -> t e -> t f -> t g -- | See liftA6. liftM6 :: Monad m => (a -> b -> c -> d -> e -> f -> g) -> m a -> m b -> m c -> m d -> m e -> m f -> m g -- | stToMIO is just liftIO . stToIO. stToMIO :: MonadIO io => ST RealWorld e -> io e -- | SDP.Finite provide generalized finite-dimensional index type -- (:&) based on repa (:.). -- -- Since sdp-0.2, for (:&) available -- OverloadedLists-based syntactic sugar. For example, instead -- of the inconvenient es!(ind4 0 1 2 3) or just awful -- es!(E:&0:&1:&1:&2:&3) you can write: -- es![0, 1, 2, 3]. -- -- Note that OverloadedLists instances requires a strictly -- defined number of subindexes. module SDP.Finite -- | Service type, that represents zero-dimensional index. data E E :: E -- | N-dimensional index type. The type (head :& tail) allows working -- with any finite dimension number. data tail :& head (:&) :: !tail -> !head -> (:&) tail head -- | 1-dimensional index ((E :& i) without -- TypeOperators). type I1 i = E :& i -- | 2-dimensional index type I2 i = E :& i :& i -- | 3-dimensional index type I3 i = (I2 i) :& i -- | 4-dimensional index type I4 i = (I3 i) :& i -- | 5-dimensional index type I5 i = (I4 i) :& i -- | 6-dimensional index type I6 i = (I5 i) :& i -- | 7-dimensional index type I7 i = (I6 i) :& i -- | 8-dimensional index type I8 i = (I7 i) :& i -- | 9-dimensional index type I9 i = (I8 i) :& i -- | 10-dimensional index type I10 i = (I9 i) :& i -- | 11-dimensional index type I11 i = (I10 i) :& i -- | 12-dimensional index type I12 i = (I11 i) :& i -- | 13-dimensional index type I13 i = (I12 i) :& i -- | 14-dimensional index type I14 i = (I13 i) :& i -- | 15-dimensional index type I15 i = (I14 i) :& i -- | 2-dimensional index constructor. ind2 :: i -> i -> I2 i -- | 3-dimensional index constructor. ind3 :: i -> i -> i -> I3 i -- | 4-dimensional index constructor. ind4 :: i -> i -> i -> i -> I4 i -- | 5-dimensional index constructor. ind5 :: i -> i -> i -> i -> i -> I5 i -- | 6-dimensional index constructor. ind6 :: i -> i -> i -> i -> i -> i -> I6 i -- | 7-dimensional index constructor. ind7 :: i -> i -> i -> i -> i -> i -> i -> I7 i -- | 8-dimensional index constructor. ind8 :: i -> i -> i -> i -> i -> i -> i -> i -> I8 i -- | 9-dimensional index constructor. ind9 :: i -> i -> i -> i -> i -> i -> i -> i -> i -> I9 i -- | 10-dimensional index constructor. ind10 :: i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> I10 i -- | 11-dimensional index constructor. ind11 :: i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> I11 i -- | 12-dimensional index constructor. ind12 :: i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> I12 i -- | 13-dimensional index constructor. ind13 :: i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> I13 i -- | 14-dimensional index constructor. ind14 :: i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> I14 i -- | 15-dimensional index constructor. ind15 :: i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> i -> I15 i instance GHC.Read.Read SDP.Finite.E instance GHC.Show.Show SDP.Finite.E instance GHC.Classes.Ord SDP.Finite.E instance GHC.Classes.Eq SDP.Finite.E instance (GHC.Classes.Ord tail, GHC.Classes.Ord head) => GHC.Classes.Ord (tail SDP.Finite.:& head) instance (GHC.Classes.Eq tail, GHC.Classes.Eq head) => GHC.Classes.Eq (tail SDP.Finite.:& head) instance GHC.Enum.Enum i => GHC.Enum.Enum (SDP.Finite.E SDP.Finite.:& i) instance (Data.Default.Class.Default d, Data.Default.Class.Default d') => Data.Default.Class.Default (d SDP.Finite.:& d') instance (GHC.Exts.IsList (i' SDP.Finite.:& i), GHC.Exts.Item (i' SDP.Finite.:& i) ~ i, GHC.Show.Show i) => GHC.Show.Show (i' SDP.Finite.:& i) instance (GHC.Exts.IsList (i' SDP.Finite.:& i), GHC.Exts.Item (i' SDP.Finite.:& i) ~ i, GHC.Read.Read i) => GHC.Read.Read (i' SDP.Finite.:& i) instance GHC.Exts.IsList (SDP.Finite.E SDP.Finite.:& i) instance (GHC.Exts.Item (i' SDP.Finite.:& i) ~ i, GHC.Exts.IsList (i' SDP.Finite.:& i)) => GHC.Exts.IsList ((i' SDP.Finite.:& i) SDP.Finite.:& i) instance Data.Default.Class.Default SDP.Finite.E instance GHC.Exts.IsList SDP.Finite.E -- | SDP.SortM provides SortM - class of sortable mutable -- structures. module SDP.SortM -- | SortM is class of sortable mutable structures. class SortM m s e | s -> m, s -> e -- | Checks if structure is already sorted. Should always return -- True for structures with less than 2 elements. sortedMBy :: SortM m s e => (e -> e -> Bool) -> s -> m Bool -- | sortMBy is common sorting algorithm. sortMBy :: SortM m s e => Compare e -> s -> m () -- | Kind (* -> *) version of SortM. type SortM1 m s e = SortM m (s e) e -- | sortM is just sortMBy compare sortM :: (SortM m s e, Ord e) => s -> m () -- | Sort by comparing the results of a key function applied to each -- element. sortMOn :: (SortM m s e, Ord o) => (e -> o) -> s -> m () -- | Checks if the structure is sorted. sortedM :: (SortM m s e, Ord e) => s -> m Bool -- | Sort by comparing the results of a given function applied to each -- element. sortedMOn :: (SortM m s e, Ord o) => (e -> o) -> s -> m Bool -- | SDP.Tuple provides tuple type synonyms. module SDP.Tuple -- | Tuple synonym type T2 i = (i, i) -- | Tuple synonym type T3 i = (i, i, i) -- | Tuple synonym type T4 i = (i, i, i, i) -- | Tuple synonym type T5 i = (i, i, i, i, i) -- | Tuple synonym type T6 i = (i, i, i, i, i, i) -- | Tuple synonym type T7 i = (i, i, i, i, i, i, i) -- | Tuple synonym type T8 i = (i, i, i, i, i, i, i, i) -- | Tuple synonym type T9 i = (i, i, i, i, i, i, i, i, i) -- | Tuple synonym type T10 i = (i, i, i, i, i, i, i, i, i, i) -- | Tuple synonym type T11 i = (i, i, i, i, i, i, i, i, i, i, i) -- | Tuple synonym type T12 i = (i, i, i, i, i, i, i, i, i, i, i, i) -- | Tuple synonym type T13 i = (i, i, i, i, i, i, i, i, i, i, i, i, i) -- | Tuple synonym type T14 i = (i, i, i, i, i, i, i, i, i, i, i, i, i, i) -- | Tuple synonym type T15 i = (i, i, i, i, i, i, i, i, i, i, i, i, i, i, i) -- | Return all first elements in pairs. fsts :: Functor f => f (a, b) -> f a -- | Return all first elements in pairs. snds :: Functor f => f (a, b) -> f b -- | Applies function to both elements of pair. both :: (a -> b) -> (a, a) -> (b, b) -- | SDP.Shape module provides Shape - class of generalized -- indices. module SDP.Shape -- | Shape is service class that constraints Index. -- -- Rules: -- --
-- rank i == rank (j `asTypeOf` i) -- rank i == length (sizes (i, i)) ---- --
-- rank (lastDim E) = 0 -- rank (lastDim i) = 1 -- rank (initDim E) = 0 -- rank (lastDim i) = rank i - 1 ---- --
-- fromGIndex . toGIndex = id -- toGIndex . fromGIndex = id --class Shape i where { -- | Type of index top dimension. type family DimLast i :: Type; -- | The type of subspace of rank n - 1, where n -- is the rank of the space specified by this Index type. type family DimInit i :: Type; type DimLast i = i; type DimInit i = E; } -- | Create index from generalized index. fromGIndex :: (Shape i, RANK1 i) => GIndex i -> i -- | Create index from generalized index. fromGIndex :: Shape i => GIndex i -> i -- | Create generalized index from index. toGIndex :: (Shape i, RANK1 i) => i -> GIndex i -- | Create generalized index from index. toGIndex :: Shape i => i -> GIndex i -- | Count of dimensions in represented space (must be finite and -- constant). rank :: Shape i => i -> Int -- | Add new dimension. consDim :: (Shape i, DimLast i ~~ i) => DimInit i -> DimLast i -> i -- | Add new dimension. consDim :: Shape i => DimInit i -> DimLast i -> i initDim :: (Shape i, DimInit i ~~ E) => i -> DimInit i initDim :: Shape i => i -> DimInit i lastDim :: (Shape i, DimLast i ~~ i) => i -> DimLast i lastDim :: Shape i => i -> DimLast i unconsDim :: Shape i => i -> (DimInit i, DimLast i) -- | Type operator GIndex returns generalized equivalent of index. type family GIndex i -- | Convert any index type bounds to generalized index bounds. toGBounds :: Shape i => (i, i) -> (GIndex i, GIndex i) -- | Convert generalized index bounds to any index type bounds. fromGBounds :: Shape i => (GIndex i, GIndex i) -> (i, i) -- | A constraint corresponding to rank 0 indices (E). type RANK0 i = i ~~ E -- | The restriction corresponding to rank indices 1 (сhecks -- GIndex). type RANK1 i = GIndex i ~~ (E :& i) -- | The restriction corresponding to rank indices 2 (сhecks -- GIndex). type RANK2 i = GIndex i ~~ I2 i -- | The restriction corresponding to rank indices 3 (сhecks -- GIndex). type RANK3 i = GIndex i ~~ I3 i -- | The restriction corresponding to rank indices 4 (сhecks -- GIndex). type RANK4 i = GIndex i ~~ I4 i -- | The restriction corresponding to rank indices 5 (сhecks -- GIndex). type RANK5 i = GIndex i ~~ I5 i -- | The restriction corresponding to rank indices 6 (сhecks -- GIndex). type RANK6 i = GIndex i ~~ I6 i -- | The restriction corresponding to rank indices 7 (сhecks -- GIndex). type RANK7 i = GIndex i ~~ I7 i -- | The restriction corresponding to rank indices 8 (сhecks -- GIndex). type RANK8 i = GIndex i ~~ I8 i -- | The restriction corresponding to rank indices 9 (сhecks -- GIndex). type RANK9 i = GIndex i ~~ I9 i -- | The restriction corresponding to rank indices 10 (сhecks -- GIndex). type RANK10 i = GIndex i ~~ I10 i -- | The restriction corresponding to rank indices 11 (сhecks -- GIndex). type RANK11 i = GIndex i ~~ I11 i -- | The restriction corresponding to rank indices 12 (сhecks -- GIndex). type RANK12 i = GIndex i ~~ I12 i -- | The restriction corresponding to rank indices 13 (сhecks -- GIndex). type RANK13 i = GIndex i ~~ I13 i -- | The restriction corresponding to rank indices 14 (сhecks -- GIndex). type RANK14 i = GIndex i ~~ I14 i -- | The restriction corresponding to rank indices 15 (сhecks -- GIndex). type RANK15 i = GIndex i ~~ I15 i instance SDP.Shape.Shape SDP.Finite.E instance SDP.Shape.Shape () instance SDP.Shape.Shape GHC.Types.Char instance SDP.Shape.Shape GHC.Integer.Type.Integer instance SDP.Shape.Shape GHC.Types.Int instance SDP.Shape.Shape GHC.Int.Int8 instance SDP.Shape.Shape GHC.Int.Int16 instance SDP.Shape.Shape GHC.Int.Int32 instance SDP.Shape.Shape GHC.Int.Int64 instance SDP.Shape.Shape GHC.Types.Word instance SDP.Shape.Shape GHC.Word.Word8 instance SDP.Shape.Shape GHC.Word.Word16 instance SDP.Shape.Shape GHC.Word.Word32 instance SDP.Shape.Shape GHC.Word.Word64 instance SDP.Shape.Shape Foreign.C.Types.CChar instance SDP.Shape.Shape Foreign.C.Types.CUChar instance SDP.Shape.Shape Foreign.C.Types.CSChar instance SDP.Shape.Shape Foreign.C.Types.CWchar instance SDP.Shape.Shape Foreign.C.Types.CShort instance SDP.Shape.Shape Foreign.C.Types.CUShort instance SDP.Shape.Shape Foreign.C.Types.CInt instance SDP.Shape.Shape Foreign.C.Types.CUInt instance SDP.Shape.Shape Foreign.C.Types.CLong instance SDP.Shape.Shape Foreign.C.Types.CLLong instance SDP.Shape.Shape Foreign.C.Types.CULong instance SDP.Shape.Shape Foreign.C.Types.CULLong instance SDP.Shape.Shape Foreign.C.Types.CIntPtr instance SDP.Shape.Shape Foreign.C.Types.CUIntPtr instance SDP.Shape.Shape Foreign.C.Types.CIntMax instance SDP.Shape.Shape Foreign.C.Types.CUIntMax instance SDP.Shape.Shape Foreign.C.Types.CSize instance SDP.Shape.Shape Foreign.C.Types.CBool instance SDP.Shape.Shape Foreign.C.Types.CPtrdiff instance SDP.Shape.Shape Foreign.C.Types.CSigAtomic instance SDP.Shape.Shape i => SDP.Shape.Shape (SDP.Finite.E SDP.Finite.:& i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i, SDP.Shape.Shape (i' SDP.Finite.:& i)) => SDP.Shape.Shape ((i' SDP.Finite.:& i) SDP.Finite.:& i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T2 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T3 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T4 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T5 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T6 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T7 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T8 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T9 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T10 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T11 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T12 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T13 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T14 i) instance (SDP.Shape.Shape i, GHC.Enum.Enum i, GHC.Enum.Bounded i) => SDP.Shape.Shape (SDP.Tuple.T15 i) -- | The Index class is a fork of Ix with a richer interface, -- more convenient function names and generalized indexes. module SDP.Index -- | (:|:) is closed type family of shape differences. type family i :|: j -- | SubIndex is service constraint that corresponds closed -- (internal) class Sub. SubIndex i j matches -- if Index type i is subspace of Index type -- j. type SubIndex = Sub -- | Take some dimensions. -- --
-- >>> takeDim ([1, 2, 3, 4] :: I4 Int) :: I1 Int -- [1] -- -- >>> takeDim ([1, 2, 3, 4] :: I4 Int) :: E -- E --takeDim :: Sub i j => i -> j -- | Drop some dimensions (second argument used as type variable). -- --
-- >>> dropDim ([1, 2, 3, 4] :: I4 Int) ([] :: E) -- [1, 2, 3, 4] -- -- >>> dropDim ([1, 2, 3, 4] :: I4 Int) ([1, 2] :: I2 Int) -- [3, 4] --dropDim :: Sub i j => i -> j -> i :|: j -- | Join some dimensions. -- --
-- >>> joinDim ([1, 2] :: I2 Int) [3] :: I3 Int -- [1, 2, 3] -- -- >>> joinDim ([1, 2] :: I2 Int) [3, 4] :: I4 Int -- [1, 2, 3, 4] --joinDim :: Sub i j => j -> (i :|: j) -> i -- | splitDim returns pair of shape difference and subshape. splitDim :: SubIndex i j => i -> (i :|: j, j) -- | Index is service class based on base Ix and repa -- Shape. -- -- Basic rules: -- --
-- size bnds >= 0 -- size bnds == product (sizes bnds) ---- --
-- isEmpty bnds == (size bnds == 0) -- isEmpty bnds == inRange bnds (safeElem bnds i) ---- --
-- isEmpty bnds => isOverflow bnds i -- isEmpty bnds => isUnderflow bnds i ---- --
-- inRange bnds i /= isEmpty bnds -- inRange bnds i /= isOverflow bnds i -- inRange bnds i /= isUnderflow bnds i -- inRange bnds i == (safeElem bnds i == i) ---- -- Note: -- --
-- es !^ i = listL es !! i --(!^) :: Linear l e => l -> Int -> e -- | write es n e writes value e in position n -- (offset), returns new structure. If n is out of range, -- returns equal structure (es or copy). write :: Linear l e => l -> Int -> e -> l -- | Generalized concat. concat :: (Linear l e, Foldable f) => f l -> l -- | Generalized concatMap. concatMap :: (Linear l e, Foldable f) => (a -> l) -> f a -> l -- | Generalized intersperse. intersperse :: Linear l e => e -> l -> l -- | Generalized filter. filter :: Linear l e => (e -> Bool) -> l -> l -- | Inverted filter. except :: Linear l e => (e -> Bool) -> l -> l -- | Generalization of partition. partition :: Linear l e => (e -> Bool) -> l -> (l, l) -- | Generalization of partition, that select sublines by predicates. partitions :: (Linear l e, Foldable f) => f (e -> Bool) -> l -> [l] -- | select f es is selective map of es elements to new -- list. select :: Linear l e => (e -> Maybe a) -> l -> [a] -- | select' f es is selective map of es elements to new -- line. select' :: (Linear l e, t e ~ l, Linear1 t a) => (e -> Maybe a) -> l -> t a -- | extract f es returns a selective map of es elements -- to new list and the remaining elements of the line. extract :: Linear l e => (e -> Maybe a) -> l -> ([a], l) -- | extract' f es returns a selective map of es elements -- to new line and the remaining elements of the line. extract' :: (Linear l e, t e ~ l, Linear1 t a) => (e -> Maybe a) -> l -> (t a, l) -- | selects fs es sequentially applies the functions from -- fs to the remainder of es, returns a list of -- selections and the remainder of the last selection. selects :: (Linear l e, Foldable f) => f (e -> Maybe a) -> l -> ([[a]], l) -- | selects' fs es sequentially applies the functions from -- fs to the remainder of es, returns a line of -- selections and the remainder of the last selection. selects' :: (Linear l e, Foldable f, t e ~ l, Linear1 t a) => f (e -> Maybe a) -> l -> ([t a], l) -- | The isSubseqOf xs ys checks if all the elements of the -- xs occur, in order, in the ys. The elements don't -- have to occur consecutively. isSubseqOf :: (Linear l e, Eq e) => l -> l -> Bool -- | Generalized reverse. reverse :: Linear l e => l -> l -- | Create new line, equal to given. force :: Linear l e => l -> l -- | Generalized subsequences. subsequences :: Linear l e => l -> [l] -- | iterate n f x returns sequence of n applications of -- f to x. -- -- Note that iterate returns finite sequence, instead -- Prelude prototype. iterate :: Linear l e => Int -> (e -> e) -> e -> l -- | Same as nubBy (==). nub :: (Linear l e, Eq e) => l -> l -- | Generalization of nubBy. nubBy :: Linear l e => Equal e -> l -> l -- | ofoldr is right fold with offset. ofoldr :: Linear l e => (Int -> e -> b -> b) -> b -> l -> b -- | ofoldl is left fold with offset. ofoldl :: Linear l e => (Int -> b -> e -> b) -> b -> l -> b -- | ofoldr' is strict version of ofoldr. ofoldr' :: Linear l e => (Int -> e -> b -> b) -> b -> l -> b -- | ofoldl' is strict version of ofoldl. ofoldl' :: Linear l e => (Int -> b -> e -> b) -> b -> l -> b -- | o_foldr is just foldr in Linear context. o_foldr :: Linear l e => (e -> b -> b) -> b -> l -> b -- | o_foldl is just foldl in Linear context. o_foldl :: Linear l e => (b -> e -> b) -> b -> l -> b -- | o_foldr' is just foldr' in Linear context. o_foldr' :: Linear l e => (e -> b -> b) -> b -> l -> b -- | o_foldl' is just foldl' in Linear context. o_foldl' :: Linear l e => (b -> e -> b) -> b -> l -> b infix 8 `filter` infixr 5 ++ infix 8 `except` infixl 9 !^ -- | Kind (* -> *) Linear structure. type Linear1 l e = Linear (l e) e -- | Split - class of splittable data structures. class (Linear s e) => Split s e | s -> e -- | take n es takes first n elements of es. take :: Split s e => Int -> s -> s -- | take n es takes first n elements of es. take :: (Split s e, Bordered s i) => Int -> s -> s -- | drop n es drops first n elements of es. drop :: Split s e => Int -> s -> s -- | drop n es drops first n elements of es. drop :: (Split s e, Bordered s i) => Int -> s -> s -- | keep n es takes last n elements of es. keep :: Split s e => Int -> s -> s -- | keep n es takes last n elements of es. keep :: (Split s e, Bordered s i) => Int -> s -> s -- | sans n es drops last n elements of es. sans :: Split s e => Int -> s -> s -- | sans n es drops last n elements of es. sans :: (Split s e, Bordered s i) => Int -> s -> s -- | save n es takes first n elements of es if -- n > 0 and last -n elements otherwise. save :: Split s e => Int -> s -> s -- | skip n es drops first n elements of es if -- n > 0 and last -n elements otherwise. skip :: Split s e => Int -> s -> s -- | split n es is same to (take n es, drop n es). split :: Split s e => Int -> s -> (s, s) -- | divide n es is same to (sans n es, keep n es). divide :: Split s e => Int -> s -> (s, s) -- | Splits line into sequences of given sizes (left to right). -- --
-- splits [5, 3, 12] ['a'..'z'] = ["abcde","fgh","ijklmnopqrst","uvwxyz"] --splits :: (Split s e, Foldable f) => f Int -> s -> [s] -- | Splits line into sequences of given sizes (right to left). -- --
-- divides [5,3,12] ['a'..'z'] == ["abcdef","ghijk","lmn","opqrstuvwxyz"] --divides :: (Split s e, Foldable f) => f Int -> s -> [s] -- | Splits structures into parts by given offsets. -- --
-- parts [0,5,6,12,26] ['a'..'z'] = ["","abcde","f","ghijkl","mnopqrstuvwxyz",""] -- -- if previous offset is equal or greater, subline is empty and next -- begins from previous: -- parts [0, 5, 4, 12, 26] ['a' .. 'z'] = ["","abcde","","fghijklm","nopqrstuvwxyz",""] --parts :: (Split s e, Foldable f) => f Int -> s -> [s] -- | Splits structures into chunks of size n and the rest. -- --
-- chunks x [] = [] -- forall x -- chunks 0 es = [] -- forall es ---- --
-- chunks 3 [1 .. 10] == [[1,2,3],[4,5,6],[7,8,9],[10]] --chunks :: Split s e => Int -> s -> [s] -- | Split line by first (left) separation element. If there is no such -- element, splitBy es = (es, Z). -- --
-- splitBy (== '.') "foo" == ("foo","")
-- splitBy (== '.') "foo." == ("foo","")
-- splitBy (== '.') ".foo" == ("","foo")
-- splitBy (== '.') "foo.bar" == ("foo","bar")
-- splitBy (== '.') "foo.bar.baz" == ("foo","bar.baz")
--
splitBy :: Split s e => (e -> Bool) -> s -> (s, s)
-- | Split line by last (right) separation element. If there is no such
-- element, divide es = (Z, es).
--
--
-- divideBy (== '.') "foo" == ("","foo")
-- divideBy (== '.') ".foo" == ("","foo")
-- divideBy (== '.') "foo." == ("foo","")
-- divideBy (== '.') "foo.bar" == ("foo","bar")
-- divideBy (== '.') "foo.bar.baz" == ("foo.bar","baz")
--
divideBy :: Split s e => (e -> Bool) -> s -> (s, s)
-- | Splits line by separation elements.
splitsBy :: Split s e => (e -> Bool) -> s -> [s]
-- | splitsOn sub line splits line by sub.
--
-- -- splitsOn "fo" "foobar bazfoobar1" == ["","obar baz","obar1"] --splitsOn :: (Split s e, Eq e, Bordered s i) => s -> s -> [s] -- | splitsOn sub line splits line by sub. -- --
-- splitsOn "fo" "foobar bazfoobar1" == ["","obar baz","obar1"] --splitsOn :: (Split s e, Eq e) => s -> s -> [s] -- | replaceBy sub new line replace every non-overlapping -- occurrence of sub in line with new. -- --
-- replaceBy "foo" "bar" "foobafoorbaz" == "barbabarrbaz" --replaceBy :: (Split s e, Eq e) => s -> s -> s -> s -- | Removes every non-overlapping occurrence of sub with -- Z. -- --
-- removeAll = concat ... splitsOn -- (`replaceBy` Z) = removeAll --removeAll :: (Split s e, Eq e) => s -> s -> s -- | combo f es returns the length of the es subsequence -- (left to tight) whose elements are in order f. -- --
-- combo (<) [] == 0 -- combo (<) [1] == 1 -- combo (<) [7, 4, 12] == 1 -- combo (<) [1, 7, 3, 12] == 2 --combo :: Split s e => Equal e -> s -> Int -- | justifyL n e es appends e elements if the -- es is shorter than n, takes n elements if -- longer. justifyL :: Split s e => Int -> e -> s -> s -- | justifyR n e es prepends e elements if the -- es is shorter than n, takes n elements if -- longer. justifyR :: Split s e => Int -> e -> s -> s -- | each n es returns each nth element of structure. If n == -- 1, returns es. If n < 1, returns Z. each :: Split s e => Int -> s -> s -- | eachFrom o n es returns each nth element of structure, -- beginning from o. -- --
-- eachFrom o n = each n . drop o ---- --
-- eachFrom 0 2 [1 .. 20] == [2, 4 .. 20] -- eachFrom 1 2 [1 .. 20] == [3, 5 .. 19] --eachFrom :: Split s e => Int -> Int -> s -> s -- | isPrefixOf checks whether the first line is the beginning of the -- second isPrefixOf :: (Split s e, Eq e) => s -> s -> Bool -- | isSuffixOf checks whether the first line is the ending of the second isSuffixOf :: (Split s e, Eq e) => s -> s -> Bool -- | isInfixOf checks whether the first line is the substring of the second isInfixOf :: (Split s e, Eq e) => s -> s -> Bool -- | prefix gives length of init, satisfying preducate. prefix :: Split s e => (e -> Bool) -> s -> Int -- | suffix gives length of tail, satisfying predicate. suffix :: Split s e => (e -> Bool) -> s -> Int -- | infixes inf es returns a list of inf positions in -- es, without intersections. -- --
-- "" `infixes` es = [] -- "abba" `infixes` "baababba" == [4] -- "abab" `infixes` "baababab" == [2] -- "aaaa" `infixes` "aaaaaaaa" == [0, 4] --infixes :: (Split s e, Eq e) => s -> s -> [Int] -- | dropSide f = dropWhile f . dropEnd f. dropSide :: Split s e => (e -> Bool) -> s -> s -- | Takes the longest init by predicate. takeWhile :: Split s e => (e -> Bool) -> s -> s -- | Drops the longest init by predicate. dropWhile :: Split s e => (e -> Bool) -> s -> s -- | Takes the longest suffix by predicate. takeEnd :: Split s e => (e -> Bool) -> s -> s -- | Drops the longest prefix by predicate. dropEnd :: Split s e => (e -> Bool) -> s -> s -- | Left-side span. spanl :: Split s e => (e -> Bool) -> s -> (s, s) -- | Left-side break. breakl :: Split s e => (e -> Bool) -> s -> (s, s) -- | Right-side span. spanr :: Split s e => (e -> Bool) -> s -> (s, s) -- | Right-side break. breakr :: Split s e => (e -> Bool) -> s -> (s, s) -- | selectWhile f es selects results of applying f to -- es (left to right) untill first fail. selectWhile :: Split s e => (e -> Maybe a) -> s -> [a] -- | selectEnd f es selects results of applying f to -- es (right to left) untill first fail. selectEnd :: Split s e => (e -> Maybe a) -> s -> [a] -- | extractWhile f es selects results of applying f to -- es (left to right) untill first fail. Returns selected -- results and rest of line. extractWhile :: Split s e => (e -> Maybe a) -> s -> ([a], s) -- | extractEnd f es selects results of applying f to -- es (right to left) untill first fail. Returns rest of line -- and selected results. extractEnd :: Split s e => (e -> Maybe a) -> s -> (s, [a]) -- | selectWhile' is selectWhile version for generalized -- structures. selectWhile' :: (Split s e, t e ~ l, Split1 t a) => (e -> Maybe a) -> s -> t a -- | selectEnd' is selectEnd version for generalized -- structures. selectEnd' :: (Split s e, t e ~ l, Split1 t a) => (e -> Maybe a) -> s -> t a -- | extractWhile' is extractWhile version for generalized -- structures. extractWhile' :: (Split s e, t e ~ l, Split1 t a) => (e -> Maybe a) -> s -> (t a, s) -- | extractEnd' is extractEnd version for generalized -- structures. extractEnd' :: (Split s e, t e ~ l, Split1 t a) => (e -> Maybe a) -> s -> (s, t a) -- | Kind (* -> *) Split structure. type Split1 s e = Split (s e) e -- | Pattern (:>) is left-size view of line. Same as -- uncons and toHead. pattern (:>) :: Linear l e => e -> l -> l infixr 5 :> -- | Pattern (:<) is right-size view of line. Same as -- unsnoc and toLast. pattern (:<) :: Linear l e => l -> e -> l infixl 5 :< -- | Z is overloaded empty (lzero) value constant. Pattern -- Z corresponds to all empty (isNull) values. pattern Z :: Nullable e => e -- | intercalate is generalization of intercalate intercalate :: (Foldable f, Linear1 f l, Linear l e) => l -> f l -> l -- | tails es returns sequence of es tails. tails :: Linear l e => l -> [l] -- | tails is generalization of inits. inits :: Linear l e => l -> [l] -- | ascending es lens checks if the subsequences of es -- of lengths lens is sorted. ascending :: (Split s e, Sort s e, Ord e) => s -> [Int] -> Bool -- | stripPrefix sub line strips prefix sub of -- line (if any). stripPrefix :: (Split s e, Bordered s i, Eq e) => s -> s -> s -- | stripSuffix sub line strips suffix sub of -- line (if any). stripSuffix :: (Split s e, Bordered s i, Eq e) => s -> s -> s -- | stripPrefix' sub line strips prefix sub of -- line or returns Nothing. stripPrefix' :: (Split s e, Bordered s i, Eq e) => s -> s -> Maybe s -- | stripSuffix sub line strips suffix sub of -- line or returns Nothing. stripSuffix' :: (Split s e, Bordered s i, Eq e) => s -> s -> Maybe s instance SDP.Linear.Linear [e] e instance SDP.Linear.Split [e] e instance SDP.Index.Index i => SDP.Linear.Bordered (i, i) i instance SDP.Linear.Bordered [e] GHC.Types.Int -- | SDP.Shaped provides advanced operations on Indexed -- structures, generalized by Index type. module SDP.Shaped -- | Service class for structures with arbitrary bounds. Allows you to -- extract subsequences corresponding to index subranges. class Shaped s e -- | rebound with defaultBounds. defaultRebound :: (Shaped s e, Index i, Index j, Bordered2 s i e) => s i e -> s j e -- | Set new bounds of same type, may shrink. rebound :: (Shaped s e, Index i) => s i e -> (i, i) -> s i e -- | Set new bounds, may shrink. reshape :: (Shaped s e, Index i, Index j) => s i e -> (j, j) -> s j e -- | es !! ij returns subshape ij of es. (!!) :: (Shaped s e, SubIndex i j) => s i e -> (i :|: j) -> s j e -- | Returns list of es subshapes. slices :: (Shaped s e, SubIndex i j) => s i e -> [s j e] -- | Unslice subshapes. unslice :: (Shaped s e, Foldable f, SubIndex i j) => f (s j e) -> s i e -- | SDP.Set provides Set - class for basic set operations. module SDP.Set -- | SetWith is a class of data structures, that can represent sets. -- -- SetWith doesn't provide data protection/validation before each -- first action. All functions (except setWith) works correctly -- only with correct sets. SetWith guarantee only that the -- returned data is correct. So if you need maximum reliability and -- security, use containers. But if you want simplicity, -- openness and a lot of non-set functions without extra conversions, -- then you are at the right place. -- -- Note that function of type Compare o must follow total order -- laws (antisymmetry, transitivity and connexity). If you use the wrong -- comparator, the result may become implementation-dependent. class (Nullable s) => SetWith s o | s -> o -- | Creates ordered set from linear structure. setWith :: (SetWith s o, Linear s o) => Compare o -> s -> s -- | Creates ordered set from linear structure. setWith :: SetWith s o => Compare o -> s -> s -- | Creates set from linear structure using additional function for -- choice/merge equal elements. groupSetWith :: (SetWith s o, Linear s o) => Compare o -> (o -> o -> o) -> s -> s -- | Creates set from linear structure using additional function for -- choice/merge equal elements. groupSetWith :: SetWith s o => Compare o -> (o -> o -> o) -> s -> s -- | Adding element to set. insertWith :: (SetWith s o, Linear s o) => Compare o -> o -> s -> s -- | Adding element to set. insertWith :: SetWith s o => Compare o -> o -> s -> s -- | Deleting element from set. deleteWith :: (SetWith s o, Linear s o) => Compare o -> o -> s -> s -- | Deleting element from set. deleteWith :: SetWith s o => Compare o -> o -> s -> s -- | Intersection of two sets. intersectionWith :: SetWith s o => Compare o -> s -> s -> s -- | Difference (relative complement, aka A / B) of two sets. differenceWith :: SetWith s o => Compare o -> s -> s -> s -- | Symmetric difference of two sets. symdiffWith :: SetWith s o => Compare o -> s -> s -> s -- | Union of two sets. unionWith :: SetWith s o => Compare o -> s -> s -> s -- | Fold by intersectionWith. intersectionsWith :: (SetWith s o, Foldable f) => Compare o -> f s -> s -- | Fold by differenceWith. differencesWith :: (SetWith s o, Foldable f) => Compare o -> f s -> s -- | Fold by unionWith. unionsWith :: (SetWith s o, Foldable f) => Compare o -> f s -> s -- | Fold by symdiffWith. symdiffsWith :: (SetWith s o, Foldable f) => Compare o -> f s -> s -- | Compares sets on intersection. isIntersectsWith :: SetWith s o => Compare o -> s -> s -> Bool -- | Compares sets on disjoint. isDisjointWith :: SetWith s o => Compare o -> s -> s -> Bool -- | Same as elem, but can work faster. By default, uses -- find. memberWith :: (SetWith s o, t o ~~ s, Foldable t) => Compare o -> o -> s -> Bool -- | Same as elem, but can work faster. By default, uses -- find. memberWith :: SetWith s o => Compare o -> o -> s -> Bool -- | Сhecks whether a first set is a subset of second. isSubsetWith :: (SetWith s o, t o ~~ s, Foldable t) => Compare o -> s -> s -> Bool -- | Сhecks whether a first set is a subset of second. isSubsetWith :: SetWith s o => Compare o -> s -> s -> Bool -- | Generates a list of different subsets (including empty and -- equivalent). subsets :: (SetWith s o, Linear s o, Ord o) => s -> [s] -- | Generates a list of different subsets (including empty and -- equivalent). subsets :: (SetWith s o, Ord o) => s -> [s] -- | lookupLTWith trying to find lesser element in set. lookupLTWith :: SetWith s o => Compare o -> o -> s -> Maybe o -- | lookupGTWith trying to find greater element in set. lookupGTWith :: SetWith s o => Compare o -> o -> s -> Maybe o -- | lookupGEWith trying to find greater or equal element in set. lookupGEWith :: SetWith s o => Compare o -> o -> s -> Maybe o -- | lookupLEWith trying to find lesser or equal element in set. lookupLEWith :: SetWith s o => Compare o -> o -> s -> Maybe o -- | Kind (* -> *) SetWith. type SetWith1 s o = SetWith (s o) o -- | Set is a class of data structures, that can represent any sets. -- Set is intended for more specific sets than ordered linear -- structures. In particular, it may not work with an arbitrary -- comparator, and also (unlike the early implementation) does not impose -- restrictions on the element type. -- -- Set, as well as SetWith, doesn't provide data -- protection/validation. class (Nullable s) => Set s o | s -> o -- | The same as setWith compare. set :: (Set s o, SetWith s o, Ord o) => s -> s -- | The same as setWith compare. set :: Set s o => s -> s -- | Same as insert compare. insert :: (Set s o, SetWith s o, Ord o) => o -> s -> s -- | Same as insert compare. insert :: Set s o => o -> s -> s -- | Same as deleteWith compare. delete :: (Set s o, SetWith s o, Ord o) => o -> s -> s -- | Same as deleteWith compare. delete :: Set s o => o -> s -> s -- | Same as intersectionWith compare. (/\) :: (Set s o, SetWith s o, Ord o) => s -> s -> s -- | Same as intersectionWith compare. (/\) :: Set s o => s -> s -> s -- | Same as unionWith compare. (\/) :: (Set s o, SetWith s o, Ord o) => s -> s -> s -- | Same as unionWith compare. (\/) :: Set s o => s -> s -> s -- | Same as differenceWith compare. (\\) :: (Set s o, SetWith s o, Ord o) => s -> s -> s -- | Same as differenceWith compare. (\\) :: Set s o => s -> s -> s -- | Same as symdiffWith compare. (\^/) :: (Set s o, SetWith s o, Ord o) => s -> s -> s -- | Same as symdiffWith compare. (\^/) :: Set s o => s -> s -> s -- | Same as isDisjointWith compare. (/?\) :: (Set s o, SetWith s o, Ord o) => s -> s -> Bool -- | Same as isDisjointWith compare. (/?\) :: Set s o => s -> s -> Bool -- | Same as isIntersectsWith compare. (\?/) :: (Set s o, SetWith s o, Ord o) => s -> s -> Bool -- | Same as isIntersectsWith compare. (\?/) :: Set s o => s -> s -> Bool -- | Same as isSubsetWith compare. (\+/) :: (Set s o, SetWith s o, Ord o) => s -> s -> Bool -- | Same as isSubsetWith compare. (\+/) :: Set s o => s -> s -> Bool -- | Same as intersectionsWith compare. intersections :: (Set s o, Foldable f, SetWith s o, Ord o) => f s -> s -- | Same as intersectionsWith compare. intersections :: (Set s o, Foldable f) => f s -> s -- | Same as unionsWith compare. unions :: (Set s o, Foldable f, SetWith s o, Ord o) => f s -> s -- | Same as unionsWith compare. unions :: (Set s o, Foldable f) => f s -> s -- | Same as differencesWith compare. differences :: (Set s o, Foldable f, SetWith s o, Ord o) => f s -> s -- | Same as differencesWith compare. differences :: (Set s o, Foldable f) => f s -> s -- | Same as symdiffsWith compare'. symdiffs :: (Set s o, Foldable f, SetWith s o, Ord o) => f s -> s -- | Same as symdiffsWith compare'. symdiffs :: (Set s o, Foldable f) => f s -> s -- | Same as memberWith compare. member :: (Set s o, SetWith s o, Ord o) => o -> s -> Bool -- | Same as memberWith compare. member :: Set s o => o -> s -> Bool -- | Same as lookupLTWith compare. lookupLT :: (Set s o, SetWith s o, Ord o) => o -> s -> Maybe o -- | Same as lookupLTWith compare. lookupLT :: (Set s o, Ord o) => o -> s -> Maybe o -- | Same as lookupGTWith compare. lookupGT :: (Set s o, SetWith s o, Ord o) => o -> s -> Maybe o -- | Same as lookupGTWith compare. lookupGT :: (Set s o, Ord o) => o -> s -> Maybe o -- | Same as lookupLEWith compare. lookupLE :: (Set s o, SetWith s o, Ord o) => o -> s -> Maybe o -- | Same as lookupLEWith compare. lookupLE :: (Set s o, Ord o) => o -> s -> Maybe o -- | Same as lookupGEWith compare. lookupGE :: (Set s o, SetWith s o, Ord o) => o -> s -> Maybe o -- | Same as lookupGEWith compare. lookupGE :: (Set s o, Ord o) => o -> s -> Maybe o -- | Kind (* -> *) Set. type Set1 s o = Set (s o) o instance GHC.Classes.Ord o => SDP.Set.Set [o] o instance SDP.Set.SetWith [o] o -- | SDP.Scan provides Scan - class for overloaded scans. -- Scan needed for generalization and not so useful is practice as -- other sdp classes. module SDP.Scan -- | Scan is class of scans. class (Linear s a) => Scan s a scanl :: Scan s a => (b -> a -> b) -> b -> s -> [b] scanl' :: Scan s a => (b -> a -> b) -> b -> s -> [b] scanr :: Scan s a => (a -> b -> b) -> b -> s -> [b] scanr' :: Scan s a => (a -> b -> b) -> b -> s -> [b] scanl1 :: Scan s a => (a -> a -> a) -> s -> [a] scanr1 :: Scan s a => (a -> a -> a) -> s -> [a] instance SDP.Scan.Scan [a] a -- | SDP.Map provides Map - class of immutable associative -- arrays. module SDP.Map -- | Map is a class of dictionaries, simple associative arrays with -- an arbitrary (implementation-dependent) key. -- -- In the current implementation, Map (since sdp-0.2) is -- a superclass of Indexed. Map provides a set of -- operations on associative arrays that aren't specific to Linear -- data structures and aren't limited by the Bordered context -- (doesn't restrict key type). class (Nullable map) => Map map key e | map -> key, map -> e -- | Returns list of associations (index, element). assocs :: (Map map key e, Bordered map key, Linear map e) => map -> [(key, e)] -- | Returns list of associations (index, element). assocs :: Map map key e => map -> [(key, e)] -- | A less specific version of "SDP.Indexed.Indexed.assoc" that creates a -- new associative array. For Linear structures without gaps, it -- may be less effective. -- --
-- Z // ascs = toMap -- forall ascs --toMap :: Map map key e => [(key, e)] -> map -- | Strict version of toMap with default value. -- -- Note that the default value is set only for elements included in the -- range of the created structure and will not be set for values outside -- its range (when expanding, concatenating, etc.) for most structures -- since they don't store it. toMap' :: Map map key e => e -> [(key, e)] -> map -- | insert' key e map inserts e with key -- to map. If map already contains an element with -- key, the element will be overwritten. -- -- If map doesn't allow gaps, then the missing elements should -- be filled with default values. insert' :: (Map map key e, Bordered map key) => key -> e -> map -> map -- | insert' key e map inserts e with key -- to map. If map already contains an element with -- key, the element will be overwritten. -- -- If map doesn't allow gaps, then the missing elements should -- be filled with default values. insert' :: Map map key e => key -> e -> map -> map -- | delete' removes element with given key. -- -- If the structure has boundaries, when removed from the beginning -- (end), they should change accordingly. If the structure doesn't allow -- gaps, then when removed from the middle, the actual value should be -- replaced with the default value. delete' :: Map map key e => key -> map -> map -- | delete' removes element with given key. -- -- If the structure has boundaries, when removed from the beginning -- (end), they should change accordingly. If the structure doesn't allow -- gaps, then when removed from the middle, the actual value should be -- replaced with the default value. delete' :: (Map map key e, Eq key) => key -> map -> map -- | member' key map checks if key in -- map. member' :: (Map map key e, Bordered map key) => key -> map -> Bool -- | member' key map checks if key in -- map. member' :: Map map key e => key -> map -> Bool -- | Update elements of immutable structure (by copying). (//) :: Map map key e => map -> [(key, e)] -> map -- | (.!) is unsafe reader, can be faster -- (!) by skipping checks. (.!) :: Map map key e => map -> key -> e -- | (!) is well-safe reader, may throw -- IndexException. (!) :: Map map key e => map -> key -> e -- | (!) is well-safe reader, may throw -- IndexException. (!) :: (Map map key e, Bordered map key) => map -> key -> e -- | (!?) is completely safe, but very boring function. (!?) :: Map map key e => map -> key -> Maybe e -- | Filter with key. filter' :: Map map key e => (key -> e -> Bool) -> map -> map -- | union' is groupSetWith for maps but works with real -- groups of elements, not with consequentive equal elements. -- -- union' merges/chooses elements with equal keys from two maps. union' :: (Map map key e, Ord key) => (e -> e -> e) -> map -> map -> map -- | difference' f mx my applies comb to values -- with equal keys. If f x y (where (k1, x) <- mx, -- (k2, y) <- my, k1 == k2) is Nothing, -- element isn't included to result map. -- -- Note that difference' is poorer than a similar functions in -- containers. difference' :: (Map map key e, Ord key) => (e -> e -> Maybe e) -> map -> map -> map -- | intersection' f mx my combines elements of -- intersection' by f: if isJust (f x y) (where -- (k1, x) <- mx, (k2, y) <- my, k1 == k2), then element -- is added to result map. intersection' :: (Map map key e, Ord key) => (e -> e -> e) -> map -> map -> map -- | Update function, by default uses (!) and may throw -- IndexException. update :: Map map key e => map -> (key -> e -> e) -> map -- | lookupLT' k map finds pair (key, value) with -- smallest key, where key < k (if any). k -- may not be a map element. lookupLT' :: (Map map key e, Ord key) => key -> map -> Maybe (key, e) -- | lookupGT' k map finds pair (key, value) with -- greatest key, where key > k (if any). k -- may not be a map element. lookupGT' :: (Map map key e, Ord key) => key -> map -> Maybe (key, e) -- | lookupLE' k map finds pair (key, value) with -- smallest key, where key <= k (if any). If -- k is a map element, returns (k, e). lookupLE' :: (Map map key e, Ord key) => key -> map -> Maybe (key, e) -- | lookupGE' k map finds pair (key, value) with -- key, where key >= k (if any). lookupGE' :: (Map map key e, Ord key) => key -> map -> Maybe (key, e) -- | Returns list of map keys. keys :: Map map key e => map -> [key] -- | Searches the key of first matching element. (.$) :: Map map key e => (e -> Bool) -> map -> Maybe key -- | Searches the keys of all matching elements. (*$) :: Map map key e => (e -> Bool) -> map -> [key] -- | kfoldr is foldr with key. kfoldr :: Map map key e => (key -> e -> b -> b) -> b -> map -> b -- | kfoldl is foldl with key. kfoldl :: Map map key e => (key -> b -> e -> b) -> b -> map -> b -- | kfoldr' is strict version of kfoldr. kfoldr' :: Map map key e => (key -> e -> b -> b) -> b -> map -> b -- | kfoldl' is strict version of kfoldl. kfoldl' :: Map map key e => (key -> b -> e -> b) -> b -> map -> b infixl 9 ! infixl 9 .! infixl 9 !? -- | Kind (* -> *) Map structure. type Map1 map key e = Map (map e) key e -- | Kind (* -> * -> *) Map structure. type Map2 map key e = Map (map key e) key e instance SDP.Map.Map [e] GHC.Types.Int e -- | SDP.LinearM is a module that provides BorderedM and -- LinearM classes. module SDP.LinearM -- | BorderedM is Bordered version for mutable data -- structures. class (Monad m, Index i) => BorderedM m b i | b -> m, b -> i -- | getBounds returns bounds of mutable data structure. getBounds :: BorderedM m b i => b -> m (i, i) -- | getLower returns lower bound of mutable data structure. getLower :: BorderedM m b i => b -> m i -- | getUpper returns upper bound of mutable data structure. getUpper :: BorderedM m b i => b -> m i -- | getSizeOf returns size of mutable data structure. getSizeOf :: BorderedM m b i => b -> m Int -- | getSizesOf returns sizes of mutable data structure. getSizesOf :: BorderedM m b i => b -> m [Int] -- | nowIndexIn is indexIn version for mutable structures. nowIndexIn :: BorderedM m b i => b -> i -> m Bool -- | getOffsetOf is offsetOf version for mutable structures. getOffsetOf :: BorderedM m b i => b -> i -> m Int -- | getIndexOf is indexOf version for mutable structures. getIndexOf :: BorderedM m b i => b -> Int -> m i -- | getIndices returns indices of mutable data structure. getIndices :: BorderedM m b i => b -> m [i] -- | Kind (* -> *) BorderedM structure. type BorderedM1 m l i e = BorderedM m (l e) i -- | Kind (* -> * -> *) BorderedM structure. type BorderedM2 m l i e = BorderedM m (l i e) i -- | LinearM is Linear version for mutable data structures. -- This class is designed with the possibility of in-place -- implementation, so many operations from Linear have no -- analogues here. class (Monad m) => LinearM m l e | l -> m, l -> e -- | Monadic single. newNull :: LinearM m l e => m l -- | Monadic isNull. nowNull :: LinearM m l e => l -> m Bool -- | Monadic single. singleM :: LinearM m l e => e -> m l -- | getHead is monadic version of head. This procedure -- mustn't modify the source structure or return references to its -- mutable fields. getHead :: LinearM m l e => l -> m e -- | getLast is monadic version of last. This procedure -- mustn't modify the source structure or return references to its -- mutable fields. getLast :: LinearM m l e => l -> m e -- | Prepends new element to the start of the structure (monadic -- toHead). Like most size-changing operations, prepend -- doesn't guarantee the correctness of the original structure after -- conversion. prepend :: LinearM m l e => e -> l -> m l -- | Appends new element to the end of the structure (monadic -- toLast). Like most size-changing operations, append -- doesn't guarantee the correctness of the original structure after -- conversion. append :: LinearM m l e => l -> e -> m l -- | Monadic fromList. newLinear :: LinearM m l e => [e] -> m l -- | Monadic fromListN. newLinearN :: LinearM m l e => Int -> [e] -> m l -- | Monadic fromFoldable. fromFoldableM :: (LinearM m l e, Foldable f) => f e -> m l -- | Left view of line. getLeft :: LinearM m l e => l -> m [e] -- | Right view of line. getRight :: LinearM m l e => l -> m [e] -- | (!#>) is unsafe monadic offset-based reader. (!#>) :: LinearM m l e => l -> Int -> m e -- | Unsafe monadic offset-based writer. writeM :: LinearM m l e => l -> Int -> e -> m () -- | Create copy. copied :: LinearM m l e => l -> m l -- | copied' es l n returns the slice of es from -- l of length n. copied' :: LinearM m l e => l -> Int -> Int -> m l -- | Monadic reverse. reversed :: LinearM m l e => l -> m l -- | Monadic concat. merged :: (LinearM m l e, Foldable f) => f l -> m l -- | Monadic version of replicate. filled :: LinearM m l e => Int -> e -> m l -- | copyTo source soff target toff count writes count -- elements of source from soff to target -- starting with toff. copyTo :: LinearM m l e => l -> Int -> l -> Int -> Int -> m () -- | ofoldrM is right monadic fold with offset. ofoldrM :: LinearM m l e => (Int -> e -> r -> m r) -> r -> l -> m r -- | ofoldlM is left monadic fold with offset. ofoldlM :: LinearM m l e => (Int -> r -> e -> m r) -> r -> l -> m r -- | ofoldrM' is strict version of ofoldrM. ofoldrM' :: LinearM m l e => (Int -> e -> r -> m r) -> r -> l -> m r -- | ofoldrM' is strict version of ofoldrM. ofoldlM' :: LinearM m l e => (Int -> r -> e -> m r) -> r -> l -> m r -- | foldrM is just ofoldrM in Linear context. foldrM :: LinearM m l e => (e -> r -> m r) -> r -> l -> m r -- | foldlM is just ofoldlM in Linear context. foldlM :: LinearM m l e => (r -> e -> m r) -> r -> l -> m r -- | foldrM' is strict version of foldrM. foldrM' :: LinearM m l e => (e -> r -> m r) -> r -> l -> m r -- | foldlM' is strict version of foldlM. foldlM' :: LinearM m l e => (r -> e -> m r) -> r -> l -> m r -- | Just swap two elements. swapM :: LinearM m l e => l -> Int -> Int -> m () infixl 5 !#> -- | Kind (* -> *) LinearM structure. type LinearM1 m l e = LinearM m (l e) e -- | SplitM is Split version for mutable data structures. -- This class is designed with the possibility of in-place -- implementation, so many operations from Split have no analogues -- here. class (LinearM m s e) => SplitM m s e -- | takeM n es returns a reference to the es, keeping -- first n elements. Changes in the source and result must be -- synchronous. takeM :: SplitM m s e => Int -> s -> m s -- | takeM n es returns a reference to the es, keeping -- first n elements. Changes in the source and result must be -- synchronous. takeM :: (SplitM m s e, BorderedM m s i) => Int -> s -> m s -- | dropM n es returns a reference to the es, discarding -- first n elements. Changes in the source and result must be -- synchronous. dropM :: SplitM m s e => Int -> s -> m s -- | dropM n es returns a reference to the es, discarding -- first n elements. Changes in the source and result must be -- synchronous. dropM :: (SplitM m s e, BorderedM m s i) => Int -> s -> m s -- | keepM n es returns a reference to the es, keeping -- last n elements. Changes in the source and result must be -- synchronous. keepM :: SplitM m s e => Int -> s -> m s -- | keepM n es returns a reference to the es, keeping -- last n elements. Changes in the source and result must be -- synchronous. keepM :: (SplitM m s e, BorderedM m s i) => Int -> s -> m s -- | sansM n es returns a reference to the es, discarding -- last n elements. Changes in the source and result must be -- synchronous. sansM :: SplitM m s e => Int -> s -> m s -- | sansM n es returns a reference to the es, discarding -- last n elements. Changes in the source and result must be -- synchronous. sansM :: (SplitM m s e, BorderedM m s i) => Int -> s -> m s -- | splitM n es returns pair of references to the es: -- keeping and discarding first n elements. Changes in the -- source and result must be synchronous. splitM :: SplitM m s e => Int -> s -> m (s, s) -- | divideM n es returns pair of references to the es: -- discarding and keeping last n elements. Changes in the source -- and results must be synchronous. divideM :: SplitM m s e => Int -> s -> m (s, s) -- | splitM ns es returns the sequence of es prefix -- references of length n <- ns. Changes in the source and -- results must be synchronous. splitsM :: (SplitM m s e, Foldable f) => f Int -> s -> m [s] -- | dividesM ns es returns the sequence of es suffix -- references of length n <- ns. Changes in the source and -- results must be synchronous. dividesM :: (SplitM m s e, Foldable f) => f Int -> s -> m [s] -- | partsM n es returns the sequence of es prefix -- references, splitted by offsets in es. Changes in the source -- and results must be synchronous. partsM :: (SplitM m s e, Foldable f) => f Int -> s -> m [s] -- | chunksM n es returns the sequence of es prefix -- references of length n. Changes in the source and results -- must be synchronous. chunksM :: SplitM m s e => Int -> s -> m [s] -- | eachM n es returns new sequence of es elements with -- step n. eachM shouldn't return references to es. eachM :: SplitM m s e => Int -> s -> m s -- | prefixM p es returns the longest es prefix size, -- satisfying p. prefixM :: SplitM m s e => (e -> Bool) -> s -> m Int -- | suffixM p es returns the longest es suffix size, -- satisfying p. suffixM :: SplitM m s e => (e -> Bool) -> s -> m Int -- | mprefix p es returns the longest es prefix size, -- satisfying p. mprefix :: SplitM m s e => (e -> m Bool) -> s -> m Int -- | msuffix p es returns the longest es suffix size, -- satisfying p. msuffix :: SplitM m s e => (e -> m Bool) -> s -> m Int -- | Kind (* -> *) SplitM structure. type SplitM1 m l e = SplitM m (l e) e -- | SDP.MapM provides MapM - class of mutable associative -- arrays. module SDP.MapM -- | MapM is class of mutable associative arrays. class (Monad m) => MapM m map key e | map -> m, map -> key, map -> e -- | Create new mutable map from list of (key, element) -- associations. newMap :: MapM m map key e => [(key, e)] -> m map -- | Create new mutable map from list of (key, element) -- associations. newMap' :: MapM m map key e => e -> [(key, e)] -> m map -- | getAssocs is version of assocs for mutable maps. getAssocs :: (MapM m map key e, LinearM m map e) => map -> m [(key, e)] -- | getAssocs is version of assocs for mutable maps. getAssocs :: MapM m map key e => map -> m [(key, e)] -- | (>!) is unsafe monadic reader. (>!) :: MapM m map key e => map -> key -> m e -- | (!>) is well-safe monadic reader. (!>) :: (MapM m map key e, BorderedM m map key) => map -> key -> m e -- | (!>) is well-safe monadic reader. (!>) :: MapM m map key e => map -> key -> m e -- | (!?>) is completely safe monadic reader. (!?>) :: MapM m map key e => map -> key -> m (Maybe e) -- | Update elements by mapping with indices. updateM :: MapM m map key e => map -> (key -> e -> e) -> m map -- | This function designed to overwrite large enough fragments of the -- structure (unlike writeM and writeM') -- -- In addition to write operations, overwrite can move and clean, -- optimize data presentation, etc. of a particular structure. Since the -- reference to the original structure may not be the same as reference -- to the result (which implementation is undesirable, but acceptable), -- the original reference (argument) shouldn't be used after -- overwrite. -- -- All standard sdp structures support safe in-place -- overwrite. -- -- If the structure uses unmanaged memory, then all unused fragments in -- the resulting structure must be deallocated, regardless of -- reachability by original reference (argument). -- -- Please note that overwrite require a list of associations -- with indices in the current structure bounds and ignore any other, -- therefore: -- --
-- fromAssocs bnds ascs /= (fromAssocs bnds ascs >>= flip overwrite ascs) --overwrite :: MapM m map key e => map -> [(key, e)] -> m map -- | Checks if key in map. memberM' :: (MapM m map key e, BorderedM m map key) => map -> key -> m Bool -- | Checks if key in map. memberM' :: MapM m map key e => map -> key -> m Bool -- | Returns list of map keys. getKeys :: (MapM m map key e, BorderedM m map key) => map -> m [key] -- | Returns list of map keys. getKeys :: MapM m map key e => map -> m [key] -- | (.?) is monadic version of (.$). (.?) :: MapM m map key e => (e -> Bool) -> map -> m (Maybe key) -- | (*?) is monadic version of (*$). (*?) :: MapM m map key e => (e -> Bool) -> map -> m [key] -- | kfoldrM is right monadic fold with key. kfoldrM :: MapM m map key e => (key -> e -> acc -> m acc) -> acc -> map -> m acc -- | kfoldlM is left monadic fold with key. kfoldlM :: MapM m map key e => (key -> acc -> e -> m acc) -> acc -> map -> m acc -- | kfoldrM' is strict version of kfoldrM. kfoldrM' :: MapM m map key e => (key -> e -> acc -> m acc) -> acc -> map -> m acc -- | kfoldlM' is strict version of kfoldlM. kfoldlM' :: MapM m map key e => (key -> acc -> e -> m acc) -> acc -> map -> m acc infixl 5 >! infixl 5 !> infixl 5 !?> -- | Rank (* -> *) MapM. type MapM1 m map key e = MapM m (map e) key e -- | Rank (* -> * -> *) MapM. type MapM2 m map key e = MapM m (map key e) key e -- | SDP.Indexed provides Indexed and Freeze classes. module SDP.Indexed -- | Indexed is class of ordered associative arrays with static -- bounds. class (Linear v e, Bordered v i, Map v i e) => Indexed v i e | v -> i, v -> e -- | assoc bnds ascs create new structure from list of -- associations, without default element. Note that bnds is -- ascs bounds and may not match with the result bounds (not -- always possible). assoc :: Indexed v i e => (i, i) -> [(i, e)] -> v -- | assoc' bnds def ascs creates new structure from list of -- associations with default element. Note that bnds is -- ascs bounds and may not match with the result bounds (not -- always possible). assoc' :: Indexed v i e => (i, i) -> e -> [(i, e)] -> v -- | fromIndexed converts this indexed structure to another one. fromIndexed :: (Indexed v i e, Indexed m j e) => m -> v -- | Safe index-based immutable writer. write' :: Indexed v i e => v -> i -> e -> v -- | accum f es ies create a new structure from es -- elements selectively updated by function f and ies -- associations list. accum :: Indexed v i e => (e -> e' -> e) -> v -> [(i, e')] -> v -- | imap creates new indexed structure from old with reshaping. imap :: (Indexed v i e, Map m j e) => (i, i) -> m -> (i -> j) -> v -- | Update element by given function. update' :: Indexed v i e => v -> (e -> e) -> i -> v -- | Create new structure from old by mapping with index. updates' :: Indexed v i e => v -> (i -> e -> e) -> v -- | Kind (* -> *) Indexed structure. type Indexed1 v i e = Indexed (v e) i e -- | Kind (* -> * -> *) Indexed structure. type Indexed2 v i e = Indexed (v i e) i e -- | binaryContain checks that sorted structure has equal element. binaryContain :: (Linear v e, Bordered v i) => Compare e -> e -> v -> Bool -- | Service class of mutable to immutable conversions. class (Monad m) => Freeze m v' v | v' -> m -- | freeze is a safe way to convert a mutable structure to a -- immutable. freeze should copy the old structure or ensure -- that it will not be used after calling the procedure. freeze :: Freeze m v' v => v' -> m v -- | unsafeFreeze is unsafe version of freeze. -- unsafeFreeze doesn't guarantee that the structure will be -- copied or locked. It only guarantees that if the old structure isn't -- used, no error will occur. unsafeFreeze :: Freeze m v' v => v' -> m v -- | Kind (* -> *) Freeze. type Freeze1 m v' v e = Freeze m (v' e) (v e) instance SDP.Indexed.Indexed [e] GHC.Types.Int e -- | SDP.IndexedM provides IndexedM and Thaw classes. module SDP.IndexedM -- | Class for work with mutable indexed structures. class (LinearM m v e, BorderedM m v i, MapM m v i e) => IndexedM m v i e -- | fromAssocs bnds ascs creates new structure from list of -- associations, without default element. Note that bnds is -- ascs bounds and may not match with the result bounds (not -- always possible). fromAssocs :: IndexedM m v i e => (i, i) -> [(i, e)] -> m v -- | fromAssocs' bnds defvalue ascs creates new structure from -- list of associations, with default element. Note that bnds is -- ascs bounds and may not match with the result bounds (not -- always possible). fromAssocs' :: IndexedM m v i e => (i, i) -> e -> [(i, e)] -> m v -- | writeM map key e writes element e to -- key position safely (if key is out of map -- range, do nothing). The writeM function is intended to -- overwrite only existing values, so its behavior is identical for -- structures with both static and dynamic boundaries. writeM' :: IndexedM m v i e => v -> i -> e -> m () -- | Just swap two elements. swapM' :: IndexedM m v i e => v -> i -> i -> m () -- | fromIndexed' is overloaded version of thaw. fromIndexed' :: (IndexedM m v i e, Indexed v' j e) => v' -> m v -- | fromIndexed converts one mutable structure to other. fromIndexedM :: (IndexedM m v i e, IndexedM m v' j e) => v' -> m v -- | reshaped creates new indexed structure from old with reshaping -- function. reshaped :: (IndexedM m v i e, IndexedM m v' j e) => (i, i) -> v' -> (i -> j) -> m v -- | fromAccum f es ies create a new structure from -- es elements selectively updated by function f and -- ies associations list. fromAccum :: IndexedM m v i e => (e -> e' -> e) -> v -> [(i, e')] -> m v -- | Update element by given function. updateM' :: IndexedM m v i e => v -> (e -> e) -> i -> m () -- | Kind (* -> *) IndexedM. type IndexedM1 m v i e = IndexedM m (v e) i e -- | Kind (* -> * -> *) IndexedM. type IndexedM2 m v i e = IndexedM m (v i e) i e -- | Service class of immutable to mutable conversions. class (Monad m) => Thaw m v v' | v' -> m -- | thaw is safe way to convert a immutable structure to a -- mutable. thaw should copy the old structure or ensure that it -- will not be used after the procedure calling. thaw :: Thaw m v v' => v -> m v' -- | unsafeThaw is unsafe version of thaw. -- unsafeThaw doesn't guarantee that the structure will be -- copied or locked. It only guarantees that if the old structure isn't -- used, no error will occur. unsafeThaw :: Thaw m v v' => v -> m v' -- | Kind (* -> *) Thaw. type Thaw1 m v v' e = Thaw m (v e) (v' e) -- | SDP.SortM.Insertion provides insertion sort - simple sorting -- algorithm. module SDP.SortM.Insertion -- | insertionSort is just synonym for insertionSortBy -- compare. insertionSort :: (LinearM m v e, BorderedM m v i, Ord e) => v -> m () -- | insertionSortBy is naive service sorting procedure, that have -- O(n^2) complexity in all cases. insertionSortBy :: (LinearM m v e, BorderedM m v i) => Compare e -> v -> m () -- | insertionSortOn is a version of insertionSortBy that -- uses a cast function to compare elements. insertionSortOn :: (LinearM m v e, BorderedM m v i, Ord o) => (e -> o) -> v -> m () -- | unsafeInsertionSort cmp es b s e is internal sorting procedure, where -- cmp - compare function, es - data structure, [b -- .. s] - sorted range, [b .. e] - sortable range. unsafeInsertionSort :: LinearM m v e => Compare e -> v -> Int -> Int -> Int -> m () -- | SDP.SortM.Tim provides InsertionSort and -- TimSort algorithms. module SDP.SortM.Tim -- | timSort is just synonym for timSortBy -- compare. timSort :: (LinearM m v e, BorderedM m v i, Ord e) => v -> m () -- | timSortBy is a sorting procedure for mutable random access data -- structures using any comparison function and having O(nlogn) -- complexity in the worst case. timSortBy :: (LinearM m v e, BorderedM m v i) => Compare e -> v -> m () -- | timSortOn is a version of timSortBy that uses a -- conversion function to compare elements. timSortOn :: (LinearM m v e, BorderedM m v i, Ord o) => (e -> o) -> v -> m () -- | minrunTS returns TimSort chunk size by given length. minrunTS :: Int -> Int -- | SDP.Prim.SBytes provides strict unboxed array pseudo-primitive -- types SBytes#, STBytes# and IOBytes#. module SDP.Prim.SBytes -- | MIOBytes# is mutable pseudo-primitive Int-indexed strict -- unboxed array. newtype MIOBytes# (io :: Type -> Type) e MIOBytes# :: STBytes# RealWorld e -> MIOBytes# (io :: Type -> Type) e -- | IOBytes# is mutable pseudo-primitive Int-indexed strict -- unboxed array. type IOBytes# = MIOBytes# IO -- | STBytes# is mutable pseudo-primitive Int-indexed strict -- unboxed array type. data STBytes# s e -- | SBytes# is immutable pseudo-primitive Int-indexed strict -- unboxed array type. -- -- SBytes# isn't real Haskell primitive (like GHC.Exts -- types) but for reliability and stability, I made it inaccessible to -- direct work. data SBytes# e -- | fromSBytes# returns new ByteArray#. fromSBytes# :: Unboxed e => SBytes# e -> ByteArray# -- | packSBytes# creates new SBytes# from sized -- ByteArray#. packSBytes# :: Unboxed e => Int -> ByteArray# -> SBytes# e -- | unpackSBytes# returns ByteArray# field of -- SBytes#. unpackSBytes# :: Unboxed e => SBytes# e -> ByteArray# -- | offsetSBytes# returns SBytes# offset in elements. offsetSBytes# :: Unboxed e => SBytes# e -> Int -- | fromSTBytes# returns new MutableByteArray#. fromSTBytes# :: Unboxed e => STBytes# s e -> State# s -> (# State# s, MutableByteArray# s #) -- | packSTBytes# creates new STBytes# from sized -- MutableByteArray#. packSTBytes# :: Unboxed e => Int -> MutableByteArray# s -> STBytes# s e -- | unpackSTBytes# returns MutableByteArray# field of -- STBytes#. unpackSTBytes# :: Unboxed e => STBytes# s e -> MutableByteArray# s -- | offsetSTBytes# returns STBytes# offset in bytes. offsetSTBytes# :: Unboxed e => STBytes# s e -> Int# -- | unsafeCoerceSBytes# is unsafe low-lowel coerce of an array with -- recounting the number of elements and offset (with possible rounding). unsafeCoerceSBytes# :: (Unboxed a, Unboxed b) => SBytes# a -> SBytes# b -- | unsafeCoerceSTBytes# is unsafe low-lowel coerce of an mutable -- array with recounting the number of elements and offset (with possible -- rounding). unsafeCoerceSTBytes# :: (Unboxed a, Unboxed b) => STBytes# s a -> STBytes# s b -- | unsafeSBytesToPtr# es byte-wise stores SBytes# -- content to Ptr. Returns the number of overwritten elements and -- a pointer to psizeof es (sizeOf es) bytes of allocated -- memory. unsafeSBytesToPtr# :: Unboxed e => SBytes# e -> IO (Int, Ptr e) -- | unsafePtrToSBytes# n ptr byte-wise stores n -- elements of Ptr ptr to SBytes#. unsafePtrToSBytes# :: Unboxed e => (Int, Ptr e) -> IO (SBytes# e) -- | Calculate hash SBytes# using hashUnboxedWith. hashSBytesWith# :: Unboxed e => Int -> SBytes# e -> Int instance GHC.Classes.Eq (SDP.Prim.SBytes.MIOBytes# io e) instance SDP.Estimate.Estimate (SDP.Prim.SBytes.MIOBytes# io e) instance SDP.Linear.Bordered (SDP.Prim.SBytes.MIOBytes# io e) GHC.Types.Int instance Control.Monad.IO.Class.MonadIO io => SDP.LinearM.BorderedM io (SDP.Prim.SBytes.MIOBytes# io e) GHC.Types.Int instance (Control.Monad.IO.Class.MonadIO io, SDP.Unboxed.Unboxed e) => SDP.LinearM.LinearM io (SDP.Prim.SBytes.MIOBytes# io e) e instance (Control.Monad.IO.Class.MonadIO io, SDP.Unboxed.Unboxed e) => SDP.LinearM.SplitM io (SDP.Prim.SBytes.MIOBytes# io e) e instance (Control.Monad.IO.Class.MonadIO io, SDP.Unboxed.Unboxed e) => SDP.MapM.MapM io (SDP.Prim.SBytes.MIOBytes# io e) GHC.Types.Int e instance (Control.Monad.IO.Class.MonadIO io, SDP.Unboxed.Unboxed e) => SDP.IndexedM.IndexedM io (SDP.Prim.SBytes.MIOBytes# io e) GHC.Types.Int e instance (Control.Monad.IO.Class.MonadIO io, SDP.Unboxed.Unboxed e) => SDP.SortM.SortM io (SDP.Prim.SBytes.MIOBytes# io e) e instance (Control.Monad.IO.Class.MonadIO io, SDP.Unboxed.Unboxed e) => SDP.IndexedM.Thaw io (SDP.Prim.SBytes.SBytes# e) (SDP.Prim.SBytes.MIOBytes# io e) instance (Control.Monad.IO.Class.MonadIO io, SDP.Unboxed.Unboxed e) => SDP.Indexed.Freeze io (SDP.Prim.SBytes.MIOBytes# io e) (SDP.Prim.SBytes.SBytes# e) instance (Foreign.Storable.Storable e, SDP.Unboxed.Unboxed e) => SDP.Indexed.Freeze GHC.Types.IO (GHC.Types.Int, GHC.Ptr.Ptr e) (SDP.Prim.SBytes.SBytes# e) instance SDP.Nullable.Nullable (SDP.Prim.SBytes.SBytes# e) instance Data.Default.Class.Default (SDP.Prim.SBytes.SBytes# e) instance SDP.Unboxed.Unboxed e => SDP.Linear.Linear (SDP.Prim.SBytes.SBytes# e) e instance SDP.Unboxed.Unboxed e => SDP.IndexedM.Thaw (GHC.ST.ST s) (SDP.Prim.SBytes.SBytes# e) (SDP.Prim.SBytes.STBytes# s e) instance SDP.Unboxed.Unboxed e => SDP.Indexed.Freeze (GHC.ST.ST s) (SDP.Prim.SBytes.STBytes# s e) (SDP.Prim.SBytes.SBytes# e) instance GHC.Classes.Eq (SDP.Prim.SBytes.STBytes# s e) instance SDP.Estimate.Estimate (SDP.Prim.SBytes.STBytes# s e) instance SDP.Linear.Bordered (SDP.Prim.SBytes.STBytes# s e) GHC.Types.Int instance SDP.LinearM.BorderedM (GHC.ST.ST s) (SDP.Prim.SBytes.STBytes# s e) GHC.Types.Int instance SDP.Unboxed.Unboxed e => SDP.LinearM.LinearM (GHC.ST.ST s) (SDP.Prim.SBytes.STBytes# s e) e instance SDP.Unboxed.Unboxed e => SDP.LinearM.SplitM (GHC.ST.ST s) (SDP.Prim.SBytes.STBytes# s e) e instance SDP.Unboxed.Unboxed e => SDP.MapM.MapM (GHC.ST.ST s) (SDP.Prim.SBytes.STBytes# s e) GHC.Types.Int e instance SDP.Unboxed.Unboxed e => SDP.IndexedM.IndexedM (GHC.ST.ST s) (SDP.Prim.SBytes.STBytes# s e) GHC.Types.Int e instance SDP.Unboxed.Unboxed e => SDP.SortM.SortM (GHC.ST.ST s) (SDP.Prim.SBytes.STBytes# s e) e instance SDP.Unboxed.Unboxed e => GHC.Classes.Eq (SDP.Prim.SBytes.SBytes# e) instance (SDP.Unboxed.Unboxed e, GHC.Classes.Ord e) => GHC.Classes.Ord (SDP.Prim.SBytes.SBytes# e) instance (SDP.Unboxed.Unboxed e, GHC.Show.Show e) => GHC.Show.Show (SDP.Prim.SBytes.SBytes# e) instance (SDP.Unboxed.Unboxed e, GHC.Read.Read e) => GHC.Read.Read (SDP.Prim.SBytes.SBytes# e) instance Data.String.IsString (SDP.Prim.SBytes.SBytes# GHC.Types.Char) instance SDP.Unboxed.Unboxed e => GHC.Exts.IsList (SDP.Prim.SBytes.SBytes# e) instance SDP.Unboxed.Unboxed e => GHC.Base.Semigroup (SDP.Prim.SBytes.SBytes# e) instance SDP.Unboxed.Unboxed e => GHC.Base.Monoid (SDP.Prim.SBytes.SBytes# e) instance SDP.Estimate.Estimate (SDP.Prim.SBytes.SBytes# e) instance SDP.Unboxed.Unboxed e => SDP.Linear.Split (SDP.Prim.SBytes.SBytes# e) e instance SDP.Linear.Bordered (SDP.Prim.SBytes.SBytes# e) GHC.Types.Int instance (SDP.Unboxed.Unboxed e, GHC.Classes.Ord e) => SDP.Set.Set (SDP.Prim.SBytes.SBytes# e) e instance SDP.Unboxed.Unboxed e => SDP.Set.SetWith (SDP.Prim.SBytes.SBytes# e) e instance SDP.Unboxed.Unboxed e => SDP.Scan.Scan (SDP.Prim.SBytes.SBytes# e) e instance SDP.Unboxed.Unboxed e => SDP.Sort.Sort (SDP.Prim.SBytes.SBytes# e) e instance SDP.Unboxed.Unboxed e => SDP.Map.Map (SDP.Prim.SBytes.SBytes# e) GHC.Types.Int e instance SDP.Unboxed.Unboxed e => SDP.Indexed.Indexed (SDP.Prim.SBytes.SBytes# e) GHC.Types.Int e instance (Foreign.Storable.Storable e, SDP.Unboxed.Unboxed e) => SDP.IndexedM.Thaw GHC.Types.IO (SDP.Prim.SBytes.SBytes# e) (GHC.Types.Int, GHC.Ptr.Ptr e) -- | SDP.Prim.SArray provides lazy boxed array pseudo-primitive -- types SArray#, STArray# and IOArray#. module SDP.Prim.SArray -- | MIOArray# is mutable preudo-primitive Int-indexed lazy -- boxed array. newtype MIOArray# (io :: Type -> Type) e MIOArray# :: STArray# RealWorld e -> MIOArray# (io :: Type -> Type) e -- | IOArray# is mutable preudo-primitive Int-indexed lazy -- boxed array. type IOArray# = MIOArray# IO -- | STArray# is mutable preudo-primitive Int-indexed lazy -- boxed array type. data STArray# s e -- | SArray# is immutable pseudo-primitive Int-indexed lazy -- boxed array type. -- -- SArray# isn't real Haskell primitive (like GHC.Exts -- types) but for reliability and stability, I made it inaccessible to -- direct work. data SArray# e -- | fromSArray# returns new Array# (uses -- cloneArray#). fromSArray# :: SArray# e -> Array# e -- | fromSTArray# returns new MutableArray#. fromSTArray# :: STArray# s e -> State# s -> (# State# s, MutableArray# s e #) -- | unpackSArray# returns MutableArray# field of -- SArray#. unpackSArray# :: SArray# e -> Array# e -- | offsetSArray# returns SArray# offset in elements. offsetSArray# :: SArray# e -> Int# -- | unpackSTArray# returns MutableArray# field of -- STArray# or fails. unpackSTArray# :: STArray# s e -> MutableArray# s e -- | offsetSTArray# returns STArray# offset in elements. offsetSTArray# :: STArray# s e -> Int# -- | packSArray# creates new SArray# from sized -- Array#. packSArray# :: Int -> Array# e -> SArray# e -- | packSTArray# creates new STArray# from sized -- MutableArray#. packSTArray# :: Int -> MutableArray# s e -> STArray# s e -- | coerceSArray# is coerce alias. coerceSArray# :: Coercible a b => SArray# a -> SArray# b -- | coerceSTArray# is coerce alias. coerceSTArray# :: Coercible a b => STArray# s a -> STArray# s b instance GHC.Classes.Eq (SDP.Prim.SArray.MIOArray# io e) instance SDP.Estimate.Estimate (SDP.Prim.SArray.MIOArray# io e) instance SDP.Linear.Bordered (SDP.Prim.SArray.MIOArray# io e) GHC.Types.Int instance Control.Monad.IO.Class.MonadIO io => SDP.LinearM.BorderedM io (SDP.Prim.SArray.MIOArray# io e) GHC.Types.Int instance Control.Monad.IO.Class.MonadIO io => SDP.LinearM.LinearM io (SDP.Prim.SArray.MIOArray# io e) e instance Control.Monad.IO.Class.MonadIO io => SDP.LinearM.SplitM io (SDP.Prim.SArray.MIOArray# io e) e instance Control.Monad.IO.Class.MonadIO io => SDP.MapM.MapM io (SDP.Prim.SArray.MIOArray# io e) GHC.Types.Int e instance Control.Monad.IO.Class.MonadIO io => SDP.IndexedM.IndexedM io (SDP.Prim.SArray.MIOArray# io e) GHC.Types.Int e instance Control.Monad.IO.Class.MonadIO io => SDP.SortM.SortM io (SDP.Prim.SArray.MIOArray# io e) e instance Control.Monad.IO.Class.MonadIO io => SDP.IndexedM.Thaw io (SDP.Prim.SArray.SArray# e) (SDP.Prim.SArray.MIOArray# io e) instance Control.Monad.IO.Class.MonadIO io => SDP.Indexed.Freeze io (SDP.Prim.SArray.MIOArray# io e) (SDP.Prim.SArray.SArray# e) instance Foreign.Storable.Storable e => SDP.Indexed.Freeze GHC.Types.IO (GHC.Types.Int, GHC.Ptr.Ptr e) (SDP.Prim.SArray.SArray# e) instance SDP.Linear.Linear (SDP.Prim.SArray.SArray# e) e instance SDP.IndexedM.Thaw (GHC.ST.ST s) (SDP.Prim.SArray.SArray# e) (SDP.Prim.SArray.STArray# s e) instance SDP.Indexed.Freeze (GHC.ST.ST s) (SDP.Prim.SArray.STArray# s e) (SDP.Prim.SArray.SArray# e) instance GHC.Classes.Eq (SDP.Prim.SArray.STArray# s e) instance SDP.Estimate.Estimate (SDP.Prim.SArray.STArray# s e) instance SDP.Linear.Bordered (SDP.Prim.SArray.STArray# s e) GHC.Types.Int instance SDP.LinearM.BorderedM (GHC.ST.ST s) (SDP.Prim.SArray.STArray# s e) GHC.Types.Int instance SDP.LinearM.LinearM (GHC.ST.ST s) (SDP.Prim.SArray.STArray# s e) e instance SDP.LinearM.SplitM (GHC.ST.ST s) (SDP.Prim.SArray.STArray# s e) e instance SDP.MapM.MapM (GHC.ST.ST s) (SDP.Prim.SArray.STArray# s e) GHC.Types.Int e instance SDP.IndexedM.IndexedM (GHC.ST.ST s) (SDP.Prim.SArray.STArray# s e) GHC.Types.Int e instance SDP.SortM.SortM (GHC.ST.ST s) (SDP.Prim.SArray.STArray# s e) e instance GHC.Classes.Eq e => GHC.Classes.Eq (SDP.Prim.SArray.SArray# e) instance Data.Functor.Classes.Eq1 SDP.Prim.SArray.SArray# instance GHC.Classes.Ord e => GHC.Classes.Ord (SDP.Prim.SArray.SArray# e) instance Data.Functor.Classes.Ord1 SDP.Prim.SArray.SArray# instance GHC.Show.Show e => GHC.Show.Show (SDP.Prim.SArray.SArray# e) instance GHC.Read.Read e => GHC.Read.Read (SDP.Prim.SArray.SArray# e) instance Data.String.IsString (SDP.Prim.SArray.SArray# GHC.Types.Char) instance GHC.Exts.IsList (SDP.Prim.SArray.SArray# e) instance SDP.Nullable.Nullable (SDP.Prim.SArray.SArray# e) instance GHC.Base.Semigroup (SDP.Prim.SArray.SArray# e) instance GHC.Base.Monoid (SDP.Prim.SArray.SArray# e) instance Data.Default.Class.Default (SDP.Prim.SArray.SArray# e) instance SDP.Estimate.Estimate (SDP.Prim.SArray.SArray# e) instance GHC.Base.Functor SDP.Prim.SArray.SArray# instance SDP.Zip.Zip SDP.Prim.SArray.SArray# instance GHC.Base.Applicative SDP.Prim.SArray.SArray# instance Data.Foldable.Foldable SDP.Prim.SArray.SArray# instance Data.Traversable.Traversable SDP.Prim.SArray.SArray# instance SDP.Linear.Split (SDP.Prim.SArray.SArray# e) e instance SDP.Linear.Bordered (SDP.Prim.SArray.SArray# e) GHC.Types.Int instance GHC.Classes.Ord e => SDP.Set.Set (SDP.Prim.SArray.SArray# e) e instance SDP.Set.SetWith (SDP.Prim.SArray.SArray# e) e instance SDP.Scan.Scan (SDP.Prim.SArray.SArray# e) e instance SDP.Sort.Sort (SDP.Prim.SArray.SArray# e) e instance SDP.Map.Map (SDP.Prim.SArray.SArray# e) GHC.Types.Int e instance SDP.Indexed.Indexed (SDP.Prim.SArray.SArray# e) GHC.Types.Int e instance Foreign.Storable.Storable e => SDP.IndexedM.Thaw GHC.Types.IO (SDP.Prim.SArray.SArray# e) (GHC.Types.Int, GHC.Ptr.Ptr e) -- | SDP.Prim.TArray provides lazy boxed array of stm -- TVars. Note that TArray# stores each element in -- TVar. module SDP.Prim.TArray -- | SArray# of stm TVars. newtype TArray# e TArray# :: SArray# (TVar e) -> TArray# e -- | A monad supporting atomic memory transactions. data STM a -- | Shared memory locations that support atomic memory transactions. data TVar a instance GHC.Classes.Eq (SDP.Prim.TArray.TArray# e) instance SDP.Nullable.Nullable (SDP.Prim.TArray.TArray# e) instance SDP.Estimate.Estimate (SDP.Prim.TArray.TArray# e) instance SDP.Linear.Bordered (SDP.Prim.TArray.TArray# e) GHC.Types.Int instance SDP.LinearM.BorderedM GHC.Conc.Sync.STM (SDP.Prim.TArray.TArray# e) GHC.Types.Int instance SDP.LinearM.LinearM GHC.Conc.Sync.STM (SDP.Prim.TArray.TArray# e) e instance SDP.LinearM.SplitM GHC.Conc.Sync.STM (SDP.Prim.TArray.TArray# e) e instance SDP.MapM.MapM GHC.Conc.Sync.STM (SDP.Prim.TArray.TArray# e) GHC.Types.Int e instance SDP.IndexedM.IndexedM GHC.Conc.Sync.STM (SDP.Prim.TArray.TArray# e) GHC.Types.Int e instance SDP.IndexedM.Thaw GHC.Conc.Sync.STM (SDP.Prim.SArray.SArray# e) (SDP.Prim.TArray.TArray# e) instance SDP.Indexed.Freeze GHC.Conc.Sync.STM (SDP.Prim.TArray.TArray# e) (SDP.Prim.SArray.SArray# e) -- | Text.Read.SDP provides common ReadPrec parsers and -- related stuff. module Text.Read.SDP expect :: Lexeme -> ReadP () appPrec :: Int -- | linearPrec ident is common parser of Linear -- structure with name ident: -- --
-- read "Z" == read "[]" == [] -- read "['l','g','p','l']" == fromList "lgpl" -- read "4 [1,5,-1,45,12,6,0,0,12]" == fromListN 4 [1,5,-1,45,12,6,0,0,12] --linearPrec :: (Linear l e, Read e) => String -> ReadPrec l -- | indexedPrec ident is common parser of Indexed -- structure with name ident: -- --
-- read "ident (0,1) [(0,0),(1,1)]" == read "(0,1) [(0,0),(1,1)]" == assoc (0,1) [(0,0),(1,1)] --indexedPrec :: (Indexed v i e, Read i, Read e) => String -> ReadPrec v -- | indexedPrec' is common Linear and Indexed parser -- (recommended). indexedPrec' :: (Indexed v i e, Read i, Read e) => String -> ReadPrec v -- | readZeroPrec is just Z parser, see linearPrec. readZeroPrec :: Linear l e => ReadPrec l -- | readAsList is fromList-based parser, see -- linearPrec. readAsList :: (Linear l e, Read e) => ReadPrec l -- | readAsListN is fromListN-based parser, see -- linearPrec. readAsListN :: (Linear l e, Read e) => ReadPrec l -- | readAssocsPrec is sdp recommended format -- ReadPrec parser for Indexed. readAssocsPrec :: (Indexed v i e, Read i, Read e) => ReadPrec v -- | allPrec is just allPrecWith readPrec allPrec :: Read e => ReadPrec [e] -- | allPrecWith is manyTill-based combinator, which reads a -- sequence of elements without any separators: -- --
-- readBy allPrecWith readPrec "1 2 3 4 5 6 7" :: [Int] == [1 .. 7] --allPrecWith :: ReadPrec e -> ReadPrec [e] -- | Just lifted expect. expectPrec :: Lexeme -> ReadPrec () -- | namedPrec readprec name is readPrec with -- optional name prefix. namedPrec :: ReadPrec e -> String -> ReadPrec e -- | read with implicit default value. readDef :: (Read e, Default e) => String -> e -- | readBy is generalized read. readBy :: ReadPrec e -> String -> e -- | readMaybeBy is generalized readMaybe. readMaybeBy :: ReadPrec e -> String -> Maybe e -- | readEitherBy is generalized readEither. readEitherBy :: ReadPrec e -> String -> Either String e -- | readBy with implicit default value. readDefBy :: Default e => ReadPrec e -> String -> e -- | Common Enum parser. readAsEnum :: (Linear l e, Read e, Enum e) => ReadPrec l -- | enumFrom parser: -- --
-- take 5 (readBy enumFromPrec "[1 ..]") == take 5 [1 ..] = [1,2,3,4,5] --enumFromPrec :: (Linear l e, Read e, Enum e) => ReadPrec l -- | enumFromTo parser: -- --
-- readBy enumFromToPrec "[9 .. 12]" == [9 .. 12] == [9,10,11,12] --enumFromToPrec :: (Linear l e, Read e, Enum e) => ReadPrec l -- | enumFromThen parser: -- --
-- take 4 (readBy enumFromThenPrec "[17, -6 .. ]") == take 4 [17, -6 ..] == [17,-6,-29,-52] --enumFromThenPrec :: (Linear l e, Read e, Enum e) => ReadPrec l -- | enumFromThenTo parser: -- --
-- take 4 (readBy enumFromThenToPrec "[17, -6 .. 4]") == [17, -6 .. 4] == [17] --enumFromThenToPrec :: (Linear l e, Read e, Enum e) => ReadPrec l -- | Text.Show.SDP provides common ShowS stuff. module Text.Show.SDP -- | assocsPrec is showsPrec template. assocsPrec :: (Indexed v i e, Show i, Show e) => String -> Int -> v -> ShowS -- | showsRaw is a primitive list-to-string conversion pattern. -- -- Note that attempting to parse the resulting string with standard -- ReadS-based functions will cause an error (ambiguous parse). -- To properly parse a string, use the readRawSequence function -- from the SDP.Text.Read module. showsRaw :: Show e => Int -> [e] -> ShowS -- | Just showsRaw version for Linear. showsRawLinear :: (Linear l e, Show e) => Int -> l -> ShowS -- | SDP.Templates.AnyChunks provides AnyChunks - list of -- data chunks. module SDP.Templates.AnyChunks -- | AnyChunks is list of data chunks. AnyChunks shouldn't contain -- empty chunks, so the AnyChunks constructor is made private (see -- fromChunks and fromChunksM). -- --