-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Efficient multidimensional arrays -- -- generalized Algebraic Dynamic Programming -- -- This library provides efficient multidimensional arrays. Import -- Data.PrimitiveArray for indices, lenses, and arrays. -- -- For generalized ADP users, the library also provides the -- machinary to fill tables in the correct order required by usual -- CYK-style parsers, or regular grammars (used e.g. in alignment -- algorithms). This means that unless your grammar requires a strange -- order in which parsing is to be performed, it will mostly "just work". -- -- In general operations do not perform bounds-checking or other -- sanity-checking and are aimed towards efficiency as much as possible. -- Users (like ADPfusion) should perform their own -- bounds-checking, outside of code that performs "loop-like" operations. @package PrimitiveArray @version 0.9.1.0 module Data.PrimitiveArray.Index.Class -- | Strict pairs -- as in repa. data a :. b (:.) :: !a -> !b -> (:.) a b infixl 3 :. infixl 3 :. -- | A different version of strict pairs. Makes for simpler type inference -- in multi-tape grammars. We use :> when we have special -- needs, like non-recursive instances on inductives tuples, as used for -- set indices. -- -- This one is infixr so that in a :> b we can have -- the main type in a and the specializing types in b -- and then dispatch on a :> ts with ts maybe a -- chain of :>. data a :> b (:>) :: !a -> !b -> (:>) a b infixr 3 :> infixr 3 :> -- | Base data constructor for multi-dimensional indices. data Z Z :: Z -- | Index structures for complex, heterogeneous indexing. Mostly designed -- for indexing in DP grammars, where the indices work for linear and -- context-free grammars on one or more tapes, for strings, sets, later -- on tree structures. class Index i where { -- | Data structure encoding the upper limit for each array. data family LimitType i :: *; } -- | Given a maximal size, and a current index, calculate the linear index. linearIndex :: Index i => LimitType i -> i -> Int -- | Given the LimitType, return the number of cells required for -- storage. size :: Index i => LimitType i -> Int -- | Check if an index is within the bounds. inBounds :: Index i => LimitType i -> i -> Bool -- | A lower bound of zero zeroBound :: Index i => i -- | A lower bound of zero but for a LimitType i. zeroBound' :: Index i => LimitType i -- | The list of cell sizes for each dimension. its product yields the -- total size. totalSize :: Index i => LimitType i -> [Integer] -- | Given the maximal number of cells (Word, because this is the -- pointer limit for the machine), and the list of sizes, will check if -- this is still legal. Consider dividing the Word by the actual -- memory requirements for each cell, to get better exception handling -- for too large arrays. -- -- One list should be given for each array. sizeIsValid :: Monad m => Word -> [[Integer]] -> ExceptT SizeError m CellSize -- | In case totalSize or variants thereof produce a size that is -- too big to handle. newtype SizeError SizeError :: String -> SizeError -- | The total number of cells that are allocated. newtype CellSize CellSize :: Word -> CellSize -- | Generate a stream of indices in correct order for dynamic programming. -- Since the stream generators require concatMap / -- flatten we have to write more specialized code for -- (z:.IX) stuff. class (Index i) => IndexStream i -- | Generate an index stream using LimitTypes. This prevents having -- to figure out how the actual limits for complicated index types (like -- Set) would look like, since for Set, for example, -- the LimitType Set == Int provides just the number of bits. -- -- This generates an index stream suitable for forward structure -- filling. The first index is the smallest (or the first indices -- considered are all equally small in partially ordered sets). Larger -- indices follow up until the largest one. streamUp :: (IndexStream i, Monad m) => LimitType i -> LimitType i -> Stream m i -- | If streamUp generates indices from smallest to largest, then -- streamDown generates indices from largest to smallest. Outside -- grammars make implicit use of this. Asking for an axiom in -- backtracking requests the first element from this stream. streamDown :: (IndexStream i, Monad m) => LimitType i -> LimitType i -> Stream m i instance GHC.Enum.Enum Data.PrimitiveArray.Index.Class.CellSize instance GHC.Real.Real Data.PrimitiveArray.Index.Class.CellSize instance GHC.Real.Integral Data.PrimitiveArray.Index.Class.CellSize instance GHC.Enum.Bounded Data.PrimitiveArray.Index.Class.CellSize instance GHC.Num.Num Data.PrimitiveArray.Index.Class.CellSize instance GHC.Show.Show Data.PrimitiveArray.Index.Class.CellSize instance GHC.Classes.Ord Data.PrimitiveArray.Index.Class.CellSize instance GHC.Classes.Eq Data.PrimitiveArray.Index.Class.CellSize instance GHC.Show.Show Data.PrimitiveArray.Index.Class.SizeError instance GHC.Classes.Ord Data.PrimitiveArray.Index.Class.SizeError instance GHC.Classes.Eq Data.PrimitiveArray.Index.Class.SizeError instance GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType Data.PrimitiveArray.Index.Class.Z) instance GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType Data.PrimitiveArray.Index.Class.Z) instance GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType Data.PrimitiveArray.Index.Class.Z) instance GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType Data.PrimitiveArray.Index.Class.Z) instance Data.Data.Data (Data.PrimitiveArray.Index.Class.LimitType Data.PrimitiveArray.Index.Class.Z) instance (GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType zs), GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType z)) => GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType (zs Data.PrimitiveArray.Index.Class.:. z)) instance (GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType zs), GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType z)) => GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType (zs Data.PrimitiveArray.Index.Class.:. z)) instance (GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType zs), GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType z)) => GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType (zs Data.PrimitiveArray.Index.Class.:. z)) instance (GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType zs), GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType z)) => GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType (zs Data.PrimitiveArray.Index.Class.:. z)) instance (Data.Data.Data zs, Data.Data.Data (Data.PrimitiveArray.Index.Class.LimitType zs), Data.Typeable.Internal.Typeable zs, Data.Data.Data z, Data.Data.Data (Data.PrimitiveArray.Index.Class.LimitType z), Data.Typeable.Internal.Typeable z) => Data.Data.Data (Data.PrimitiveArray.Index.Class.LimitType (zs Data.PrimitiveArray.Index.Class.:. z)) instance Data.PrimitiveArray.Index.Class.IndexStream Data.PrimitiveArray.Index.Class.Z instance Data.PrimitiveArray.Index.Class.Index Data.PrimitiveArray.Index.Class.Z instance (Data.PrimitiveArray.Index.Class.Index zs, Data.PrimitiveArray.Index.Class.Index z) => Data.PrimitiveArray.Index.Class.Index (zs Data.PrimitiveArray.Index.Class.:. z) instance Data.Vector.Unboxed.Base.Unbox Data.PrimitiveArray.Index.Class.Z instance Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector Data.PrimitiveArray.Index.Class.Z instance Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector Data.PrimitiveArray.Index.Class.Z instance Data.Binary.Class.Binary Data.PrimitiveArray.Index.Class.Z instance Data.Serialize.Serialize Data.PrimitiveArray.Index.Class.Z instance Data.Aeson.Types.ToJSON.ToJSON Data.PrimitiveArray.Index.Class.Z instance Data.Aeson.Types.FromJSON.FromJSON Data.PrimitiveArray.Index.Class.Z instance Data.Hashable.Class.Hashable Data.PrimitiveArray.Index.Class.Z instance Test.QuickCheck.Arbitrary.Arbitrary Data.PrimitiveArray.Index.Class.Z instance Control.DeepSeq.NFData Data.PrimitiveArray.Index.Class.Z instance Control.Lens.Tuple.Field1 (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a) (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a') a a' instance Control.Lens.Tuple.Field1 ((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a) Data.PrimitiveArray.Index.Class.:. b) ((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a') Data.PrimitiveArray.Index.Class.:. b) a a' instance Control.Lens.Tuple.Field1 (((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a) Data.PrimitiveArray.Index.Class.:. b) Data.PrimitiveArray.Index.Class.:. c) (((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a') Data.PrimitiveArray.Index.Class.:. b) Data.PrimitiveArray.Index.Class.:. c) a a' instance Control.Lens.Tuple.Field2 ((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a) Data.PrimitiveArray.Index.Class.:. b) ((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a) Data.PrimitiveArray.Index.Class.:. b') b b' instance Control.Lens.Tuple.Field2 (((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a) Data.PrimitiveArray.Index.Class.:. b) Data.PrimitiveArray.Index.Class.:. c) (((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a) Data.PrimitiveArray.Index.Class.:. b') Data.PrimitiveArray.Index.Class.:. c) b b' instance Control.Lens.Tuple.Field3 (((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a) Data.PrimitiveArray.Index.Class.:. b) Data.PrimitiveArray.Index.Class.:. c) (((Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. a) Data.PrimitiveArray.Index.Class.:. b) Data.PrimitiveArray.Index.Class.:. c') c c' instance Data.Data.Data Data.PrimitiveArray.Index.Class.Z instance GHC.Generics.Generic Data.PrimitiveArray.Index.Class.Z instance GHC.Show.Show Data.PrimitiveArray.Index.Class.Z instance GHC.Read.Read Data.PrimitiveArray.Index.Class.Z instance GHC.Classes.Ord Data.PrimitiveArray.Index.Class.Z instance GHC.Classes.Eq Data.PrimitiveArray.Index.Class.Z instance (GHC.Read.Read a, GHC.Read.Read b) => GHC.Read.Read (a Data.PrimitiveArray.Index.Class.:> b) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Vector.Unboxed.Base.Unbox b) => Data.Vector.Unboxed.Base.Unbox (a Data.PrimitiveArray.Index.Class.:> b) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Vector.Unboxed.Base.Unbox b) => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (a Data.PrimitiveArray.Index.Class.:> b) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Vector.Unboxed.Base.Unbox b) => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (a Data.PrimitiveArray.Index.Class.:> b) instance (Data.Binary.Class.Binary a, Data.Binary.Class.Binary b) => Data.Binary.Class.Binary (a Data.PrimitiveArray.Index.Class.:> b) instance (Data.Serialize.Serialize a, Data.Serialize.Serialize b) => Data.Serialize.Serialize (a Data.PrimitiveArray.Index.Class.:> b) instance (Data.Aeson.Types.ToJSON.ToJSON a, Data.Aeson.Types.ToJSON.ToJSON b) => Data.Aeson.Types.ToJSON.ToJSON (a Data.PrimitiveArray.Index.Class.:> b) instance (Data.Aeson.Types.FromJSON.FromJSON a, Data.Aeson.Types.FromJSON.FromJSON b) => Data.Aeson.Types.FromJSON.FromJSON (a Data.PrimitiveArray.Index.Class.:> b) instance (Data.Hashable.Class.Hashable a, Data.Hashable.Class.Hashable b) => Data.Hashable.Class.Hashable (a Data.PrimitiveArray.Index.Class.:> b) instance (Control.DeepSeq.NFData a, Control.DeepSeq.NFData b) => Control.DeepSeq.NFData (a Data.PrimitiveArray.Index.Class.:> b) instance (Data.Data.Data a, Data.Data.Data b) => Data.Data.Data (a Data.PrimitiveArray.Index.Class.:> b) instance GHC.Generics.Generic (a Data.PrimitiveArray.Index.Class.:> b) instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (a Data.PrimitiveArray.Index.Class.:> b) instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (a Data.PrimitiveArray.Index.Class.:> b) instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (a Data.PrimitiveArray.Index.Class.:> b) instance (GHC.Read.Read a, GHC.Read.Read b) => GHC.Read.Read (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Vector.Unboxed.Base.Unbox b) => Data.Vector.Unboxed.Base.Unbox (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Vector.Unboxed.Base.Unbox b) => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Vector.Unboxed.Base.Unbox b) => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Binary.Class.Binary a, Data.Binary.Class.Binary b) => Data.Binary.Class.Binary (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Serialize.Serialize a, Data.Serialize.Serialize b) => Data.Serialize.Serialize (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Aeson.Types.ToJSON.ToJSON a, Data.Aeson.Types.ToJSON.ToJSON b) => Data.Aeson.Types.ToJSON.ToJSON (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Aeson.Types.FromJSON.FromJSON a, Data.Aeson.Types.FromJSON.FromJSON b) => Data.Aeson.Types.FromJSON.FromJSON (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Hashable.Class.Hashable a, Data.Hashable.Class.Hashable b) => Data.Hashable.Class.Hashable (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Aeson.Types.ToJSON.ToJSON a, Data.Aeson.Types.ToJSON.ToJSONKey a, Data.Aeson.Types.ToJSON.ToJSON b, Data.Aeson.Types.ToJSON.ToJSONKey b) => Data.Aeson.Types.ToJSON.ToJSONKey (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Aeson.Types.FromJSON.FromJSON a, Data.Aeson.Types.FromJSON.FromJSONKey a, Data.Aeson.Types.FromJSON.FromJSON b, Data.Aeson.Types.FromJSON.FromJSONKey b) => Data.Aeson.Types.FromJSON.FromJSONKey (a Data.PrimitiveArray.Index.Class.:. b) instance (Control.DeepSeq.NFData a, Control.DeepSeq.NFData b) => Control.DeepSeq.NFData (a Data.PrimitiveArray.Index.Class.:. b) instance (Test.QuickCheck.Arbitrary.Arbitrary a, Test.QuickCheck.Arbitrary.Arbitrary b) => Test.QuickCheck.Arbitrary.Arbitrary (a Data.PrimitiveArray.Index.Class.:. b) instance (Data.Data.Data a, Data.Data.Data b) => Data.Data.Data (a Data.PrimitiveArray.Index.Class.:. b) instance GHC.Generics.Generic (a Data.PrimitiveArray.Index.Class.:. b) instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (a Data.PrimitiveArray.Index.Class.:. b) instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (a Data.PrimitiveArray.Index.Class.:. b) instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (a Data.PrimitiveArray.Index.Class.:. b) -- | Vastly extended primitive arrays. Some basic ideas are now modeled -- after the vector package, especially the monadic mutable / pure -- immutable array system. -- -- NOTE all operations in MPrimArrayOps and PrimArrayOps are highly -- unsafe. No bounds-checking is performed at all. module Data.PrimitiveArray.Class -- | Mutable version of an array. data family MutArr (m :: * -> *) (arr :: *) :: * -- | The core set of operations for monadic arrays. class (Index sh) => MPrimArrayOps arr sh elm -- | Return the bounds of the array. All bounds are inclusive, as in -- [lb..ub] upperBoundM :: MPrimArrayOps arr sh elm => MutArr m (arr sh elm) -> LimitType sh -- | Given lower and upper bounds and a list of all elements, -- produce a mutable array. fromListM :: (MPrimArrayOps arr sh elm, PrimMonad m) => LimitType sh -> [elm] -> m (MutArr m (arr sh elm)) -- | Creates a new array with the given bounds with each element within the -- array being in an undefined state. newM :: (MPrimArrayOps arr sh elm, PrimMonad m) => LimitType sh -> m (MutArr m (arr sh elm)) -- | Creates a new array with all elements being equal to elm. newWithM :: (MPrimArrayOps arr sh elm, PrimMonad m) => LimitType sh -> elm -> m (MutArr m (arr sh elm)) -- | Reads a single element in the array. readM :: (MPrimArrayOps arr sh elm, PrimMonad m) => MutArr m (arr sh elm) -> sh -> m elm -- | Writes a single element in the array. writeM :: (MPrimArrayOps arr sh elm, PrimMonad m) => MutArr m (arr sh elm) -> sh -> elm -> m () -- | The core set of functions on immutable arrays. class (Index sh) => PrimArrayOps arr sh elm -- | Returns the bounds of an immutable array, again inclusive bounds: -- [lb..ub] . upperBound :: PrimArrayOps arr sh elm => arr sh elm -> LimitType sh -- | Freezes a mutable array an returns its immutable version. This -- operation is O(1) and both arrays share the same memory. Do not -- use the mutable array afterwards. unsafeFreeze :: (PrimArrayOps arr sh elm, PrimMonad m) => MutArr m (arr sh elm) -> m (arr sh elm) -- | Thaw an immutable array into a mutable one. Both versions share -- memory. unsafeThaw :: (PrimArrayOps arr sh elm, PrimMonad m) => arr sh elm -> m (MutArr m (arr sh elm)) -- | Extract a single element from the array. Generally unsafe as not -- bounds-checking is performed. unsafeIndex :: PrimArrayOps arr sh elm => arr sh elm -> sh -> elm -- | Savely transform the shape space of a table. transformShape :: (PrimArrayOps arr sh elm, Index sh') => (LimitType sh -> LimitType sh') -> arr sh elm -> arr sh' elm class (Index sh) => PrimArrayMap arr sh e e' -- | Map a function over each element, keeping the shape intact. map :: PrimArrayMap arr sh e e' => (e -> e') -> arr sh e -> arr sh e' data PAErrors PAEUpperBound :: PAErrors -- | Infix index operator. Performs minimal bounds-checking using assert in -- non-optimized code. (!) :: PrimArrayOps arr sh elm => arr sh elm -> sh -> elm -- | Returns true if the index is valid for the array. inBoundsM :: (Monad m, MPrimArrayOps arr sh elm) => MutArr m (arr sh elm) -> sh -> Bool -- | Construct a mutable primitive array from a lower and an upper bound, a -- default element, and a list of associations. fromAssocsM :: (PrimMonad m, MPrimArrayOps arr sh elm) => LimitType sh -> elm -> [(sh, elm)] -> m (MutArr m (arr sh elm)) -- | Initialize an immutable array but stay within the primitive monad -- m. newWithPA :: (PrimMonad m, MPrimArrayOps arr sh elm, PrimArrayOps arr sh elm) => LimitType sh -> elm -> m (arr sh elm) -- | Safely prepare a primitive array. -- -- TODO Check if having a MonadError instance degrades -- performance. (We should see this once the test with NeedlemanWunsch is -- under way). safeNewWithPA :: forall m arr sh elm. (PrimMonad m, MonadError PAErrors m, MPrimArrayOps arr sh elm, PrimArrayOps arr sh elm) => LimitType sh -> elm -> m (arr sh elm) -- | Return all associations from an array. assocs :: forall arr sh elm. (IndexStream sh, PrimArrayOps arr sh elm) => arr sh elm -> [(sh, elm)] -- | Creates an immutable array from lower and upper bounds and a complete -- list of elements. fromList :: (PrimArrayOps arr sh elm, MPrimArrayOps arr sh elm) => LimitType sh -> [elm] -> arr sh elm -- | Creates an immutable array from lower and upper bounds, a default -- element, and a list of associations. fromAssocs :: (PrimArrayOps arr sh elm, MPrimArrayOps arr sh elm) => LimitType sh -> elm -> [(sh, elm)] -> arr sh elm -- | Returns all elements of an immutable array as a list. toList :: forall arr sh elm. (IndexStream sh, PrimArrayOps arr sh elm) => arr sh elm -> [elm] -- | freezeTables freezes a stack of tables. class FreezeTables m t where { type family Frozen t :: *; } freezeTables :: FreezeTables m t => t -> m (Frozen t) instance GHC.Generics.Generic Data.PrimitiveArray.Class.PAErrors instance GHC.Classes.Eq Data.PrimitiveArray.Class.PAErrors instance GHC.Base.Applicative m => Data.PrimitiveArray.Class.FreezeTables m Data.PrimitiveArray.Index.Class.Z instance (GHC.Base.Functor m, GHC.Base.Applicative m, GHC.Base.Monad m, Control.Monad.Primitive.PrimMonad m, Data.PrimitiveArray.Class.FreezeTables m ts, Data.PrimitiveArray.Class.PrimArrayOps arr sh elm) => Data.PrimitiveArray.Class.FreezeTables m (ts Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Class.MutArr m (arr sh elm)) instance GHC.Show.Show Data.PrimitiveArray.Class.PAErrors -- | Dense primitive arrays where the lower index is zero (or the -- equivalent of zero for newtypes and enumerations). -- -- Actual writes to data structures use a more safe -- write instead of the unsafe unsafeWrite. Writes also -- tend to occur much less in DP algorithms (say, N^2 writes for an N^3 -- time algorithm -- mostly reads are being executed). -- -- TODO consider if we want to force the lower index to be zero, or allow -- non-zero lower indices. Will have to be considered together with the -- Index.Class module! -- -- TODO while Unboxed is, in princile, Hashable, we'd -- need the corresponding VU.Vector instances ... module Data.PrimitiveArray.Dense data Unboxed sh e Unboxed :: !LimitType sh -> !Vector e -> Unboxed sh e data Boxed sh e Boxed :: !LimitType sh -> !Vector e -> Boxed sh e instance GHC.Generics.Generic (Data.PrimitiveArray.Class.MutArr m (Data.PrimitiveArray.Dense.Unboxed sh e)) instance GHC.Generics.Generic (Data.PrimitiveArray.Class.MutArr m (Data.PrimitiveArray.Dense.Boxed sh e)) instance (GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Classes.Eq e, Data.Vector.Unboxed.Base.Unbox e) => GHC.Classes.Eq (Data.PrimitiveArray.Dense.Unboxed sh e) instance (GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e, Data.Vector.Unboxed.Base.Unbox e) => GHC.Generics.Generic (Data.PrimitiveArray.Dense.Unboxed sh e) instance (GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Read.Read e, Data.Vector.Unboxed.Base.Unbox e) => GHC.Read.Read (Data.PrimitiveArray.Dense.Unboxed sh e) instance (GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Show.Show e, Data.Vector.Unboxed.Base.Unbox e) => GHC.Show.Show (Data.PrimitiveArray.Dense.Unboxed sh e) instance (Data.Data.Data sh, Data.Data.Data (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Data.Data e, Data.Vector.Unboxed.Base.Unbox e) => Data.Data.Data (Data.PrimitiveArray.Dense.Unboxed sh e) instance (GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Read.Read e) => GHC.Read.Read (Data.PrimitiveArray.Dense.Boxed sh e) instance (GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Show.Show e) => GHC.Show.Show (Data.PrimitiveArray.Dense.Boxed sh e) instance (GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Classes.Eq e) => GHC.Classes.Eq (Data.PrimitiveArray.Dense.Boxed sh e) instance (GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => GHC.Generics.Generic (Data.PrimitiveArray.Dense.Boxed sh e) instance (Data.Data.Data sh, Data.Data.Data (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Data.Data e) => Data.Data.Data (Data.PrimitiveArray.Dense.Boxed sh e) instance (Data.Binary.Class.Binary (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Binary.Class.Binary e, Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Binary.Class.Binary (Data.PrimitiveArray.Dense.Boxed sh e) instance (Data.Serialize.Serialize (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Serialize.Serialize e, Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Serialize.Serialize (Data.PrimitiveArray.Dense.Boxed sh e) instance (Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Aeson.Types.ToJSON.ToJSON e, Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Dense.Boxed sh e) instance (Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Aeson.Types.FromJSON.FromJSON e, Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Dense.Boxed sh e) instance (Data.Hashable.Class.Hashable (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Hashable.Class.Hashable e, Data.Hashable.Class.Hashable (Data.Vector.Vector e), Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Hashable.Class.Hashable (Data.PrimitiveArray.Dense.Boxed sh e) instance (Control.DeepSeq.NFData (Data.PrimitiveArray.Index.Class.LimitType sh), Control.DeepSeq.NFData e) => Control.DeepSeq.NFData (Data.PrimitiveArray.Dense.Boxed sh e) instance Control.DeepSeq.NFData (Data.PrimitiveArray.Index.Class.LimitType sh) => Control.DeepSeq.NFData (Data.PrimitiveArray.Class.MutArr m (Data.PrimitiveArray.Dense.Boxed sh e)) instance Data.PrimitiveArray.Index.Class.Index sh => Data.PrimitiveArray.Class.MPrimArrayOps Data.PrimitiveArray.Dense.Boxed sh elm instance Data.PrimitiveArray.Index.Class.Index sh => Data.PrimitiveArray.Class.PrimArrayOps Data.PrimitiveArray.Dense.Boxed sh elm instance Data.PrimitiveArray.Index.Class.Index sh => Data.PrimitiveArray.Class.PrimArrayMap Data.PrimitiveArray.Dense.Boxed sh e e' instance (Data.Binary.Class.Binary (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Binary.Class.Binary e, Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Binary.Class.Binary (Data.PrimitiveArray.Dense.Unboxed sh e) instance (Data.Serialize.Serialize (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Serialize.Serialize e, Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Serialize.Serialize (Data.PrimitiveArray.Dense.Unboxed sh e) instance (Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Aeson.Types.ToJSON.ToJSON e, Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Dense.Unboxed sh e) instance (Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Aeson.Types.FromJSON.FromJSON e, Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Dense.Unboxed sh e) instance (Data.Hashable.Class.Hashable (Data.PrimitiveArray.Index.Class.LimitType sh), Data.Hashable.Class.Hashable e, Data.Hashable.Class.Hashable (Data.Vector.Unboxed.Base.Vector e), Data.Vector.Unboxed.Base.Unbox e, GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType sh), GHC.Generics.Generic e) => Data.Hashable.Class.Hashable (Data.PrimitiveArray.Dense.Unboxed sh e) instance Control.DeepSeq.NFData (Data.PrimitiveArray.Index.Class.LimitType sh) => Control.DeepSeq.NFData (Data.PrimitiveArray.Dense.Unboxed sh e) instance Control.DeepSeq.NFData (Data.PrimitiveArray.Index.Class.LimitType sh) => Control.DeepSeq.NFData (Data.PrimitiveArray.Class.MutArr m (Data.PrimitiveArray.Dense.Unboxed sh e)) instance (Data.PrimitiveArray.Index.Class.Index sh, Data.Vector.Unboxed.Base.Unbox elm) => Data.PrimitiveArray.Class.MPrimArrayOps Data.PrimitiveArray.Dense.Unboxed sh elm instance (Data.PrimitiveArray.Index.Class.Index sh, Data.Vector.Unboxed.Base.Unbox elm) => Data.PrimitiveArray.Class.PrimArrayOps Data.PrimitiveArray.Dense.Unboxed sh elm instance (Data.PrimitiveArray.Index.Class.Index sh, Data.Vector.Unboxed.Base.Unbox e, Data.Vector.Unboxed.Base.Unbox e') => Data.PrimitiveArray.Class.PrimArrayMap Data.PrimitiveArray.Dense.Unboxed sh e e' module Data.PrimitiveArray.Index.IOC -- | Phantom type for Inside indices. data I -- | Phantom type for Outside indices. data O -- | Phantom type for Complement indices. data C -- | A collection of a number of data types and type classes shared by all -- bitset variants. module Data.PrimitiveArray.Index.BitSetClasses -- | Certain sets have an interface, a particular element with special -- meaning. In this module, certain `meanings' are already -- provided. These include a First element and a Last -- element. We phantom-type these to reduce programming overhead. newtype Boundary boundaryType ioc Boundary :: Int -> Boundary boundaryType ioc [getBoundary] :: Boundary boundaryType ioc -> Int streamUpBndMk :: Monad m => b -> p -> a -> m (a, b) streamUpBndStep :: Monad m => p -> Int -> (a, Int) -> m (Step (a, Int) (a :. Boundary boundaryType ioc)) streamDownBndMk :: Monad m => p -> b -> a -> m (a, b) streamDownBndStep :: Monad m => Int -> p -> (a, Int) -> m (Step (a, Int) (a :. Boundary boundaryType ioc)) -- | Declare the interface to be the start of a path. data First -- | Declare the interface to be the end of a path. data Last -- | Declare the interface to match anything. -- -- TODO needed? want to use later in ADPfusion data Any -- | Successor and Predecessor for sets. Designed as a class to accomodate -- sets with interfaces and without interfaces with one function. -- -- The functions are not written recursively, as we currently only have -- three cases, and we do not want to "reset" while generating successors -- and predecessors. -- -- Note that sets have a partial order. Within the group of element with -- the same popCount, we use popPermutation which has -- the same stepping order for both, setSucc and -- setPred. class SetPredSucc s -- | Set successor. The first argument is the lower set limit, the second -- the upper set limit, the third the current set. setSucc :: SetPredSucc s => Int -> Int -> s -> Maybe s -- | Set predecessor. The first argument is the lower set limit, the second -- the upper set limit, the third the current set. setPred :: SetPredSucc s => Int -> Int -> s -> Maybe s -- | Masks are used quite often for different types of bitsets. We liberate -- them as a type family. type family Mask s :: * -- | Fixed allows us to fix some or all bits of a bitset, thereby -- providing succ/pred operations which are only partially free. -- -- The mask is lazy, this allows us to have undefined for -- l and h. -- -- f = getFixedMask .&. getFixed are the fixed bits. n = -- getFixed .&. complement getFixedMask are the free bits. -- to = complement getFixed is the to move mask n' = -- popShiftR to n yields the population after the move p = -- popPermutation undefined n' yields the new population permutation -- p' = popShiftL to p yields the population moved back -- final = p' .|. f data Fixed t Fixed :: Mask t -> !t -> Fixed t [getFixedMask] :: Fixed t -> Mask t [getFixed] :: Fixed t -> !t -- | Assuming a bitset on bits [0 .. highbit], we can apply a mask -- that stretches out those bits over [0 .. higherBit] with -- highbit <= higherBit. Any active interfaces are correctly -- set as well. class ApplyMask s applyMask :: ApplyMask s => Mask s -> s -> s -- | for Arbitrary arbitraryBitSetMax :: Int instance forall k1 k2 (i :: k2) (t :: k1). Data.Vector.Unboxed.Base.Unbox (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 k2 (i :: k2) (t :: k1). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 k2 (i :: k2) (t :: k1). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 k2 (i :: k2) (t :: k1). Data.Binary.Class.Binary (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 k2 (i :: k2) (t :: k1). Data.Serialize.Serialize (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 k2 (i :: k2) (t :: k1). Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 k2 (i :: k2) (t :: k1). Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 k2 (i :: k2) (t :: k1). Data.Hashable.Class.Hashable (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 k2 (i :: k2) (t :: k1). Control.DeepSeq.NFData (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 k2 (i :: k2) (t :: k1). Data.PrimitiveArray.Index.Class.Index (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) instance forall k1 z (k2 :: k1). Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.BitSetClasses.Boundary k2 Data.PrimitiveArray.Index.IOC.I) instance forall k1 (k2 :: k1). Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.BitSetClasses.Boundary k2 Data.PrimitiveArray.Index.IOC.I) => Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.BitSetClasses.Boundary k2 Data.PrimitiveArray.Index.IOC.I) instance forall k1 (boundaryType :: k1) k2 (ioc :: k2). GHC.Num.Num (Data.PrimitiveArray.Index.BitSetClasses.Boundary boundaryType ioc) instance forall k1 (boundaryType :: k1) k2 (ioc :: k2). GHC.Generics.Generic (Data.PrimitiveArray.Index.BitSetClasses.Boundary boundaryType ioc) instance forall k1 (boundaryType :: k1) k2 (ioc :: k2). GHC.Classes.Ord (Data.PrimitiveArray.Index.BitSetClasses.Boundary boundaryType ioc) instance forall k1 (boundaryType :: k1) k2 (ioc :: k2). GHC.Classes.Eq (Data.PrimitiveArray.Index.BitSetClasses.Boundary boundaryType ioc) instance forall k1 k2 (i :: k2) (t :: k1). GHC.Show.Show (Data.PrimitiveArray.Index.BitSetClasses.Boundary i t) -- | The most basic bitset structure. Alone, not particularly useful, -- because two sets {u,v},{v',w} have no way of annotating the -- connection between the sets. Together with boundaries this yields sets -- for useful DP algorithms. module Data.PrimitiveArray.Index.BitSet0 -- | Newtype for a bitset. -- -- Int integrates better with the rest of the framework. But we -- should consider moving to Word-based indexing, if possible. newtype BitSet t BitSet :: Int -> BitSet t [_bitSet] :: BitSet t -> Int bitSet :: forall t_aPQq t_aQq3. Iso (BitSet t_aPQq) (BitSet t_aQq3) Int Int streamUpMk :: Monad m => Int -> Int -> t -> m (t, Maybe (BitSet ioc)) streamUpStep :: Monad m => Int -> Int -> (t, Maybe (BitSet ioc)) -> m (Step (t, Maybe (BitSet ioc)) (t :. BitSet ioc)) streamDownMk :: Monad m => Int -> Int -> t -> m (t, Maybe (BitSet ioc)) streamDownStep :: Monad m => Int -> Int -> (t, Maybe (BitSet ioc)) -> m (Step (t, Maybe (BitSet ioc)) (t :. BitSet ioc)) instance forall k (t :: k). Data.Vector.Unboxed.Base.Unbox (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). GHC.Show.Show (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Control.DeepSeq.NFData (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.Index (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.PrimitiveArray.Index.BitSetClasses.SetPredSucc (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.BitSet0.BitSet Data.PrimitiveArray.Index.IOC.I) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.BitSet0.BitSet Data.PrimitiveArray.Index.IOC.O) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.BitSet0.BitSet Data.PrimitiveArray.Index.IOC.C) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.BitSet0.BitSet t) => Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Test.QuickCheck.Arbitrary.Arbitrary (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSONKey (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSONKey (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Binary.Class.Binary (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Serialize.Serialize (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Hashable.Class.Hashable (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Bits.Bits (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). GHC.Num.Num (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Bits.Extras.Ranked (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). Data.Bits.FiniteBits (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). GHC.Classes.Ord (Data.PrimitiveArray.Index.BitSet0.BitSet t) instance forall k (t :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.BitSet0.BitSet t) -- | A bitset with one interface. This includes the often-encountered case -- where {u,v},{v}, or sets with a single edge between the old -- set and a new singleton set are required. Uses are Hamiltonian path -- problems, and TSP, among others. module Data.PrimitiveArray.Index.BitSet1 -- | The bitset with one interface or boundary. data BitSet1 i ioc BitSet1 :: !BitSet ioc -> !Boundary i ioc -> BitSet1 i ioc [_bitset] :: BitSet1 i ioc -> !BitSet ioc [_boundary] :: BitSet1 i ioc -> !Boundary i ioc boundary :: forall i_aUh6 ioc_aUh7 i_aUnH. Lens (BitSet1 i_aUh6 ioc_aUh7) (BitSet1 i_aUnH ioc_aUh7) (Boundary i_aUh6 ioc_aUh7) (Boundary i_aUnH ioc_aUh7) bitset :: forall i_aUh6 ioc_aUh7. Lens' (BitSet1 i_aUh6 ioc_aUh7) (BitSet ioc_aUh7) streamUpMk :: Monad m => Int -> Int -> z -> m (z, Maybe (BitSet1 c ioc)) streamUpStep :: Monad m => Int -> Int -> (t, Maybe (BitSet1 c ioc)) -> m (Step (t, Maybe (BitSet1 c ioc)) (t :. BitSet1 c ioc)) streamDownMk :: Monad m => Int -> Int -> z -> m (z, Maybe (BitSet1 c ioc)) streamDownStep :: Monad m => Int -> Int -> (t, Maybe (BitSet1 c ioc)) -> m (Step (t, Maybe (BitSet1 c ioc)) (t :. BitSet1 c ioc)) instance forall k1 k2 (bnd :: k2) (ioc :: k1). GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.BitSet1.BitSet1 bnd ioc)) instance forall k1 k2 (i :: k2) (ioc :: k1). Data.Vector.Unboxed.Base.Unbox (Data.PrimitiveArray.Index.BitSet1.BitSet1 i ioc) instance forall k1 k2 (i :: k2) (ioc :: k1). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Data.PrimitiveArray.Index.BitSet1.BitSet1 i ioc) instance forall k1 k2 (i :: k2) (ioc :: k1). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Data.PrimitiveArray.Index.BitSet1.BitSet1 i ioc) instance forall k1 k2 (bnd :: k2) (ioc :: k1). Data.PrimitiveArray.Index.Class.Index (Data.PrimitiveArray.Index.BitSet1.BitSet1 bnd ioc) instance forall k z (i :: k). Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.BitSet1.BitSet1 i Data.PrimitiveArray.Index.IOC.I) instance forall k z (i :: k). Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.BitSet1.BitSet1 i Data.PrimitiveArray.Index.IOC.O) instance forall k1 k2 (i :: k2) (t :: k1). Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.BitSet1.BitSet1 i t) => Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.BitSet1.BitSet1 i t) instance forall k1 k2 (t :: k2) (ioc :: k1). Data.PrimitiveArray.Index.BitSetClasses.SetPredSucc (Data.PrimitiveArray.Index.BitSet1.BitSet1 t ioc) instance forall k1 k2 (t :: k2) (ioc :: k1). Test.QuickCheck.Arbitrary.Arbitrary (Data.PrimitiveArray.Index.BitSet1.BitSet1 t ioc) instance forall k1 (i :: k1) k2 (ioc :: k2). GHC.Show.Show (Data.PrimitiveArray.Index.BitSet1.BitSet1 i ioc) instance forall k1 (i :: k1) k2 (ioc :: k2). GHC.Generics.Generic (Data.PrimitiveArray.Index.BitSet1.BitSet1 i ioc) instance forall k1 (i :: k1) k2 (ioc :: k2). GHC.Classes.Ord (Data.PrimitiveArray.Index.BitSet1.BitSet1 i ioc) instance forall k1 (i :: k1) k2 (ioc :: k2). GHC.Classes.Eq (Data.PrimitiveArray.Index.BitSet1.BitSet1 i ioc) module Data.PrimitiveArray.Index.Int instance GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType GHC.Types.Int) instance Data.PrimitiveArray.Index.Class.Index GHC.Types.Int instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. GHC.Types.Int) instance Data.PrimitiveArray.Index.Class.IndexStream GHC.Types.Int -- | A linear 0-based int-index with a phantom type. module Data.PrimitiveArray.Index.PhantomInt -- | A PInt behaves exactly like an Int, but has an -- attached phantom type p. In particular, the Index -- and IndexStream instances are the same as for raw -- Ints. newtype PInt (ioc :: k) (p :: k) PInt :: Int -> PInt [getPInt] :: PInt -> Int pIntI :: Int -> PInt I p pIntO :: Int -> PInt O p pIntC :: Int -> PInt C p streamUpMk :: Monad m => b -> p -> a -> m (a, b) streamUpStep :: Monad m => p1 -> Int -> (a, Int) -> m (Step (a, Int) (a :. PInt ioc p2)) streamDownMk :: Monad m => p -> b -> a -> m (a, b) streamDownStep :: Monad m => Int -> p1 -> (a, Int) -> m (Step (a, Int) (a :. PInt ioc p2)) instance forall k (t :: k) (p :: k). GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.PhantomInt.PInt t p)) instance forall k (t :: k) (p :: k). GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.PhantomInt.PInt t p)) instance forall k (t :: k) (p :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.PhantomInt.PInt t p)) instance forall k (t :: k) (p :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.PhantomInt.PInt t p)) instance forall k (t :: k) (p :: k). Data.Vector.Unboxed.Base.Unbox (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.Binary.Class.Binary (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.Serialize.Serialize (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.Aeson.Types.FromJSON.FromJSONKey (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.Aeson.Types.ToJSON.ToJSONKey (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.Hashable.Class.Hashable (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Control.DeepSeq.NFData (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance forall k (t :: k) (p :: k). Data.PrimitiveArray.Index.Class.Index (Data.PrimitiveArray.Index.PhantomInt.PInt t p) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.PhantomInt.PInt Data.PrimitiveArray.Index.IOC.I p) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.PhantomInt.PInt Data.PrimitiveArray.Index.IOC.O p) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.PhantomInt.PInt Data.PrimitiveArray.Index.IOC.C p) instance forall k (ioc :: k) (p :: k). Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) => Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Arr.Ix (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). (Data.Typeable.Internal.Typeable ioc, Data.Typeable.Internal.Typeable p, Data.Typeable.Internal.Typeable k) => Data.Data.Data (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Real.Real (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Real.Integral (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Num.Num (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Enum.Enum (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Classes.Ord (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Show.Show (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) instance forall k (ioc :: k) (p :: k). GHC.Read.Read (Data.PrimitiveArray.Index.PhantomInt.PInt ioc p) -- | Point index structures are used for left- and right-linear -- grammars. Such grammars have at most one syntactic symbol on each -- r.h.s. of a rule. The syntactic symbol needs to be in an outermost -- position. module Data.PrimitiveArray.Index.Point -- | A point in a left-linear grammar. The syntactic symbol is in left-most -- position. newtype PointL t PointL :: Int -> PointL t [fromPointL] :: PointL t -> Int pointLI :: Int -> PointL I pointLO :: Int -> PointL O pointLC :: Int -> PointL C data SP z SP :: !z -> !Int# -> SP z streamUpMk :: Monad m => Int -> z -> m (SP z) streamUpStep :: Monad m => (Int -> b) -> Int -> SP z -> m (Step (SP z) (z :. b)) streamDownMk :: Monad m => Int -> z -> m (SP z) streamDownStep :: Monad m => (Int -> b) -> Int -> SP z -> m (Step (SP z) (z :. b)) -- | A point in a right-linear grammars. newtype PointR t PointR :: Int -> PointR t [fromPointR] :: PointR t -> Int arbMaxPointR :: Int instance forall k (t :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Point.PointR t)) instance forall k (t :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Point.PointR t)) instance forall k (t :: k). GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Point.PointR t)) instance forall k (t :: k). GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Point.PointR t)) instance forall k (t :: k). Data.Vector.Unboxed.Base.Unbox (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.Binary.Class.Binary (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.Serialize.Serialize (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSONKey (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSONKey (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.Hashable.Class.Hashable (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Control.DeepSeq.NFData (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.Index (Data.PrimitiveArray.Index.Point.PointR t) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Point.PointR Data.PrimitiveArray.Index.IOC.I) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Point.PointR Data.PrimitiveArray.Index.IOC.O) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Point.PointR t) => Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). Test.QuickCheck.Arbitrary.Arbitrary (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). GHC.Show.Show (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). GHC.Read.Read (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). GHC.Classes.Ord (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.Point.PointR t) instance forall k (t :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Point.PointL t)) instance forall k (t :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Point.PointL t)) instance forall k (t :: k). GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Point.PointL t)) instance forall k (t :: k). GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Point.PointL t)) instance forall k (t :: k). Data.Vector.Unboxed.Base.Unbox (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.Binary.Class.Binary (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.Serialize.Serialize (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSONKey (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSONKey (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.Hashable.Class.Hashable (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Control.DeepSeq.NFData (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.Index (Data.PrimitiveArray.Index.Point.PointL t) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Point.PointL Data.PrimitiveArray.Index.IOC.I) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Point.PointL Data.PrimitiveArray.Index.IOC.O) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Point.PointL Data.PrimitiveArray.Index.IOC.C) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Point.PointL t) => Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). Test.QuickCheck.Arbitrary.Arbitrary (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (m :: * -> *) (t :: k). GHC.Base.Monad m => Test.SmallCheck.Series.Serial m (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). GHC.Show.Show (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). GHC.Read.Read (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). GHC.Classes.Ord (Data.PrimitiveArray.Index.Point.PointL t) instance forall k (t :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.Point.PointL t) -- | Index structure for context-free grammars on strings. A -- Subword captures a pair (i,j) with i<=j. module Data.PrimitiveArray.Index.Subword -- | A subword wraps a pair of Int indices i,j with -- i<=j. -- -- Subwords always yield the upper-triangular part of a rect-angular -- array. This gives the quite curious effect that (0,N) points -- to the `largest' index, while (0,0) ... (1,1) ... (k,k) -- ... (N,N) point to the smallest. We do, however, use (0,0) as the -- smallest as (0,k) gives successively smaller upper triangular parts. newtype Subword t Subword :: (Int :. Int) -> Subword t [fromSubword] :: Subword t -> Int :. Int fromSubwordFst :: Subword t -> Int fromSubwordSnd :: Subword t -> Int -- | Create a Subword t where t is inferred. subword :: Int -> Int -> Subword t subwordI :: Int -> Int -> Subword I subwordO :: Int -> Int -> Subword O subwordC :: Int -> Int -> Subword C -- | generic mk for streamUp / streamDown streamUpMk :: Monad m => c -> a -> m (a, c, c) streamUpStep :: Monad m => Int -> Int -> (a, Int, Int) -> m (Step (a, Int, Int) (a :. Subword t)) streamDownMk :: Monad m => b -> c -> a -> m (a, b, c) streamDownStep :: Monad m => Int -> (a, Int, Int) -> m (Step (a, Int, Int) (a :. Subword t)) instance forall k (t :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Subword.Subword t)) instance forall k (t :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Subword.Subword t)) instance forall k (t :: k). GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Subword.Subword t)) instance forall k (t :: k). GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Subword.Subword t)) instance forall k (t :: k). Data.Vector.Unboxed.Base.Unbox (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.Binary.Class.Binary (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.Serialize.Serialize (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSONKey (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSONKey (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.Hashable.Class.Hashable (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Control.DeepSeq.NFData (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.Index (Data.PrimitiveArray.Index.Subword.Subword t) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Subword.Subword Data.PrimitiveArray.Index.IOC.I) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Subword.Subword Data.PrimitiveArray.Index.IOC.O) instance Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Subword.Subword Data.PrimitiveArray.Index.IOC.C) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Subword.Subword t) => Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). Test.QuickCheck.Arbitrary.Arbitrary (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (m :: * -> *) (t :: k). GHC.Base.Monad m => Test.SmallCheck.Series.Serial m (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). GHC.Read.Read (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). GHC.Show.Show (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). GHC.Classes.Ord (Data.PrimitiveArray.Index.Subword.Subword t) instance forall k (t :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.Subword.Subword t) -- | Unit indices admit a single element to be memoized. We can't use -- () because we want to attach phantom types. module Data.PrimitiveArray.Index.Unit data Unit t Unit :: Unit t instance forall k (t :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Unit.Unit t)) instance forall k (t :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Unit.Unit t)) instance forall k (t :: k). GHC.Read.Read (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Unit.Unit t)) instance forall k (t :: k). GHC.Show.Show (Data.PrimitiveArray.Index.Class.LimitType (Data.PrimitiveArray.Index.Unit.Unit t)) instance forall k (t :: k). Data.Vector.Unboxed.Base.Unbox (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.Binary.Class.Binary (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.Serialize.Serialize (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSON (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSONKey (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSON (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSONKey (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.Hashable.Class.Hashable (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Control.DeepSeq.NFData (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.Index (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k z (t :: k). Data.PrimitiveArray.Index.Class.IndexStream z => Data.PrimitiveArray.Index.Class.IndexStream (z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Class.Z Data.PrimitiveArray.Index.Class.:. Data.PrimitiveArray.Index.Unit.Unit t) => Data.PrimitiveArray.Index.Class.IndexStream (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). Test.QuickCheck.Arbitrary.Arbitrary (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). GHC.Read.Read (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). GHC.Generics.Generic (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). GHC.Show.Show (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). GHC.Classes.Ord (Data.PrimitiveArray.Index.Unit.Unit t) instance forall k (t :: k). GHC.Classes.Eq (Data.PrimitiveArray.Index.Unit.Unit t) module Data.PrimitiveArray.Index data family Vector a :: Type data family MVector s a :: Type -- | Data structure encoding the upper limit for each array. data family LimitType i :: * -- | Newtype for a bitset. -- -- Int integrates better with the rest of the framework. But we -- should consider moving to Word-based indexing, if possible. newtype BitSet t BitSet :: Int -> BitSet t [_bitSet] :: BitSet t -> Int bitSet :: forall t_aPQq t_aQq3. Iso (BitSet t_aPQq) (BitSet t_aQq3) Int Int data family Vector a :: Type data family MVector s a :: Type -- | Data structure encoding the upper limit for each array. data family LimitType i :: * -- | The bitset with one interface or boundary. data BitSet1 i ioc BitSet1 :: !BitSet ioc -> !Boundary i ioc -> BitSet1 i ioc [_bitset] :: BitSet1 i ioc -> !BitSet ioc [_boundary] :: BitSet1 i ioc -> !Boundary i ioc bitset :: forall i_aUh6 ioc_aUh7. Lens' (BitSet1 i_aUh6 ioc_aUh7) (BitSet ioc_aUh7) boundary :: forall i_aUh6 ioc_aUh7 i_aUnH. Lens (BitSet1 i_aUh6 ioc_aUh7) (BitSet1 i_aUnH ioc_aUh7) (Boundary i_aUh6 ioc_aUh7) (Boundary i_aUnH ioc_aUh7) data family Vector a :: Type data family MVector s a :: Type -- | Data structure encoding the upper limit for each array. data family LimitType i :: * -- | A PInt behaves exactly like an Int, but has an -- attached phantom type p. In particular, the Index -- and IndexStream instances are the same as for raw -- Ints. newtype PInt (ioc :: k) (p :: k) PInt :: Int -> PInt [getPInt] :: PInt -> Int pIntI :: Int -> PInt I p pIntO :: Int -> PInt O p pIntC :: Int -> PInt C p data family Vector a :: Type data family MVector s a :: Type -- | Data structure encoding the upper limit for each array. data family LimitType i :: * -- | A point in a left-linear grammar. The syntactic symbol is in left-most -- position. newtype PointL t PointL :: Int -> PointL t [fromPointL] :: PointL t -> Int pointLI :: Int -> PointL I pointLO :: Int -> PointL O pointLC :: Int -> PointL C -- | A point in a right-linear grammars. newtype PointR t PointR :: Int -> PointR t [fromPointR] :: PointR t -> Int data SP z SP :: !z -> !Int# -> SP z arbMaxPointR :: Int data family Vector a :: Type data family MVector s a :: Type -- | Data structure encoding the upper limit for each array. data family LimitType i :: * -- | A subword wraps a pair of Int indices i,j with -- i<=j. -- -- Subwords always yield the upper-triangular part of a rect-angular -- array. This gives the quite curious effect that (0,N) points -- to the `largest' index, while (0,0) ... (1,1) ... (k,k) -- ... (N,N) point to the smallest. We do, however, use (0,0) as the -- smallest as (0,k) gives successively smaller upper triangular parts. newtype Subword t Subword :: (Int :. Int) -> Subword t [fromSubword] :: Subword t -> Int :. Int fromSubwordFst :: Subword t -> Int fromSubwordSnd :: Subword t -> Int -- | Create a Subword t where t is inferred. subword :: Int -> Int -> Subword t subwordI :: Int -> Int -> Subword I subwordO :: Int -> Int -> Subword O subwordC :: Int -> Int -> Subword C module Data.PrimitiveArray -- | This module exports everything that Data.PrimitiveArray -- exports, but it will do some bounds-checking on certain operations. -- -- Checked are: (!) module Data.PrimitiveArray.Checked data family Vector a :: Type data family MVector s a :: Type -- | Strict pairs -- as in repa. data a :. b (:.) :: !a -> !b -> (:.) a b infixl 3 :. infixl 3 :. -- | A different version of strict pairs. Makes for simpler type inference -- in multi-tape grammars. We use :> when we have special -- needs, like non-recursive instances on inductives tuples, as used for -- set indices. -- -- This one is infixr so that in a :> b we can have -- the main type in a and the specializing types in b -- and then dispatch on a :> ts with ts maybe a -- chain of :>. data a :> b (:>) :: !a -> !b -> (:>) a b infixr 3 :> infixr 3 :> -- | Base data constructor for multi-dimensional indices. data Z Z :: Z -- | Generate a stream of indices in correct order for dynamic programming. -- Since the stream generators require concatMap / -- flatten we have to write more specialized code for -- (z:.IX) stuff. class (Index i) => IndexStream i -- | Generate an index stream using LimitTypes. This prevents having -- to figure out how the actual limits for complicated index types (like -- Set) would look like, since for Set, for example, -- the LimitType Set == Int provides just the number of bits. -- -- This generates an index stream suitable for forward structure -- filling. The first index is the smallest (or the first indices -- considered are all equally small in partially ordered sets). Larger -- indices follow up until the largest one. streamUp :: (IndexStream i, Monad m) => LimitType i -> LimitType i -> Stream m i -- | If streamUp generates indices from smallest to largest, then -- streamDown generates indices from largest to smallest. Outside -- grammars make implicit use of this. Asking for an axiom in -- backtracking requests the first element from this stream. streamDown :: (IndexStream i, Monad m) => LimitType i -> LimitType i -> Stream m i -- | The total number of cells that are allocated. newtype CellSize CellSize :: Word -> CellSize -- | In case totalSize or variants thereof produce a size that is -- too big to handle. newtype SizeError SizeError :: String -> SizeError -- | Index structures for complex, heterogeneous indexing. Mostly designed -- for indexing in DP grammars, where the indices work for linear and -- context-free grammars on one or more tapes, for strings, sets, later -- on tree structures. class Index i where { -- | Data structure encoding the upper limit for each array. data family LimitType i :: *; } -- | Given a maximal size, and a current index, calculate the linear index. linearIndex :: Index i => LimitType i -> i -> Int -- | Given the LimitType, return the number of cells required for -- storage. size :: Index i => LimitType i -> Int -- | Check if an index is within the bounds. inBounds :: Index i => LimitType i -> i -> Bool -- | A lower bound of zero zeroBound :: Index i => i -- | A lower bound of zero but for a LimitType i. zeroBound' :: Index i => LimitType i -- | The list of cell sizes for each dimension. its product yields the -- total size. totalSize :: Index i => LimitType i -> [Integer] -- | Given the maximal number of cells (Word, because this is the -- pointer limit for the machine), and the list of sizes, will check if -- this is still legal. Consider dividing the Word by the actual -- memory requirements for each cell, to get better exception handling -- for too large arrays. -- -- One list should be given for each array. sizeIsValid :: Monad m => Word -> [[Integer]] -> ExceptT SizeError m CellSize -- | freezeTables freezes a stack of tables. class FreezeTables m t where { type family Frozen t :: *; } freezeTables :: FreezeTables m t => t -> m (Frozen t) data PAErrors PAEUpperBound :: PAErrors class (Index sh) => PrimArrayMap arr sh e e' -- | Map a function over each element, keeping the shape intact. map :: PrimArrayMap arr sh e e' => (e -> e') -> arr sh e -> arr sh e' -- | The core set of functions on immutable arrays. class (Index sh) => PrimArrayOps arr sh elm -- | Returns the bounds of an immutable array, again inclusive bounds: -- [lb..ub] . upperBound :: PrimArrayOps arr sh elm => arr sh elm -> LimitType sh -- | Freezes a mutable array an returns its immutable version. This -- operation is O(1) and both arrays share the same memory. Do not -- use the mutable array afterwards. unsafeFreeze :: (PrimArrayOps arr sh elm, PrimMonad m) => MutArr m (arr sh elm) -> m (arr sh elm) -- | Thaw an immutable array into a mutable one. Both versions share -- memory. unsafeThaw :: (PrimArrayOps arr sh elm, PrimMonad m) => arr sh elm -> m (MutArr m (arr sh elm)) -- | Extract a single element from the array. Generally unsafe as not -- bounds-checking is performed. unsafeIndex :: PrimArrayOps arr sh elm => arr sh elm -> sh -> elm -- | Savely transform the shape space of a table. transformShape :: (PrimArrayOps arr sh elm, Index sh') => (LimitType sh -> LimitType sh') -> arr sh elm -> arr sh' elm -- | The core set of operations for monadic arrays. class (Index sh) => MPrimArrayOps arr sh elm -- | Return the bounds of the array. All bounds are inclusive, as in -- [lb..ub] upperBoundM :: MPrimArrayOps arr sh elm => MutArr m (arr sh elm) -> LimitType sh -- | Given lower and upper bounds and a list of all elements, -- produce a mutable array. fromListM :: (MPrimArrayOps arr sh elm, PrimMonad m) => LimitType sh -> [elm] -> m (MutArr m (arr sh elm)) -- | Creates a new array with the given bounds with each element within the -- array being in an undefined state. newM :: (MPrimArrayOps arr sh elm, PrimMonad m) => LimitType sh -> m (MutArr m (arr sh elm)) -- | Creates a new array with all elements being equal to elm. newWithM :: (MPrimArrayOps arr sh elm, PrimMonad m) => LimitType sh -> elm -> m (MutArr m (arr sh elm)) -- | Reads a single element in the array. readM :: (MPrimArrayOps arr sh elm, PrimMonad m) => MutArr m (arr sh elm) -> sh -> m elm -- | Writes a single element in the array. writeM :: (MPrimArrayOps arr sh elm, PrimMonad m) => MutArr m (arr sh elm) -> sh -> elm -> m () -- | Mutable version of an array. data family MutArr (m :: * -> *) (arr :: *) :: * -- | Returns true if the index is valid for the array. inBoundsM :: (Monad m, MPrimArrayOps arr sh elm) => MutArr m (arr sh elm) -> sh -> Bool -- | Construct a mutable primitive array from a lower and an upper bound, a -- default element, and a list of associations. fromAssocsM :: (PrimMonad m, MPrimArrayOps arr sh elm) => LimitType sh -> elm -> [(sh, elm)] -> m (MutArr m (arr sh elm)) -- | Initialize an immutable array but stay within the primitive monad -- m. newWithPA :: (PrimMonad m, MPrimArrayOps arr sh elm, PrimArrayOps arr sh elm) => LimitType sh -> elm -> m (arr sh elm) -- | Safely prepare a primitive array. -- -- TODO Check if having a MonadError instance degrades -- performance. (We should see this once the test with NeedlemanWunsch is -- under way). safeNewWithPA :: forall m arr sh elm. (PrimMonad m, MonadError PAErrors m, MPrimArrayOps arr sh elm, PrimArrayOps arr sh elm) => LimitType sh -> elm -> m (arr sh elm) -- | Return all associations from an array. assocs :: forall arr sh elm. (IndexStream sh, PrimArrayOps arr sh elm) => arr sh elm -> [(sh, elm)] -- | Creates an immutable array from lower and upper bounds and a complete -- list of elements. fromList :: (PrimArrayOps arr sh elm, MPrimArrayOps arr sh elm) => LimitType sh -> [elm] -> arr sh elm -- | Creates an immutable array from lower and upper bounds, a default -- element, and a list of associations. fromAssocs :: (PrimArrayOps arr sh elm, MPrimArrayOps arr sh elm) => LimitType sh -> elm -> [(sh, elm)] -> arr sh elm -- | Returns all elements of an immutable array as a list. toList :: forall arr sh elm. (IndexStream sh, PrimArrayOps arr sh elm) => arr sh elm -> [elm] data Boxed sh e Boxed :: !LimitType sh -> !Vector e -> Boxed sh e data Unboxed sh e Unboxed :: !LimitType sh -> !Vector e -> Unboxed sh e -- | Phantom type for Complement indices. data C -- | Phantom type for Outside indices. data O -- | Phantom type for Inside indices. data I -- | Certain sets have an interface, a particular element with special -- meaning. In this module, certain `meanings' are already -- provided. These include a First element and a Last -- element. We phantom-type these to reduce programming overhead. newtype Boundary boundaryType ioc Boundary :: Int -> Boundary boundaryType ioc [getBoundary] :: Boundary boundaryType ioc -> Int -- | Assuming a bitset on bits [0 .. highbit], we can apply a mask -- that stretches out those bits over [0 .. higherBit] with -- highbit <= higherBit. Any active interfaces are correctly -- set as well. class ApplyMask s applyMask :: ApplyMask s => Mask s -> s -> s -- | Fixed allows us to fix some or all bits of a bitset, thereby -- providing succ/pred operations which are only partially free. -- -- The mask is lazy, this allows us to have undefined for -- l and h. -- -- f = getFixedMask .&. getFixed are the fixed bits. n = -- getFixed .&. complement getFixedMask are the free bits. -- to = complement getFixed is the to move mask n' = -- popShiftR to n yields the population after the move p = -- popPermutation undefined n' yields the new population permutation -- p' = popShiftL to p yields the population moved back -- final = p' .|. f data Fixed t Fixed :: Mask t -> !t -> Fixed t [getFixedMask] :: Fixed t -> Mask t [getFixed] :: Fixed t -> !t -- | Masks are used quite often for different types of bitsets. We liberate -- them as a type family. type family Mask s :: * -- | Successor and Predecessor for sets. Designed as a class to accomodate -- sets with interfaces and without interfaces with one function. -- -- The functions are not written recursively, as we currently only have -- three cases, and we do not want to "reset" while generating successors -- and predecessors. -- -- Note that sets have a partial order. Within the group of element with -- the same popCount, we use popPermutation which has -- the same stepping order for both, setSucc and -- setPred. class SetPredSucc s -- | Set successor. The first argument is the lower set limit, the second -- the upper set limit, the third the current set. setSucc :: SetPredSucc s => Int -> Int -> s -> Maybe s -- | Set predecessor. The first argument is the lower set limit, the second -- the upper set limit, the third the current set. setPred :: SetPredSucc s => Int -> Int -> s -> Maybe s -- | Declare the interface to match anything. -- -- TODO needed? want to use later in ADPfusion data Any -- | Declare the interface to be the end of a path. data Last -- | Declare the interface to be the start of a path. data First streamUpBndMk :: Monad m => b -> p -> a -> m (a, b) streamUpBndStep :: Monad m => p -> Int -> (a, Int) -> m (Step (a, Int) (a :. Boundary boundaryType ioc)) streamDownBndMk :: Monad m => p -> b -> a -> m (a, b) streamDownBndStep :: Monad m => Int -> p -> (a, Int) -> m (Step (a, Int) (a :. Boundary boundaryType ioc)) -- | for Arbitrary arbitraryBitSetMax :: Int -- | Newtype for a bitset. -- -- Int integrates better with the rest of the framework. But we -- should consider moving to Word-based indexing, if possible. newtype BitSet t BitSet :: Int -> BitSet t [_bitSet] :: BitSet t -> Int bitSet :: forall t_aPQq t_aQq3. Iso (BitSet t_aPQq) (BitSet t_aQq3) Int Int -- | The bitset with one interface or boundary. data BitSet1 i ioc BitSet1 :: !BitSet ioc -> !Boundary i ioc -> BitSet1 i ioc [_bitset] :: BitSet1 i ioc -> !BitSet ioc [_boundary] :: BitSet1 i ioc -> !Boundary i ioc bitset :: forall i_aUh6 ioc_aUh7. Lens' (BitSet1 i_aUh6 ioc_aUh7) (BitSet ioc_aUh7) boundary :: forall i_aUh6 ioc_aUh7 i_aUnH. Lens (BitSet1 i_aUh6 ioc_aUh7) (BitSet1 i_aUnH ioc_aUh7) (Boundary i_aUh6 ioc_aUh7) (Boundary i_aUnH ioc_aUh7) -- | A PInt behaves exactly like an Int, but has an -- attached phantom type p. In particular, the Index -- and IndexStream instances are the same as for raw -- Ints. newtype PInt (ioc :: k) (p :: k) PInt :: Int -> PInt [getPInt] :: PInt -> Int pIntI :: Int -> PInt I p pIntO :: Int -> PInt O p pIntC :: Int -> PInt C p -- | A point in a left-linear grammar. The syntactic symbol is in left-most -- position. newtype PointL t PointL :: Int -> PointL t [fromPointL] :: PointL t -> Int pointLI :: Int -> PointL I pointLO :: Int -> PointL O pointLC :: Int -> PointL C -- | A point in a right-linear grammars. newtype PointR t PointR :: Int -> PointR t [fromPointR] :: PointR t -> Int data SP z SP :: !z -> !Int# -> SP z arbMaxPointR :: Int -- | A subword wraps a pair of Int indices i,j with -- i<=j. -- -- Subwords always yield the upper-triangular part of a rect-angular -- array. This gives the quite curious effect that (0,N) points -- to the `largest' index, while (0,0) ... (1,1) ... (k,k) -- ... (N,N) point to the smallest. We do, however, use (0,0) as the -- smallest as (0,k) gives successively smaller upper triangular parts. newtype Subword t Subword :: (Int :. Int) -> Subword t [fromSubword] :: Subword t -> Int :. Int fromSubwordFst :: Subword t -> Int fromSubwordSnd :: Subword t -> Int -- | Create a Subword t where t is inferred. subword :: Int -> Int -> Subword t subwordI :: Int -> Int -> Subword I subwordO :: Int -> Int -> Subword O subwordC :: Int -> Int -> Subword C data Unit t Unit :: Unit t -- | Bounds-checked version of indexing. -- -- First, we check via inBounds, second we check if the linear -- index is outside of the allocated area. (!) :: (Index sh, Unbox p, Show sh, Show (LimitType sh)) => Unboxed sh p -> sh -> p -- | Simple score and distance matrices. These are two-dimensional tables -- together with row and column vectors of names. module Data.PrimitiveArray.ScoreMatrix -- | NxN sized score matrices -- -- TODO needs a vector with the column names! data ScoreMatrix t ScoreMatrix :: !Unboxed ((Z :. Int) :. Int) t -> !Unboxed Int t -> !Vector Text -> !Vector Text -> ScoreMatrix t [scoreMatrix] :: ScoreMatrix t -> !Unboxed ((Z :. Int) :. Int) t [scoreNodes] :: ScoreMatrix t -> !Unboxed Int t [rowNames] :: ScoreMatrix t -> !Vector Text [colNames] :: ScoreMatrix t -> !Vector Text -- | Get the distance between edges (From,To). (.!.) :: Unbox t => ScoreMatrix t -> (Int, Int) -> t -- | If the initial node has a "distance", it'll be here nodeDist :: Unbox t => ScoreMatrix t -> Int -> t -- | Get the name of the node at an row index rowNameOf :: ScoreMatrix t -> Int -> Text -- | Get the name of the node at an column index colNameOf :: ScoreMatrix t -> Int -> Text -- | Number of rows in a score matrix. numRows :: Unbox t => ScoreMatrix t -> Int -- | Number of columns in a score matrix. numCols :: Unbox t => ScoreMatrix t -> Int listOfRowNames :: ScoreMatrix t -> [Text] listOfColNames :: ScoreMatrix t -> [Text] -- | Turns a ScoreMatrix for distances into one scaled by -- "temperature" for Inside/Outside calculations. Each value is scaled by -- k -> exp $ negate k / r * t where r = (n-1) * d d = mean -- of genetic distance -- -- Node scores are turned directly into probabilities. -- -- TODO Again, there is overlap and we should really have newtype -- Distance and friends. -- -- TODO newtype Temperature = Temperature Double -- -- TODO fix for rows /= cols!!! toPartMatrix :: Double -> ScoreMatrix Double -> ScoreMatrix (Log Double) -- | Import data. -- -- TODO Should be generalized because Lib-BiobaseBlast does -- almost the same thing. fromFile :: FilePath -> IO (ScoreMatrix Double) instance (GHC.Show.Show t, Data.Vector.Unboxed.Base.Unbox t) => GHC.Show.Show (Data.PrimitiveArray.ScoreMatrix.ScoreMatrix t)