-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A fast ECS for game engine programming
--   
--   A fast ECS for game engine programming
@package apecs
@version 0.2.4.7

module Apecs.Types

-- | An Entity is really just an Int. The type variable is used to keep
--   track of reads and writes, but can be freely cast.
newtype Entity c
Entity :: Int -> Entity c
[unEntity] :: Entity c -> Int

-- | A slice is a list of entities, represented by a Data.Unbox.Vector of
--   Ints.
newtype Slice c
Slice :: Vector Int -> Slice c
[unSlice] :: Slice c -> Vector Int

-- | A system is a newtype around `ReaderT w IO a`, where <tt>w</tt> is the
--   game world variable.
newtype System w a
System :: ReaderT w IO a -> System w a
[unSystem] :: System w a -> ReaderT w IO a

-- | A component is defined by the type of its storage The storage in turn
--   supplies runtime types for the component. For the component to be
--   valid, its Storage must be in instance of Store.
class (Stores (Storage c) ~ c, Store (Storage c)) => Component c where {
    type family Storage c;
}

-- | A world <a>Has</a> a component if it can produce its Storage
class Component c => Has w c
getStore :: Has w c => System w (Storage c)

-- | Represents a safe access to <tt>c</tt>. A safe access is either a read
--   that might fail, or a write that might delete.
newtype Safe c
Safe :: SafeRW (Storage c) -> Safe c
[getSafe] :: Safe c -> SafeRW (Storage c)

-- | Holds components indexed by entities
class Store s where {
    type family Stores s;
    type family SafeRW s;
}
initStore :: Store s => IO s

-- | Retrieves a component from the store
explGet :: Store s => s -> Int -> IO (SafeRW s)

-- | Writes a component
explSet :: Store s => s -> Int -> Stores s -> IO ()

-- | Destroys the component for the given index.
explDestroy :: Store s => s -> Int -> IO ()

-- | Returns whether there is a component for the given index
explExists :: Store s => s -> Int -> IO Bool

-- | Returns an unboxed vector of member indices
explMembers :: Store s => s -> IO (Vector Int)

-- | Unsafe index to the store. What happens if the component does not
--   exist is left undefined.
explGetUnsafe :: Store s => s -> Int -> IO (Stores s)

-- | Either writes or deletes a component
explSetMaybe :: Store s => s -> Int -> SafeRW s -> IO ()

-- | Removes all components. Equivalent to calling <tt>explDestroy</tt> on
--   each member
explReset :: Store s => s -> IO ()

-- | Monadically iterates over member indices
explImapM_ :: (Store s, MonadIO m) => s -> (Int -> m a) -> m ()

-- | Monadically iterates over member indices
explImapM :: (Store s, MonadIO m) => s -> (Int -> m a) -> m [a]

-- | Modifies an element in the store. Equivalent to reading a value, and
--   then writing the result of the function application.
explModify :: Store s => s -> Int -> (Stores s -> Stores s) -> IO ()

-- | Maps over all elements of this store. Equivalent to getting a list of
--   all entities with this component, and then explModifying each of them.
explCmap :: Store s => s -> (Stores s -> Stores s) -> IO ()
explCmapM_ :: (Store s, MonadIO m) => s -> (Stores s -> m a) -> m ()
explCimapM_ :: (Store s, MonadIO m) => s -> ((Int, Stores s) -> m a) -> m ()
explCmapM :: (Store s, MonadIO m) => s -> (Stores s -> m a) -> m [a]
explCimapM :: (Store s, MonadIO m) => s -> ((Int, Stores s) -> m a) -> m [a]

-- | Class of storages for global values
class (SafeRW s ~ Stores s, Store s) => GlobalStore s

-- | Casts for entities and slices
class Cast m
cast :: forall a. Cast m => m a -> forall b. m b
instance (Apecs.Types.Component t_0, Apecs.Types.Component t_1) => Apecs.Types.Component (t_0, t_1)
instance (Apecs.Types.Has w t_0, Apecs.Types.Has w t_1) => Apecs.Types.Has w (t_0, t_1)
instance (Apecs.Types.Store t_0, Apecs.Types.Store t_1) => Apecs.Types.Store (t_0, t_1)
instance (Apecs.Types.Component t_0, Apecs.Types.Component t_1, Apecs.Types.Component t_2) => Apecs.Types.Component (t_0, t_1, t_2)
instance (Apecs.Types.Has w t_0, Apecs.Types.Has w t_1, Apecs.Types.Has w t_2) => Apecs.Types.Has w (t_0, t_1, t_2)
instance (Apecs.Types.Store t_0, Apecs.Types.Store t_1, Apecs.Types.Store t_2) => Apecs.Types.Store (t_0, t_1, t_2)
instance (Apecs.Types.Component t_0, Apecs.Types.Component t_1, Apecs.Types.Component t_2, Apecs.Types.Component t_3) => Apecs.Types.Component (t_0, t_1, t_2, t_3)
instance (Apecs.Types.Has w t_0, Apecs.Types.Has w t_1, Apecs.Types.Has w t_2, Apecs.Types.Has w t_3) => Apecs.Types.Has w (t_0, t_1, t_2, t_3)
instance (Apecs.Types.Store t_0, Apecs.Types.Store t_1, Apecs.Types.Store t_2, Apecs.Types.Store t_3) => Apecs.Types.Store (t_0, t_1, t_2, t_3)
instance (Apecs.Types.Component t_0, Apecs.Types.Component t_1, Apecs.Types.Component t_2, Apecs.Types.Component t_3, Apecs.Types.Component t_4) => Apecs.Types.Component (t_0, t_1, t_2, t_3, t_4)
instance (Apecs.Types.Has w t_0, Apecs.Types.Has w t_1, Apecs.Types.Has w t_2, Apecs.Types.Has w t_3, Apecs.Types.Has w t_4) => Apecs.Types.Has w (t_0, t_1, t_2, t_3, t_4)
instance (Apecs.Types.Store t_0, Apecs.Types.Store t_1, Apecs.Types.Store t_2, Apecs.Types.Store t_3, Apecs.Types.Store t_4) => Apecs.Types.Store (t_0, t_1, t_2, t_3, t_4)
instance (Apecs.Types.Component t_0, Apecs.Types.Component t_1, Apecs.Types.Component t_2, Apecs.Types.Component t_3, Apecs.Types.Component t_4, Apecs.Types.Component t_5) => Apecs.Types.Component (t_0, t_1, t_2, t_3, t_4, t_5)
instance (Apecs.Types.Has w t_0, Apecs.Types.Has w t_1, Apecs.Types.Has w t_2, Apecs.Types.Has w t_3, Apecs.Types.Has w t_4, Apecs.Types.Has w t_5) => Apecs.Types.Has w (t_0, t_1, t_2, t_3, t_4, t_5)
instance (Apecs.Types.Store t_0, Apecs.Types.Store t_1, Apecs.Types.Store t_2, Apecs.Types.Store t_3, Apecs.Types.Store t_4, Apecs.Types.Store t_5) => Apecs.Types.Store (t_0, t_1, t_2, t_3, t_4, t_5)
instance (Apecs.Types.GlobalStore a, Apecs.Types.GlobalStore b) => Apecs.Types.GlobalStore (a, b)
instance (Apecs.Types.GlobalStore a, Apecs.Types.GlobalStore b, Apecs.Types.GlobalStore c) => Apecs.Types.GlobalStore (a, b, c)
instance Control.Monad.IO.Class.MonadIO (Apecs.Types.System w)
instance GHC.Base.Applicative (Apecs.Types.System w)
instance GHC.Base.Monad (Apecs.Types.System w)
instance GHC.Base.Functor (Apecs.Types.System w)
instance GHC.Base.Monoid (Apecs.Types.Slice c)
instance GHC.Show.Show (Apecs.Types.Slice c)
instance GHC.Show.Show (Apecs.Types.Entity c)
instance GHC.Classes.Ord (Apecs.Types.Entity c)
instance GHC.Classes.Eq (Apecs.Types.Entity c)
instance Apecs.Types.Cast Apecs.Types.Entity
instance Apecs.Types.Cast Apecs.Types.Slice

module Apecs.System

-- | Run a system with a game world
runSystem :: System w a -> w -> IO a

-- | Run a system with a game world
runWith :: w -> System w a -> IO a

-- | A slice containing all entities with component <tt>c</tt>
owners :: forall c w. Has w c => System w (Slice c)

-- | Returns whether the given entity has component <tt>c</tt> For
--   composite components, this indicates whether the component has all its
--   constituents
exists :: forall w c. Has w c => Entity c -> System w Bool

-- | Destroys the component <tt>c</tt> for the given entity
destroy :: forall w c. Has w c => Entity c -> System w ()

-- | Removes all components. Equivalent to manually iterating and deleting,
--   but usually optimized.
resetStore :: forall w c p. Has w c => p c -> System w ()

-- | Gets the component for a given entity. This is a safe access, because
--   the entity might not have the requested components.
get :: forall w c. Has w c => Entity c -> System w (Safe c)

-- | Same as <tt>get</tt>, but does not return a safe value and therefore
--   errors if the target component is not present.
getUnsafe :: forall w c. Has w c => Entity c -> System w c

-- | Writes a component to a given entity. Will overwrite existing
--   components. The type was originally 'Entity c -&gt; c -&gt; System w
--   ()', but is relaxed to 'Entity e' so you don't always have to write
--   'set . cast'
set :: forall w c e. Has w c => Entity e -> c -> System w ()

-- | Same as <tt>set</tt>, but uses Safe to possibly delete a component
set' :: forall w c. Has w c => Entity c -> Safe c -> System w ()

-- | Applies a function if possible. Equivalent to reading, mapping, and
--   writing, but stores can provide optimized implementations.
modify :: forall w c. Has w c => Entity c -> (c -> c) -> System w ()

-- | Monadically iterate a system over all entities that have that
--   component. Note that writing to the store while iterating over it is
--   undefined behaviour.
imapM_ :: forall w c. Has w c => (Entity c -> System w ()) -> System w ()

-- | Monadically iterate a system over all entities that have that
--   component. Note that writing to the store while iterating over it is
--   undefined behaviour.
imapM :: forall w c a. Has w c => (Entity c -> System w a) -> System w [a]

-- | Maps a pure function over all components
cmap :: forall world c. Has world c => (c -> c) -> System world ()

-- | <a>mapM_</a> version of <a>cmap</a>
cmapM_ :: forall w c. Has w c => (c -> System w ()) -> System w ()

-- | indexed <a>cmapM_</a>, also gives the current entity.
cimapM_ :: forall w c. Has w c => ((Entity c, c) -> System w ()) -> System w ()

-- | mapM version of cmap. Can be used to get a list of entities As the
--   type signature implies, and unlike <a>cmap</a>, the return value is
--   not written to the component store.
cmapM :: forall w c a. Has w c => (c -> System w a) -> System w [a]

-- | indexed <a>cmapM</a>, also gives the current entity.
cimapM :: forall w c a. Has w c => ((Entity c, c) -> System w a) -> System w [a]

-- | Maps a function that might delete its components
cmap' :: forall world c. Has world c => (c -> Safe c) -> System world ()

-- | Maps a function over all entities with a <tt>r</tt>, and writes their
--   <tt>w</tt>
rmap :: forall world r w. (Has world w, Has world r) => (r -> w) -> System world ()

-- | Maps a function over all entities with a <tt>r</tt>, and writes or
--   deletes their <tt>w</tt>
rmap' :: forall world r w. (Has world w, Has world r) => (r -> Safe w) -> System world ()

-- | For all entities with a <tt>w</tt>, this map reads their <tt>r</tt>
--   and writes their <tt>w</tt>
wmap :: forall world r w. (Has world w, Has world r) => (Safe r -> w) -> System world ()

-- | For all entities with a <tt>w</tt>, this map reads their <tt>r</tt>
--   and writes or deletes their <tt>w</tt>
wmap' :: forall world r w. (Has world w, Has world r) => (Safe r -> Safe w) -> System world ()

-- | Reads a global value
getGlobal :: forall w c. (Has w c, GlobalStore (Storage c)) => System w c

-- | Writes a global value
setGlobal :: forall w c. (Has w c, GlobalStore (Storage c)) => c -> System w ()

-- | Modifies a global value
modifyGlobal :: forall w c. (Has w c, GlobalStore (Storage c)) => (c -> c) -> System w ()

module Apecs.Stores

-- | A map from Data.Intmap.Strict. O(log(n)) for most operations. Yields
--   safe runtime representations of type <tt>Maybe c</tt>.
data Map c

-- | A store that keeps membership, but holds no values. Produces
--   <tt>flag</tt> runtime values.
data Set c

-- | Class for flags, used by <tt>Set</tt> to yield runtime
--   representations.
class Flag c
flag :: Flag c => c

-- | A cache around another store. The wrapped store must produce safe
--   representations using Maybe. Note that iterating over a cache is
--   linear in its size, so large, sparsely populated caches might actually
--   decrease performance.
data Cache (n :: Nat) s

-- | A Unique contains at most one component. Writing to it overwrites both
--   the previous component and its owner.
data Unique c

-- | Global value. Initialized with <a>mempty</a>
data Global c
class (Store s, SafeRW s ~ Maybe (Stores s)) => Cachable s

-- | Default version of <tt>explSetMaybe</tt>, for your convenience. Can be
--   used when 'SafeRW s ~ Maybe (Stores s)'.
defaultSetMaybe :: (Store s, SafeRW s ~ Maybe (Stores s)) => s -> Int -> Maybe (Stores s) -> IO ()
instance Apecs.Stores.Cachable (Apecs.Stores.Map s)
instance (GHC.TypeNats.KnownNat n, Apecs.Stores.Cachable s) => Apecs.Stores.Cachable (Apecs.Stores.Cache n s)
instance (GHC.TypeNats.KnownNat n, Apecs.Stores.Cachable s) => Apecs.Types.Store (Apecs.Stores.Cache n s)
instance GHC.Base.Monoid c => Apecs.Types.GlobalStore (Apecs.Stores.Global c)
instance GHC.Base.Monoid c => Apecs.Types.Store (Apecs.Stores.Global c)
instance GHC.Base.Monoid c => Apecs.Types.Store (Apecs.Stores.Const c)
instance GHC.Base.Monoid c => Apecs.Types.GlobalStore (Apecs.Stores.Const c)
instance Apecs.Types.Store (Apecs.Stores.Unique c)
instance Apecs.Stores.Flag c => Apecs.Types.Store (Apecs.Stores.Set c)
instance Apecs.Types.Store (Apecs.Stores.Map c)


-- | This module is designed to be imported with qualified
module Apecs.Slice

-- | Slice version of foldM_
foldM_ :: (a -> Entity c -> System w a) -> a -> Slice b -> System w ()

-- | Gets the size of a slice (O(n))
size :: Slice a -> Int

-- | Checks whether an entity is in a slice
elem :: Entity c -> Slice c -> Bool

-- | More polymorphic version of <a>elem</a>
elem' :: Entity a -> Slice b -> Bool

-- | Tests whether a slice is empty (O(1))
null :: Slice a -> Bool

-- | Construct a slice from a list of IDs
fromList :: [Int] -> Slice a

-- | Monadically filter a slice
filterM :: (Entity c -> System w Bool) -> Slice c -> System w (Slice c)

-- | Concatenates two slices. Equivalent to mappend
concat :: Slice a -> Slice b -> Slice c

-- | Slice version of forM_
forM_ :: Monad m => Slice c -> (Entity c -> m b) -> m ()

-- | Slice version of forM
forM :: Monad m => Slice c -> (Entity c -> m a) -> m [a]

-- | Iterates over a slice, and reads the components of the Slice's type
--   argument.
forMC :: forall w c a. Has w c => Slice c -> ((Entity c, Safe c) -> System w a) -> System w [a]

-- | Iterates over a slice, and reads the components of the Slice's type
--   argument.
forMC_ :: forall w c a. Has w c => Slice c -> ((Entity c, Safe c) -> System w a) -> System w ()

-- | Slice version of mapM_
mapM_ :: Monad m => (Entity c -> m a) -> Slice c -> m ()

-- | Slice version of mapM
mapM :: Monad m => (Entity c -> m a) -> Slice c -> m [a]

-- | Iterates over a slice, and reads the components of the Slice's type
--   argument.
mapMC :: forall w c a. Has w c => ((Entity c, Safe c) -> System w a) -> Slice c -> System w [a]

-- | Iterates over a slice, and reads the components of the Slice's type
--   argument.
mapMC_ :: forall w c a. Has w c => ((Entity c, Safe c) -> System w a) -> Slice c -> System w ()
toList :: Slice a -> [Entity a]


-- | Experimental module for logging a store
module Apecs.Logs

-- | A Log is a PureLog with mutable state.
class Log l c
logEmpty :: Log l c => IO (l c)
logOnSet :: Log l c => l c -> Entity a -> Maybe c -> c -> IO ()
logOnDestroy :: Log l c => l c -> Entity a -> c -> IO ()
logReset :: Log l c => l c -> IO ()

-- | A PureLog is a piece of state <tt>l c</tt> that is updated when
--   components <tt>c</tt> are written or destroyed. Note that <tt>l :: *
--   -&gt; *</tt>
class PureLog l c
pureEmpty :: PureLog l c => l c
pureOnSet :: PureLog l c => Entity a -> Maybe c -> c -> l c -> l c
pureOnDestroy :: PureLog l c => Entity a -> c -> l c -> l c

-- | FromPure turns a PureLog into a Log
newtype FromPure l c
FromPure :: (IORef (l c)) -> FromPure l c

-- | A <tt>Logger l</tt> of some store updates its <tt>Log l</tt> with the
--   writes and deletes to store <tt>s</tt>
data Logger l s

-- | Produces the log indicated by the return type.
getLog :: forall w c l. (Store (Storage c), Has w c, HasLog (Storage c) l, Log l c) => System w (l c)

-- | Read the value of an <a>IORef</a>
readIORef :: () => IORef a -> IO a

-- | Composite Log consisting of 1 Log
data LVec1 l c

-- | Composite Log consisting of 2 Logs
data LVec2 l1 l2 c

-- | Composite Log consisting of 3 Logs
data LVec3 l1 l2 l3 c

-- | Hashtable that maintains buckets of entities whose <tt>fromEnum c</tt>
--   produces the same value
data EnumTable c

-- | Query the <tt>EnumTable</tt> by an index (the result of
--   <tt>fromEnum</tt>). Will return an empty slice if <tt>index &lt;
--   0</tt> of <tt>index &gt;= fromEnum (maxBound)</tt>.
byIndex :: EnumTable c -> Int -> System w (Slice c)

-- | Query the <tt>EnumTable</tt> by an example enum. Will not perform
--   bound checks, so crashes if `fromEnum c <a>&amp;&amp; fromEnum c</a>
--   fromEnum maxBound `.
byEnum :: Enum c => EnumTable c -> c -> System w (Slice c)
instance (GHC.Enum.Bounded c, GHC.Enum.Enum c) => Apecs.Logs.Log Apecs.Logs.EnumTable c
instance (Apecs.Logs.Log l1 c, Apecs.Logs.Log l2 c, Apecs.Logs.Log l3 c) => Apecs.Logs.Log (Apecs.Logs.LVec3 l1 l2 l3) c
instance (Apecs.Logs.Log l1 c, Apecs.Logs.Log l2 c) => Apecs.Logs.Log (Apecs.Logs.LVec2 l1 l2) c
instance Apecs.Logs.Log l c => Apecs.Logs.Log (Apecs.Logs.LVec1 l) c
instance Apecs.Logs.HasLog (Apecs.Logs.Logger l s) l
instance (Apecs.Logs.Log l (Apecs.Types.Stores s), Apecs.Stores.Cachable s) => Apecs.Types.Store (Apecs.Logs.Logger l s)
instance Apecs.Logs.PureLog l c => Apecs.Logs.Log (Apecs.Logs.FromPure l) c

module Apecs.Concurrent

-- | Executes a list of systems concurrently, and blocks until all have
--   finished. Provides zero protection against race conditions and other
--   hazards, so use with caution.
concurrently :: [System w ()] -> System w ()

-- | Executes a map in parallel by requesting a slice of all components,
--   and spawning threads iterating over <tt>grainSize</tt> components
--   each.
pcmap :: forall world c. Has world c => Int -> (c -> c) -> System world ()

-- | <tt>rmap</tt> version of <tt>pcmap</tt>
prmap :: forall world r w. (Has world w, Has world r) => Int -> (r -> w) -> System world ()

-- | <tt>wmap</tt> version of <tt>pcmap</tt>
pwmap :: forall world r w. (Has world w, Has world r, Store (Storage r), Store (Storage w)) => Int -> (Safe r -> w) -> System world ()

-- | <tt>cmap'</tt> version of <tt>pcmap</tt>
pcmap' :: forall world c. Has world c => Int -> (c -> Safe c) -> System world ()

-- | <tt>rmap'</tt> version of <tt>pcmap</tt>
prmap' :: forall world r w. (Has world w, Has world r, Store (Storage r), Store (Storage w)) => Int -> (r -> Safe w) -> System world ()

-- | <tt>wmap'</tt> version of <tt>pcmap</tt>
pwmap' :: forall world r w. (Has world w, Has world r, Store (Storage r), Store (Storage w)) => Int -> (Safe r -> Safe w) -> System world ()

module Apecs.Util
initStore :: Store s => IO s

-- | Explicitly invoke the garbage collector
runGC :: System w ()

-- | A proxy entity for TODO
proxy :: Entity c

-- | Secretly just an int in a newtype
data EntityCounter

-- | Bumps the EntityCounter and yields its value
nextEntity :: Has w EntityCounter => System w (Entity ())

-- | Writes the given components to a new entity, and yields that entity
newEntity :: (Store (Storage c), Has w c, Has w EntityCounter) => c -> System w (Entity c)

-- | Quantize turns a world-space coordinate into a table-space coordinate
--   by dividing by the given cell size and rounding towards negative
--   infinity.
quantize :: (Fractional (v a), Integral b, RealFrac a, Functor v) => v a -> v a -> v b

-- | Turns a table-space vector into an integral index, given some table
--   size vector. Yields Nothing for out-of-bounds queries
flatten :: (Applicative v, Integral a, Foldable v) => v a -> v a -> Maybe a

-- | Tests whether a vector is in the region given by 0 and the size vector
--   (inclusive)
inbounds :: (Num a, Ord a, Applicative v, Foldable v) => v a -> v a -> Bool

-- | For two table-space vectors indicating a region's bounds, gives a list
--   of the vectors contained between them. This is useful for querying a
--   spatial hash.
region :: (Enum a, Applicative v, Traversable v) => v a -> v a -> [v a]

-- | flatten, but yields garbage for out-of-bounds vectors.
flatten' :: (Applicative v, Integral a, Foldable v) => v a -> v a -> a

-- | Runs a system and gives its execution time in seconds
timeSystem :: System w a -> System w (Double, a)

-- | Runs a system, discards its output, and gives its execution time in
--   seconds
timeSystem_ :: System w a -> System w Double

-- | imapM return
listAllE :: Has w c => System w [Entity c]

-- | cmapM return
listAllC :: Has w c => System w [c]

-- | cimapM return
listAllEC :: Has w c => System w [(Entity c, c)]
instance GHC.Show.Show Apecs.Util.EntityCounter
instance GHC.Classes.Eq Apecs.Util.EntityCounter
instance GHC.Num.Num Apecs.Util.EntityCounter
instance GHC.Base.Monoid Apecs.Util.EntityCounter
instance Apecs.Types.Component Apecs.Util.EntityCounter

module Apecs.TH

-- | <pre>
--   makeWorld "WorldName" [''Component1, ''Component2, ...]
--   </pre>
--   
--   turns into
--   
--   <pre>
--   data WorldName = WorldName Component1 Component2 ... EntityCounter
--   instance WorldName `Has` Component1 where ...
--   instance WorldName `Has` Component2 where ...
--   ...
--   instance WorldName `Has` EntityCounter where ...
--   
--   initWorldName :: IO WorldName
--   initWorldName = WorldName &lt;$&gt; initStore &lt;*&gt; initStore &lt;*&gt; ... &lt;*&gt; initStore
--   </pre>
--   
--   |
makeWorld :: String -> [Name] -> Q [Dec]

-- | Same as <a>makeWorld</a>, but has no <a>EntityCounter</a>
makeWorldNoEC :: String -> [Name] -> Q [Dec]


-- | This module forms the apecs Prelude. It selectively re-exports the
--   user-facing functions from the submodules.
module Apecs

-- | A system is a newtype around `ReaderT w IO a`, where <tt>w</tt> is the
--   game world variable.
newtype System w a
System :: ReaderT w IO a -> System w a
[unSystem] :: System w a -> ReaderT w IO a

-- | A component is defined by the type of its storage The storage in turn
--   supplies runtime types for the component. For the component to be
--   valid, its Storage must be in instance of Store.
class (Stores (Storage c) ~ c, Store (Storage c)) => Component c where {
    type family Storage c;
}

-- | An Entity is really just an Int. The type variable is used to keep
--   track of reads and writes, but can be freely cast.
newtype Entity c
Entity :: Int -> Entity c
[unEntity] :: Entity c -> Int

-- | A slice is a list of entities, represented by a Data.Unbox.Vector of
--   Ints.
data Slice c

-- | A world <a>Has</a> a component if it can produce its Storage
class Component c => Has w c
getStore :: Has w c => System w (Storage c)

-- | Represents a safe access to <tt>c</tt>. A safe access is either a read
--   that might fail, or a write that might delete.
newtype Safe c
Safe :: SafeRW (Storage c) -> Safe c
[getSafe] :: Safe c -> SafeRW (Storage c)
cast :: forall a. Cast m => m a -> forall b. m b

-- | A map from Data.Intmap.Strict. O(log(n)) for most operations. Yields
--   safe runtime representations of type <tt>Maybe c</tt>.
data Map c

-- | A store that keeps membership, but holds no values. Produces
--   <tt>flag</tt> runtime values.
data Set c

-- | A Unique contains at most one component. Writing to it overwrites both
--   the previous component and its owner.
data Unique c

-- | Global value. Initialized with <a>mempty</a>
data Global c

-- | Class for flags, used by <tt>Set</tt> to yield runtime
--   representations.
class Flag c
flag :: Flag c => c
initStore :: Store s => IO s

-- | Destroys the component <tt>c</tt> for the given entity
destroy :: forall w c. Has w c => Entity c -> System w ()

-- | Returns whether the given entity has component <tt>c</tt> For
--   composite components, this indicates whether the component has all its
--   constituents
exists :: forall w c. Has w c => Entity c -> System w Bool

-- | A slice containing all entities with component <tt>c</tt>
owners :: forall c w. Has w c => System w (Slice c)

-- | Removes all components. Equivalent to manually iterating and deleting,
--   but usually optimized.
resetStore :: forall w c p. Has w c => p c -> System w ()

-- | Gets the component for a given entity. This is a safe access, because
--   the entity might not have the requested components.
get :: forall w c. Has w c => Entity c -> System w (Safe c)

-- | Same as <tt>get</tt>, but does not return a safe value and therefore
--   errors if the target component is not present.
getUnsafe :: forall w c. Has w c => Entity c -> System w c

-- | Writes a component to a given entity. Will overwrite existing
--   components. The type was originally 'Entity c -&gt; c -&gt; System w
--   ()', but is relaxed to 'Entity e' so you don't always have to write
--   'set . cast'
set :: forall w c e. Has w c => Entity e -> c -> System w ()

-- | Same as <tt>set</tt>, but uses Safe to possibly delete a component
set' :: forall w c. Has w c => Entity c -> Safe c -> System w ()

-- | Applies a function if possible. Equivalent to reading, mapping, and
--   writing, but stores can provide optimized implementations.
modify :: forall w c. Has w c => Entity c -> (c -> c) -> System w ()

-- | Maps a pure function over all components
cmap :: forall world c. Has world c => (c -> c) -> System world ()

-- | mapM version of cmap. Can be used to get a list of entities As the
--   type signature implies, and unlike <a>cmap</a>, the return value is
--   not written to the component store.
cmapM :: forall w c a. Has w c => (c -> System w a) -> System w [a]

-- | <a>mapM_</a> version of <a>cmap</a>
cmapM_ :: forall w c. Has w c => (c -> System w ()) -> System w ()

-- | indexed <a>cmapM</a>, also gives the current entity.
cimapM :: forall w c a. Has w c => ((Entity c, c) -> System w a) -> System w [a]

-- | indexed <a>cmapM_</a>, also gives the current entity.
cimapM_ :: forall w c. Has w c => ((Entity c, c) -> System w ()) -> System w ()

-- | Maps a function over all entities with a <tt>r</tt>, and writes or
--   deletes their <tt>w</tt>
rmap' :: forall world r w. (Has world w, Has world r) => (r -> Safe w) -> System world ()

-- | Maps a function over all entities with a <tt>r</tt>, and writes their
--   <tt>w</tt>
rmap :: forall world r w. (Has world w, Has world r) => (r -> w) -> System world ()

-- | For all entities with a <tt>w</tt>, this map reads their <tt>r</tt>
--   and writes their <tt>w</tt>
wmap :: forall world r w. (Has world w, Has world r) => (Safe r -> w) -> System world ()

-- | For all entities with a <tt>w</tt>, this map reads their <tt>r</tt>
--   and writes or deletes their <tt>w</tt>
wmap' :: forall world r w. (Has world w, Has world r) => (Safe r -> Safe w) -> System world ()

-- | Maps a function that might delete its components
cmap' :: forall world c. Has world c => (c -> Safe c) -> System world ()

-- | Reads a global value
getGlobal :: forall w c. (Has w c, GlobalStore (Storage c)) => System w c

-- | Writes a global value
setGlobal :: forall w c. (Has w c, GlobalStore (Storage c)) => c -> System w ()

-- | Modifies a global value
modifyGlobal :: forall w c. (Has w c, GlobalStore (Storage c)) => (c -> c) -> System w ()

-- | Run a system with a game world
runSystem :: System w a -> w -> IO a

-- | Run a system with a game world
runWith :: w -> System w a -> IO a

-- | Explicitly invoke the garbage collector
runGC :: System w ()

-- | Secretly just an int in a newtype
data EntityCounter

-- | Writes the given components to a new entity, and yields that entity
newEntity :: (Store (Storage c), Has w c, Has w EntityCounter) => c -> System w (Entity c)

-- | <pre>
--   makeWorld "WorldName" [''Component1, ''Component2, ...]
--   </pre>
--   
--   turns into
--   
--   <pre>
--   data WorldName = WorldName Component1 Component2 ... EntityCounter
--   instance WorldName `Has` Component1 where ...
--   instance WorldName `Has` Component2 where ...
--   ...
--   instance WorldName `Has` EntityCounter where ...
--   
--   initWorldName :: IO WorldName
--   initWorldName = WorldName &lt;$&gt; initStore &lt;*&gt; initStore &lt;*&gt; ... &lt;*&gt; initStore
--   </pre>
--   
--   |
makeWorld :: String -> [Name] -> Q [Dec]

-- | Retrieves a function of the current environment.
asks :: MonadReader r m => (r -> a) -> m a

-- | Retrieves the monad environment.
ask :: MonadReader r m => m r

-- | Lift a computation from the <a>IO</a> monad.
liftIO :: MonadIO m => forall a. () => IO a -> m a

-- | Lift a computation from the argument monad to the constructed monad.
lift :: MonadTrans t => forall (m :: * -> *) a. Monad m => m a -> t m a
