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


-- | A game engine library for tactical squad ASCII roguelike dungeon crawlers
--   
--   LambdaHack is a Haskell game engine library for ASCII roguelike games
--   of arbitrary theme, size and complexity, with optional tactical squad
--   combat. It's packaged together with a sample dungeon crawler in a
--   quirky fantasy setting. The sample game can be tried out in the
--   browser at <a>http://lambdahack.github.io</a>.
--   
--   Please see the changelog file for recent improvements and the issue
--   tracker for short-term plans. Long term goals include multiplayer
--   tactical squad combat, in-game content creation, auto-balancing and
--   persistent content modification based on player behaviour.
--   Contributions are welcome.
--   
--   Other games known to use the LambdaHack library:
--   
--   <ul>
--   <li>Allure of the Stars, a near-future Sci-Fi game,
--   <a>http://hackage.haskell.org/package/Allure</a></li>
--   </ul>
--   
--   Note: All modules in this library are kept visible, to let games
--   override and reuse them. OTOH, to reflect that some modules are
--   implementation details relative to others, the source code adheres to
--   the following convention. If a module has the same name as a
--   directory, the module is the exclusive interface to the directory. No
--   references to the modules in the directory are allowed except from the
--   interface module. This policy is only binding when developing the
--   library --- library users are free to access any modules, since the
--   library authors are in no position to guess their particular needs.
--   
--   This is a workaround .cabal file, flattened to eliminate internal
--   libraries until generating haddocks for them is fixed. The original
--   .cabal file is in .cabal.bkp file.
@package LambdaHack
@version 0.11.0.1


-- | Custom Prelude, compatible across many GHC versions.
module Game.LambdaHack.Core.Prelude

-- | A fixed-precision integer type with at least the range <tt>[-2^29 ..
--   2^29-1]</tt>. The exact range for a given implementation can be
--   determined by using <a>minBound</a> and <a>maxBound</a> from the
--   <a>Bounded</a> class.
data () => Int

-- | Arbitrary precision integers. In contrast with fixed-size integral
--   types such as <a>Int</a>, the <a>Integer</a> type represents the
--   entire infinite range of integers.
--   
--   Integers are stored in a kind of sign-magnitude form, hence do not
--   expect two's complement form when using bit operations.
--   
--   If the value is small (fit into an <a>Int</a>), <a>IS</a> constructor
--   is used. Otherwise <a>Integer</a> and <a>IN</a> constructors are used
--   to store a <a>BigNat</a> representing respectively the positive or the
--   negative value magnitude.
--   
--   Invariant: <a>Integer</a> and <a>IN</a> are used iff value doesn't fit
--   in <a>IS</a>
data () => Integer

-- | Double-precision floating point numbers. It is desirable that this
--   type be at least equal in range and precision to the IEEE
--   double-precision type.
data () => Double

-- | Single-precision floating point numbers. It is desirable that this
--   type be at least equal in range and precision to the IEEE
--   single-precision type.
data () => Float

-- | Conversion of values to readable <a>String</a>s.
--   
--   Derived instances of <a>Show</a> have the following properties, which
--   are compatible with derived instances of <a>Read</a>:
--   
--   <ul>
--   <li>The result of <a>show</a> is a syntactically correct Haskell
--   expression containing only constants, given the fixity declarations in
--   force at the point where the type is declared. It contains only the
--   constructor names defined in the data type, parentheses, and spaces.
--   When labelled constructor fields are used, braces, commas, field
--   names, and equal signs are also used.</li>
--   <li>If the constructor is defined to be an infix operator, then
--   <a>showsPrec</a> will produce infix applications of the
--   constructor.</li>
--   <li>the representation will be enclosed in parentheses if the
--   precedence of the top-level constructor in <tt>x</tt> is less than
--   <tt>d</tt> (associativity is ignored). Thus, if <tt>d</tt> is
--   <tt>0</tt> then the result is never surrounded in parentheses; if
--   <tt>d</tt> is <tt>11</tt> it is always surrounded in parentheses,
--   unless it is an atomic expression.</li>
--   <li>If the constructor is defined using record syntax, then
--   <a>show</a> will produce the record-syntax form, with the fields given
--   in the same order as the original declaration.</li>
--   </ul>
--   
--   For example, given the declarations
--   
--   <pre>
--   infixr 5 :^:
--   data Tree a =  Leaf a  |  Tree a :^: Tree a
--   </pre>
--   
--   the derived instance of <a>Show</a> is equivalent to
--   
--   <pre>
--   instance (Show a) =&gt; Show (Tree a) where
--   
--          showsPrec d (Leaf m) = showParen (d &gt; app_prec) $
--               showString "Leaf " . showsPrec (app_prec+1) m
--            where app_prec = 10
--   
--          showsPrec d (u :^: v) = showParen (d &gt; up_prec) $
--               showsPrec (up_prec+1) u .
--               showString " :^: "      .
--               showsPrec (up_prec+1) v
--            where up_prec = 5
--   </pre>
--   
--   Note that right-associativity of <tt>:^:</tt> is ignored. For example,
--   
--   <ul>
--   <li><tt><a>show</a> (Leaf 1 :^: Leaf 2 :^: Leaf 3)</tt> produces the
--   string <tt>"Leaf 1 :^: (Leaf 2 :^: Leaf 3)"</tt>.</li>
--   </ul>
class () => Show a

-- | Convert a value to a readable <a>String</a>.
--   
--   <a>showsPrec</a> should satisfy the law
--   
--   <pre>
--   showsPrec d x r ++ s  ==  showsPrec d x (r ++ s)
--   </pre>
--   
--   Derived instances of <a>Read</a> and <a>Show</a> satisfy the
--   following:
--   
--   <ul>
--   <li><tt>(x,"")</tt> is an element of <tt>(<a>readsPrec</a> d
--   (<a>showsPrec</a> d x ""))</tt>.</li>
--   </ul>
--   
--   That is, <a>readsPrec</a> parses the string produced by
--   <a>showsPrec</a>, and delivers the value that <a>showsPrec</a> started
--   with.
showsPrec :: Show a => Int -> a -> ShowS

-- | A specialised variant of <a>showsPrec</a>, using precedence context
--   zero, and returning an ordinary <a>String</a>.
show :: Show a => a -> String

-- | The method <a>showList</a> is provided to allow the programmer to give
--   a specialised way of showing lists of values. For example, this is
--   used by the predefined <a>Show</a> instance of the <a>Char</a> type,
--   where values of type <a>String</a> should be shown in double quotes,
--   rather than between square brackets.
showList :: Show a => [a] -> ShowS

-- | The <a>Bounded</a> class is used to name the upper and lower limits of
--   a type. <a>Ord</a> is not a superclass of <a>Bounded</a> since types
--   that are not totally ordered may also have upper and lower bounds.
--   
--   The <a>Bounded</a> class may be derived for any enumeration type;
--   <a>minBound</a> is the first constructor listed in the <tt>data</tt>
--   declaration and <a>maxBound</a> is the last. <a>Bounded</a> may also
--   be derived for single-constructor datatypes whose constituent types
--   are in <a>Bounded</a>.
class () => Bounded a
minBound :: Bounded a => a
maxBound :: Bounded a => a

-- | Class <a>Enum</a> defines operations on sequentially ordered types.
--   
--   The <tt>enumFrom</tt>... methods are used in Haskell's translation of
--   arithmetic sequences.
--   
--   Instances of <a>Enum</a> may be derived for any enumeration type
--   (types whose constructors have no fields). The nullary constructors
--   are assumed to be numbered left-to-right by <a>fromEnum</a> from
--   <tt>0</tt> through <tt>n-1</tt>. See Chapter 10 of the <i>Haskell
--   Report</i> for more details.
--   
--   For any type that is an instance of class <a>Bounded</a> as well as
--   <a>Enum</a>, the following should hold:
--   
--   <ul>
--   <li>The calls <tt><a>succ</a> <a>maxBound</a></tt> and <tt><a>pred</a>
--   <a>minBound</a></tt> should result in a runtime error.</li>
--   <li><a>fromEnum</a> and <a>toEnum</a> should give a runtime error if
--   the result value is not representable in the result type. For example,
--   <tt><a>toEnum</a> 7 :: <a>Bool</a></tt> is an error.</li>
--   <li><a>enumFrom</a> and <a>enumFromThen</a> should be defined with an
--   implicit bound, thus:</li>
--   </ul>
--   
--   <pre>
--   enumFrom     x   = enumFromTo     x maxBound
--   enumFromThen x y = enumFromThenTo x y bound
--     where
--       bound | fromEnum y &gt;= fromEnum x = maxBound
--             | otherwise                = minBound
--   </pre>
class () => Enum a

-- | the successor of a value. For numeric types, <a>succ</a> adds 1.
succ :: Enum a => a -> a

-- | the predecessor of a value. For numeric types, <a>pred</a> subtracts
--   1.
pred :: Enum a => a -> a

-- | Convert from an <a>Int</a>.
toEnum :: Enum a => Int -> a

-- | Convert to an <a>Int</a>. It is implementation-dependent what
--   <a>fromEnum</a> returns when applied to a value that is too large to
--   fit in an <a>Int</a>.
fromEnum :: Enum a => a -> Int

-- | Used in Haskell's translation of <tt>[n..]</tt> with <tt>[n..] =
--   enumFrom n</tt>, a possible implementation being <tt>enumFrom n = n :
--   enumFrom (succ n)</tt>. For example:
--   
--   <ul>
--   <li><pre>enumFrom 4 :: [Integer] = [4,5,6,7,...]</pre></li>
--   <li><pre>enumFrom 6 :: [Int] = [6,7,8,9,...,maxBound ::
--   Int]</pre></li>
--   </ul>
enumFrom :: Enum a => a -> [a]

-- | Used in Haskell's translation of <tt>[n,n'..]</tt> with <tt>[n,n'..] =
--   enumFromThen n n'</tt>, a possible implementation being
--   <tt>enumFromThen n n' = n : n' : worker (f x) (f x n')</tt>,
--   <tt>worker s v = v : worker s (s v)</tt>, <tt>x = fromEnum n' -
--   fromEnum n</tt> and <tt>f n y | n &gt; 0 = f (n - 1) (succ y) | n &lt;
--   0 = f (n + 1) (pred y) | otherwise = y</tt> For example:
--   
--   <ul>
--   <li><pre>enumFromThen 4 6 :: [Integer] = [4,6,8,10...]</pre></li>
--   <li><pre>enumFromThen 6 2 :: [Int] = [6,2,-2,-6,...,minBound ::
--   Int]</pre></li>
--   </ul>
enumFromThen :: Enum a => a -> a -> [a]

-- | Used in Haskell's translation of <tt>[n..m]</tt> with <tt>[n..m] =
--   enumFromTo n m</tt>, a possible implementation being <tt>enumFromTo n
--   m | n &lt;= m = n : enumFromTo (succ n) m | otherwise = []</tt>. For
--   example:
--   
--   <ul>
--   <li><pre>enumFromTo 6 10 :: [Int] = [6,7,8,9,10]</pre></li>
--   <li><pre>enumFromTo 42 1 :: [Integer] = []</pre></li>
--   </ul>
enumFromTo :: Enum a => a -> a -> [a]

-- | Used in Haskell's translation of <tt>[n,n'..m]</tt> with <tt>[n,n'..m]
--   = enumFromThenTo n n' m</tt>, a possible implementation being
--   <tt>enumFromThenTo n n' m = worker (f x) (c x) n m</tt>, <tt>x =
--   fromEnum n' - fromEnum n</tt>, <tt>c x = bool (&gt;=) (<a>(x</a>
--   0)</tt> <tt>f n y | n &gt; 0 = f (n - 1) (succ y) | n &lt; 0 = f (n +
--   1) (pred y) | otherwise = y</tt> and <tt>worker s c v m | c v m = v :
--   worker s c (s v) m | otherwise = []</tt> For example:
--   
--   <ul>
--   <li><pre>enumFromThenTo 4 2 -6 :: [Integer] =
--   [4,2,0,-2,-4,-6]</pre></li>
--   <li><pre>enumFromThenTo 6 8 2 :: [Int] = []</pre></li>
--   </ul>
enumFromThenTo :: Enum a => a -> a -> a -> [a]

-- | Extracting components of fractions.
class (Real a, Fractional a) => RealFrac a

-- | The function <a>properFraction</a> takes a real fractional number
--   <tt>x</tt> and returns a pair <tt>(n,f)</tt> such that <tt>x =
--   n+f</tt>, and:
--   
--   <ul>
--   <li><tt>n</tt> is an integral number with the same sign as <tt>x</tt>;
--   and</li>
--   <li><tt>f</tt> is a fraction with the same type and sign as
--   <tt>x</tt>, and with absolute value less than <tt>1</tt>.</li>
--   </ul>
--   
--   The default definitions of the <a>ceiling</a>, <a>floor</a>,
--   <a>truncate</a> and <a>round</a> functions are in terms of
--   <a>properFraction</a>.
properFraction :: (RealFrac a, Integral b) => a -> (b, a)

-- | <tt><a>truncate</a> x</tt> returns the integer nearest <tt>x</tt>
--   between zero and <tt>x</tt>
truncate :: (RealFrac a, Integral b) => a -> b

-- | <tt><a>round</a> x</tt> returns the nearest integer to <tt>x</tt>; the
--   even integer if <tt>x</tt> is equidistant between two integers
round :: (RealFrac a, Integral b) => a -> b

-- | <tt><a>ceiling</a> x</tt> returns the least integer not less than
--   <tt>x</tt>
ceiling :: (RealFrac a, Integral b) => a -> b

-- | <tt><a>floor</a> x</tt> returns the greatest integer not greater than
--   <tt>x</tt>
floor :: (RealFrac a, Integral b) => a -> b

-- | Integral numbers, supporting integer division.
--   
--   The Haskell Report defines no laws for <a>Integral</a>. However,
--   <a>Integral</a> instances are customarily expected to define a
--   Euclidean domain and have the following properties for the
--   <a>div</a>/<a>mod</a> and <a>quot</a>/<a>rem</a> pairs, given suitable
--   Euclidean functions <tt>f</tt> and <tt>g</tt>:
--   
--   <ul>
--   <li><tt>x</tt> = <tt>y * quot x y + rem x y</tt> with <tt>rem x y</tt>
--   = <tt>fromInteger 0</tt> or <tt>g (rem x y)</tt> &lt; <tt>g
--   y</tt></li>
--   <li><tt>x</tt> = <tt>y * div x y + mod x y</tt> with <tt>mod x y</tt>
--   = <tt>fromInteger 0</tt> or <tt>f (mod x y)</tt> &lt; <tt>f
--   y</tt></li>
--   </ul>
--   
--   An example of a suitable Euclidean function, for <a>Integer</a>'s
--   instance, is <a>abs</a>.
--   
--   In addition, <a>toInteger</a> should be total, and <a>fromInteger</a>
--   should be a left inverse for it, i.e. <tt>fromInteger (toInteger i) =
--   i</tt>.
class (Real a, Enum a) => Integral a

-- | integer division truncated toward zero
--   
--   WARNING: This function is partial (because it throws when 0 is passed
--   as the divisor) for all the integer types in <tt>base</tt>.
quot :: Integral a => a -> a -> a

-- | integer remainder, satisfying
--   
--   <pre>
--   (x `quot` y)*y + (x `rem` y) == x
--   </pre>
--   
--   WARNING: This function is partial (because it throws when 0 is passed
--   as the divisor) for all the integer types in <tt>base</tt>.
rem :: Integral a => a -> a -> a

-- | integer division truncated toward negative infinity
--   
--   WARNING: This function is partial (because it throws when 0 is passed
--   as the divisor) for all the integer types in <tt>base</tt>.
div :: Integral a => a -> a -> a

-- | integer modulus, satisfying
--   
--   <pre>
--   (x `div` y)*y + (x `mod` y) == x
--   </pre>
--   
--   WARNING: This function is partial (because it throws when 0 is passed
--   as the divisor) for all the integer types in <tt>base</tt>.
mod :: Integral a => a -> a -> a

-- | simultaneous <a>quot</a> and <a>rem</a>
--   
--   WARNING: This function is partial (because it throws when 0 is passed
--   as the divisor) for all the integer types in <tt>base</tt>.
quotRem :: Integral a => a -> a -> (a, a)

-- | simultaneous <a>div</a> and <a>mod</a>
--   
--   WARNING: This function is partial (because it throws when 0 is passed
--   as the divisor) for all the integer types in <tt>base</tt>.
divMod :: Integral a => a -> a -> (a, a)

-- | conversion to <a>Integer</a>
toInteger :: Integral a => a -> Integer
infixl 7 `quot`
infixl 7 `rem`
infixl 7 `div`
infixl 7 `mod`

-- | Parsing of <a>String</a>s, producing values.
--   
--   Derived instances of <a>Read</a> make the following assumptions, which
--   derived instances of <a>Show</a> obey:
--   
--   <ul>
--   <li>If the constructor is defined to be an infix operator, then the
--   derived <a>Read</a> instance will parse only infix applications of the
--   constructor (not the prefix form).</li>
--   <li>Associativity is not used to reduce the occurrence of parentheses,
--   although precedence may be.</li>
--   <li>If the constructor is defined using record syntax, the derived
--   <a>Read</a> will parse only the record-syntax form, and furthermore,
--   the fields must be given in the same order as the original
--   declaration.</li>
--   <li>The derived <a>Read</a> instance allows arbitrary Haskell
--   whitespace between tokens of the input string. Extra parentheses are
--   also allowed.</li>
--   </ul>
--   
--   For example, given the declarations
--   
--   <pre>
--   infixr 5 :^:
--   data Tree a =  Leaf a  |  Tree a :^: Tree a
--   </pre>
--   
--   the derived instance of <a>Read</a> in Haskell 2010 is equivalent to
--   
--   <pre>
--   instance (Read a) =&gt; Read (Tree a) where
--   
--           readsPrec d r =  readParen (d &gt; app_prec)
--                            (\r -&gt; [(Leaf m,t) |
--                                    ("Leaf",s) &lt;- lex r,
--                                    (m,t) &lt;- readsPrec (app_prec+1) s]) r
--   
--                         ++ readParen (d &gt; up_prec)
--                            (\r -&gt; [(u:^:v,w) |
--                                    (u,s) &lt;- readsPrec (up_prec+1) r,
--                                    (":^:",t) &lt;- lex s,
--                                    (v,w) &lt;- readsPrec (up_prec+1) t]) r
--   
--             where app_prec = 10
--                   up_prec = 5
--   </pre>
--   
--   Note that right-associativity of <tt>:^:</tt> is unused.
--   
--   The derived instance in GHC is equivalent to
--   
--   <pre>
--   instance (Read a) =&gt; Read (Tree a) where
--   
--           readPrec = parens $ (prec app_prec $ do
--                                    Ident "Leaf" &lt;- lexP
--                                    m &lt;- step readPrec
--                                    return (Leaf m))
--   
--                        +++ (prec up_prec $ do
--                                    u &lt;- step readPrec
--                                    Symbol ":^:" &lt;- lexP
--                                    v &lt;- step readPrec
--                                    return (u :^: v))
--   
--             where app_prec = 10
--                   up_prec = 5
--   
--           readListPrec = readListPrecDefault
--   </pre>
--   
--   Why do both <a>readsPrec</a> and <a>readPrec</a> exist, and why does
--   GHC opt to implement <a>readPrec</a> in derived <a>Read</a> instances
--   instead of <a>readsPrec</a>? The reason is that <a>readsPrec</a> is
--   based on the <a>ReadS</a> type, and although <a>ReadS</a> is mentioned
--   in the Haskell 2010 Report, it is not a very efficient parser data
--   structure.
--   
--   <a>readPrec</a>, on the other hand, is based on a much more efficient
--   <a>ReadPrec</a> datatype (a.k.a "new-style parsers"), but its
--   definition relies on the use of the <tt>RankNTypes</tt> language
--   extension. Therefore, <a>readPrec</a> (and its cousin,
--   <a>readListPrec</a>) are marked as GHC-only. Nevertheless, it is
--   recommended to use <a>readPrec</a> instead of <a>readsPrec</a>
--   whenever possible for the efficiency improvements it brings.
--   
--   As mentioned above, derived <a>Read</a> instances in GHC will
--   implement <a>readPrec</a> instead of <a>readsPrec</a>. The default
--   implementations of <a>readsPrec</a> (and its cousin, <a>readList</a>)
--   will simply use <a>readPrec</a> under the hood. If you are writing a
--   <a>Read</a> instance by hand, it is recommended to write it like so:
--   
--   <pre>
--   instance <a>Read</a> T where
--     <a>readPrec</a>     = ...
--     <a>readListPrec</a> = <a>readListPrecDefault</a>
--   </pre>
class () => Read a

-- | attempts to parse a value from the front of the string, returning a
--   list of (parsed value, remaining string) pairs. If there is no
--   successful parse, the returned list is empty.
--   
--   Derived instances of <a>Read</a> and <a>Show</a> satisfy the
--   following:
--   
--   <ul>
--   <li><tt>(x,"")</tt> is an element of <tt>(<a>readsPrec</a> d
--   (<a>showsPrec</a> d x ""))</tt>.</li>
--   </ul>
--   
--   That is, <a>readsPrec</a> parses the string produced by
--   <a>showsPrec</a>, and delivers the value that <a>showsPrec</a> started
--   with.
readsPrec :: Read a => Int -> ReadS a

-- | The method <a>readList</a> is provided to allow the programmer to give
--   a specialised way of parsing lists of values. For example, this is
--   used by the predefined <a>Read</a> instance of the <a>Char</a> type,
--   where values of type <a>String</a> should be are expected to use
--   double quotes, rather than square brackets.
readList :: Read a => ReadS [a]
data () => Bool
False :: Bool
True :: Bool

-- | A value of type <tt><a>IO</a> a</tt> is a computation which, when
--   performed, does some I/O before returning a value of type <tt>a</tt>.
--   
--   There is really only one way to "perform" an I/O action: bind it to
--   <tt>Main.main</tt> in your program. When your program is run, the I/O
--   will be performed. It isn't possible to perform I/O from an arbitrary
--   function, unless that function is itself in the <a>IO</a> monad and
--   called at some point, directly or indirectly, from <tt>Main.main</tt>.
--   
--   <a>IO</a> is a monad, so <a>IO</a> actions can be combined using
--   either the do-notation or the <a>&gt;&gt;</a> and <a>&gt;&gt;=</a>
--   operations from the <a>Monad</a> class.
data () => IO a

-- | The <a>Ord</a> class is used for totally ordered datatypes.
--   
--   Instances of <a>Ord</a> can be derived for any user-defined datatype
--   whose constituent types are in <a>Ord</a>. The declared order of the
--   constructors in the data declaration determines the ordering in
--   derived <a>Ord</a> instances. The <a>Ordering</a> datatype allows a
--   single comparison to determine the precise ordering of two objects.
--   
--   <a>Ord</a>, as defined by the Haskell report, implements a total order
--   and has the following properties:
--   
--   <ul>
--   <li><i><b>Comparability</b></i> <tt>x &lt;= y || y &lt;= x</tt> =
--   <a>True</a></li>
--   <li><i><b>Transitivity</b></i> if <tt>x &lt;= y &amp;&amp; y &lt;=
--   z</tt> = <a>True</a>, then <tt>x &lt;= z</tt> = <a>True</a></li>
--   <li><i><b>Reflexivity</b></i> <tt>x &lt;= x</tt> = <a>True</a></li>
--   <li><i><b>Antisymmetry</b></i> if <tt>x &lt;= y &amp;&amp; y &lt;=
--   x</tt> = <a>True</a>, then <tt>x == y</tt> = <a>True</a></li>
--   </ul>
--   
--   The following operator interactions are expected to hold:
--   
--   <ol>
--   <li><tt>x &gt;= y</tt> = <tt>y &lt;= x</tt></li>
--   <li><tt>x &lt; y</tt> = <tt>x &lt;= y &amp;&amp; x /= y</tt></li>
--   <li><tt>x &gt; y</tt> = <tt>y &lt; x</tt></li>
--   <li><tt>x &lt; y</tt> = <tt>compare x y == LT</tt></li>
--   <li><tt>x &gt; y</tt> = <tt>compare x y == GT</tt></li>
--   <li><tt>x == y</tt> = <tt>compare x y == EQ</tt></li>
--   <li><tt>min x y == if x &lt;= y then x else y</tt> = <a>True</a></li>
--   <li><tt>max x y == if x &gt;= y then x else y</tt> = <a>True</a></li>
--   </ol>
--   
--   Note that (7.) and (8.) do <i>not</i> require <a>min</a> and
--   <a>max</a> to return either of their arguments. The result is merely
--   required to <i>equal</i> one of the arguments in terms of <a>(==)</a>.
--   
--   Minimal complete definition: either <a>compare</a> or <a>&lt;=</a>.
--   Using <a>compare</a> can be more efficient for complex types.
class Eq a => Ord a
compare :: Ord a => a -> a -> Ordering
(<) :: Ord a => a -> a -> Bool
(<=) :: Ord a => a -> a -> Bool
(>) :: Ord a => a -> a -> Bool
(>=) :: Ord a => a -> a -> Bool
max :: Ord a => a -> a -> a
min :: Ord a => a -> a -> a
infix 4 >=
infix 4 <
infix 4 <=
infix 4 >

-- | <a>String</a> is an alias for a list of characters.
--   
--   String constants in Haskell are values of type <a>String</a>. That
--   means if you write a string literal like <tt>"hello world"</tt>, it
--   will have the type <tt>[Char]</tt>, which is the same as
--   <tt>String</tt>.
--   
--   <b>Note:</b> You can ask the compiler to automatically infer different
--   types with the <tt>-XOverloadedStrings</tt> language extension, for
--   example <tt>"hello world" :: Text</tt>. See <a>IsString</a> for more
--   information.
--   
--   Because <tt>String</tt> is just a list of characters, you can use
--   normal list functions to do basic string manipulation. See
--   <a>Data.List</a> for operations on lists.
--   
--   <h3><b>Performance considerations</b></h3>
--   
--   <tt>[Char]</tt> is a relatively memory-inefficient type. It is a
--   linked list of boxed word-size characters, internally it looks
--   something like:
--   
--   <pre>
--   ╭─────┬───┬──╮  ╭─────┬───┬──╮  ╭─────┬───┬──╮  ╭────╮
--   │ (:) │   │ ─┼─&gt;│ (:) │   │ ─┼─&gt;│ (:) │   │ ─┼─&gt;│ [] │
--   ╰─────┴─┼─┴──╯  ╰─────┴─┼─┴──╯  ╰─────┴─┼─┴──╯  ╰────╯
--           v               v               v
--          'a'             'b'             'c'
--   </pre>
--   
--   The <tt>String</tt> "abc" will use <tt>5*3+1 = 16</tt> (in general
--   <tt>5n+1</tt>) words of space in memory.
--   
--   Furthermore, operations like <a>(++)</a> (string concatenation) are
--   <tt>O(n)</tt> (in the left argument).
--   
--   For historical reasons, the <tt>base</tt> library uses <tt>String</tt>
--   in a lot of places for the conceptual simplicity, but library code
--   dealing with user-data should use the <a>text</a> package for Unicode
--   text, or the the <a>bytestring</a> package for binary data.
type String = [Char]

-- | The character type <a>Char</a> is an enumeration whose values
--   represent Unicode (or equivalently ISO/IEC 10646) code points (i.e.
--   characters, see <a>http://www.unicode.org/</a> for details). This set
--   extends the ISO 8859-1 (Latin-1) character set (the first 256
--   characters), which is itself an extension of the ASCII character set
--   (the first 128 characters). A character literal in Haskell has type
--   <a>Char</a>.
--   
--   To convert a <a>Char</a> to or from the corresponding <a>Int</a> value
--   defined by Unicode, use <a>toEnum</a> and <a>fromEnum</a> from the
--   <a>Enum</a> class respectively (or equivalently <a>ord</a> and
--   <a>chr</a>).
data () => Char

-- | A <a>Word</a> is an unsigned integral type, with the same size as
--   <a>Int</a>.
data () => Word
data () => Ordering
LT :: Ordering
EQ :: Ordering
GT :: Ordering

-- | The <a>Maybe</a> type encapsulates an optional value. A value of type
--   <tt><a>Maybe</a> a</tt> either contains a value of type <tt>a</tt>
--   (represented as <tt><a>Just</a> a</tt>), or it is empty (represented
--   as <a>Nothing</a>). Using <a>Maybe</a> is a good way to deal with
--   errors or exceptional cases without resorting to drastic measures such
--   as <a>error</a>.
--   
--   The <a>Maybe</a> type is also a monad. It is a simple kind of error
--   monad, where all errors are represented by <a>Nothing</a>. A richer
--   error monad can be built using the <a>Either</a> type.
data () => Maybe a
Nothing :: Maybe a
Just :: a -> Maybe a

-- | Lifted, homogeneous equality. By lifted, we mean that it can be bogus
--   (deferred type error). By homogeneous, the two types <tt>a</tt> and
--   <tt>b</tt> must have the same kinds.
class a ~# b => (a :: k) ~ (b :: k)
infix 4 ~

-- | Arbitrary-precision rational numbers, represented as a ratio of two
--   <a>Integer</a> values. A rational number may be constructed using the
--   <a>%</a> operator.
type Rational = Ratio Integer

-- | Fractional numbers, supporting real division.
--   
--   The Haskell Report defines no laws for <a>Fractional</a>. However,
--   <tt>(<a>+</a>)</tt> and <tt>(<a>*</a>)</tt> are customarily expected
--   to define a division ring and have the following properties:
--   
--   <ul>
--   <li><i><b><a>recip</a> gives the multiplicative inverse</b></i> <tt>x
--   * recip x</tt> = <tt>recip x * x</tt> = <tt>fromInteger 1</tt></li>
--   <li><i><b>Totality of <a>toRational</a></b></i> <a>toRational</a> is
--   total</li>
--   <li><i><b>Coherence with <a>toRational</a></b></i> if the type also
--   implements <a>Real</a>, then <a>fromRational</a> is a left inverse for
--   <a>toRational</a>, i.e. <tt>fromRational (toRational i) = i</tt></li>
--   </ul>
--   
--   Note that it <i>isn't</i> customarily expected that a type instance of
--   <a>Fractional</a> implement a field. However, all instances in
--   <tt>base</tt> do.
class Num a => Fractional a

-- | Fractional division.
(/) :: Fractional a => a -> a -> a

-- | Reciprocal fraction.
recip :: Fractional a => a -> a

-- | Conversion from a <a>Rational</a> (that is <tt><a>Ratio</a>
--   <a>Integer</a></tt>). A floating literal stands for an application of
--   <a>fromRational</a> to a value of type <a>Rational</a>, so such
--   literals have type <tt>(<a>Fractional</a> a) =&gt; a</tt>.
fromRational :: Fractional a => Rational -> a
infixl 7 /

-- | Real numbers.
--   
--   The Haskell report defines no laws for <a>Real</a>, however
--   <a>Real</a> instances are customarily expected to adhere to the
--   following law:
--   
--   <ul>
--   <li><i><b>Coherence with <a>fromRational</a></b></i> if the type also
--   implements <a>Fractional</a>, then <a>fromRational</a> is a left
--   inverse for <a>toRational</a>, i.e. <tt>fromRational (toRational i) =
--   i</tt></li>
--   </ul>
class (Num a, Ord a) => Real a

-- | the rational equivalent of its real argument with full precision
toRational :: Real a => a -> Rational

-- | The <a>Eq</a> class defines equality (<a>==</a>) and inequality
--   (<a>/=</a>). All the basic datatypes exported by the <a>Prelude</a>
--   are instances of <a>Eq</a>, and <a>Eq</a> may be derived for any
--   datatype whose constituents are also instances of <a>Eq</a>.
--   
--   The Haskell Report defines no laws for <a>Eq</a>. However, instances
--   are encouraged to follow these properties:
--   
--   <ul>
--   <li><i><b>Reflexivity</b></i> <tt>x == x</tt> = <a>True</a></li>
--   <li><i><b>Symmetry</b></i> <tt>x == y</tt> = <tt>y == x</tt></li>
--   <li><i><b>Transitivity</b></i> if <tt>x == y &amp;&amp; y == z</tt> =
--   <a>True</a>, then <tt>x == z</tt> = <a>True</a></li>
--   <li><i><b>Extensionality</b></i> if <tt>x == y</tt> = <a>True</a> and
--   <tt>f</tt> is a function whose return type is an instance of
--   <a>Eq</a>, then <tt>f x == f y</tt> = <a>True</a></li>
--   <li><i><b>Negation</b></i> <tt>x /= y</tt> = <tt>not (x ==
--   y)</tt></li>
--   </ul>
--   
--   Minimal complete definition: either <a>==</a> or <a>/=</a>.
class () => Eq a
(==) :: Eq a => a -> a -> Bool
(/=) :: Eq a => a -> a -> Bool
infix 4 ==
infix 4 /=

-- | The class of monoids (types with an associative binary operation that
--   has an identity). Instances should satisfy the following:
--   
--   <ul>
--   <li><i>Right identity</i> <tt>x <a>&lt;&gt;</a> <a>mempty</a> =
--   x</tt></li>
--   <li><i>Left identity</i> <tt><a>mempty</a> <a>&lt;&gt;</a> x =
--   x</tt></li>
--   <li><i>Associativity</i> <tt>x <a>&lt;&gt;</a> (y <a>&lt;&gt;</a> z) =
--   (x <a>&lt;&gt;</a> y) <a>&lt;&gt;</a> z</tt> (<a>Semigroup</a>
--   law)</li>
--   <li><i>Concatenation</i> <tt><a>mconcat</a> = <a>foldr</a>
--   (<a>&lt;&gt;</a>) <a>mempty</a></tt></li>
--   </ul>
--   
--   You can alternatively define <a>mconcat</a> instead of <a>mempty</a>,
--   in which case the laws are:
--   
--   <ul>
--   <li><i>Unit</i> <tt><a>mconcat</a> (<a>pure</a> x) = x</tt></li>
--   <li><i>Multiplication</i> <tt><a>mconcat</a> (<a>join</a> xss) =
--   <a>mconcat</a> (<a>fmap</a> <a>mconcat</a> xss)</tt></li>
--   <li><i>Subclass</i> <tt><a>mconcat</a> (<tt>toList</tt> xs) =
--   <a>sconcat</a> xs</tt></li>
--   </ul>
--   
--   The method names refer to the monoid of lists under concatenation, but
--   there are many other instances.
--   
--   Some types can be viewed as a monoid in more than one way, e.g. both
--   addition and multiplication on numbers. In such cases we often define
--   <tt>newtype</tt>s and make those instances of <a>Monoid</a>, e.g.
--   <a>Sum</a> and <a>Product</a>.
--   
--   <b>NOTE</b>: <a>Semigroup</a> is a superclass of <a>Monoid</a> since
--   <i>base-4.11.0.0</i>.
class Semigroup a => Monoid a

-- | Identity of <a>mappend</a>
--   
--   <h4><b>Examples</b></h4>
--   
--   <pre>
--   &gt;&gt;&gt; "Hello world" &lt;&gt; mempty
--   "Hello world"
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; mempty &lt;&gt; [1, 2, 3]
--   [1,2,3]
--   </pre>
mempty :: Monoid a => a

-- | An associative operation
--   
--   <b>NOTE</b>: This method is redundant and has the default
--   implementation <tt><a>mappend</a> = (<a>&lt;&gt;</a>)</tt> since
--   <i>base-4.11.0.0</i>. Should it be implemented manually, since
--   <a>mappend</a> is a synonym for (<a>&lt;&gt;</a>), it is expected that
--   the two functions are defined the same way. In a future GHC release
--   <a>mappend</a> will be removed from <a>Monoid</a>.
mappend :: Monoid a => a -> a -> a

-- | Fold a list using the monoid.
--   
--   For most types, the default definition for <a>mconcat</a> will be
--   used, but the function is included in the class definition so that an
--   optimized version can be provided for specific types.
--   
--   <pre>
--   &gt;&gt;&gt; mconcat ["Hello", " ", "Haskell", "!"]
--   "Hello Haskell!"
--   </pre>
mconcat :: Monoid a => [a] -> a

-- | The class of semigroups (types with an associative binary operation).
--   
--   Instances should satisfy the following:
--   
--   <ul>
--   <li><i>Associativity</i> <tt>x <a>&lt;&gt;</a> (y <a>&lt;&gt;</a> z) =
--   (x <a>&lt;&gt;</a> y) <a>&lt;&gt;</a> z</tt></li>
--   </ul>
--   
--   You can alternatively define <a>sconcat</a> instead of
--   (<a>&lt;&gt;</a>), in which case the laws are:
--   
--   <ul>
--   <li><i>Unit</i> <tt><a>sconcat</a> (<a>pure</a> x) = x</tt></li>
--   <li><i>Multiplication</i> <tt><a>sconcat</a> (<a>join</a> xss) =
--   <a>sconcat</a> (<a>fmap</a> <a>sconcat</a> xss)</tt></li>
--   </ul>
class () => Semigroup a

-- | An associative operation.
--   
--   <h4><b>Examples</b></h4>
--   
--   <pre>
--   &gt;&gt;&gt; [1,2,3] &lt;&gt; [4,5,6]
--   [1,2,3,4,5,6]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; Just [1, 2, 3] &lt;&gt; Just [4, 5, 6]
--   Just [1,2,3,4,5,6]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; putStr "Hello, " &lt;&gt; putStrLn "World!"
--   Hello, World!
--   </pre>
(<>) :: Semigroup a => a -> a -> a
infixr 6 <>

-- | A functor with application, providing operations to
--   
--   <ul>
--   <li>embed pure expressions (<a>pure</a>), and</li>
--   <li>sequence computations and combine their results (<a>&lt;*&gt;</a>
--   and <a>liftA2</a>).</li>
--   </ul>
--   
--   A minimal complete definition must include implementations of
--   <a>pure</a> and of either <a>&lt;*&gt;</a> or <a>liftA2</a>. If it
--   defines both, then they must behave the same as their default
--   definitions:
--   
--   <pre>
--   (<a>&lt;*&gt;</a>) = <a>liftA2</a> <a>id</a>
--   </pre>
--   
--   <pre>
--   <a>liftA2</a> f x y = f <a>&lt;$&gt;</a> x <a>&lt;*&gt;</a> y
--   </pre>
--   
--   Further, any definition must satisfy the following:
--   
--   <ul>
--   <li><i>Identity</i> <pre><a>pure</a> <a>id</a> <a>&lt;*&gt;</a> v =
--   v</pre></li>
--   <li><i>Composition</i> <pre><a>pure</a> (.) <a>&lt;*&gt;</a> u
--   <a>&lt;*&gt;</a> v <a>&lt;*&gt;</a> w = u <a>&lt;*&gt;</a> (v
--   <a>&lt;*&gt;</a> w)</pre></li>
--   <li><i>Homomorphism</i> <pre><a>pure</a> f <a>&lt;*&gt;</a>
--   <a>pure</a> x = <a>pure</a> (f x)</pre></li>
--   <li><i>Interchange</i> <pre>u <a>&lt;*&gt;</a> <a>pure</a> y =
--   <a>pure</a> (<a>$</a> y) <a>&lt;*&gt;</a> u</pre></li>
--   </ul>
--   
--   The other methods have the following default definitions, which may be
--   overridden with equivalent specialized implementations:
--   
--   <ul>
--   <li><pre>u <a>*&gt;</a> v = (<a>id</a> <a>&lt;$</a> u)
--   <a>&lt;*&gt;</a> v</pre></li>
--   <li><pre>u <a>&lt;*</a> v = <a>liftA2</a> <a>const</a> u v</pre></li>
--   </ul>
--   
--   As a consequence of these laws, the <a>Functor</a> instance for
--   <tt>f</tt> will satisfy
--   
--   <ul>
--   <li><pre><a>fmap</a> f x = <a>pure</a> f <a>&lt;*&gt;</a> x</pre></li>
--   </ul>
--   
--   It may be useful to note that supposing
--   
--   <pre>
--   forall x y. p (q x y) = f x . g y
--   </pre>
--   
--   it follows from the above that
--   
--   <pre>
--   <a>liftA2</a> p (<a>liftA2</a> q u v) = <a>liftA2</a> f u . <a>liftA2</a> g v
--   </pre>
--   
--   If <tt>f</tt> is also a <a>Monad</a>, it should satisfy
--   
--   <ul>
--   <li><pre><a>pure</a> = <a>return</a></pre></li>
--   <li><pre>m1 <a>&lt;*&gt;</a> m2 = m1 <a>&gt;&gt;=</a> (\x1 -&gt; m2
--   <a>&gt;&gt;=</a> (\x2 -&gt; <a>return</a> (x1 x2)))</pre></li>
--   <li><pre>(<a>*&gt;</a>) = (<a>&gt;&gt;</a>)</pre></li>
--   </ul>
--   
--   (which implies that <a>pure</a> and <a>&lt;*&gt;</a> satisfy the
--   applicative functor laws).
class Functor f => Applicative (f :: Type -> Type)

-- | Lift a value.
pure :: Applicative f => a -> f a

-- | Sequential application.
--   
--   A few functors support an implementation of <a>&lt;*&gt;</a> that is
--   more efficient than the default one.
--   
--   <h4><b>Example</b></h4>
--   
--   Used in combination with <tt>(<tt>&lt;$&gt;</tt>)</tt>,
--   <tt>(<a>&lt;*&gt;</a>)</tt> can be used to build a record.
--   
--   <pre>
--   &gt;&gt;&gt; data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; produceFoo :: Applicative f =&gt; f Foo
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; produceBar :: Applicative f =&gt; f Bar
--   
--   &gt;&gt;&gt; produceBaz :: Applicative f =&gt; f Baz
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; mkState :: Applicative f =&gt; f MyState
--   
--   &gt;&gt;&gt; mkState = MyState &lt;$&gt; produceFoo &lt;*&gt; produceBar &lt;*&gt; produceBaz
--   </pre>
(<*>) :: Applicative f => f (a -> b) -> f a -> f b

-- | Lift a binary function to actions.
--   
--   Some functors support an implementation of <a>liftA2</a> that is more
--   efficient than the default one. In particular, if <a>fmap</a> is an
--   expensive operation, it is likely better to use <a>liftA2</a> than to
--   <a>fmap</a> over the structure and then use <a>&lt;*&gt;</a>.
--   
--   This became a typeclass method in 4.10.0.0. Prior to that, it was a
--   function defined in terms of <a>&lt;*&gt;</a> and <a>fmap</a>.
--   
--   <h4><b>Example</b></h4>
--   
--   <pre>
--   &gt;&gt;&gt; liftA2 (,) (Just 3) (Just 5)
--   Just (3,5)
--   </pre>
liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c

-- | Sequence actions, discarding the value of the first argument.
--   
--   <h4><b>Examples</b></h4>
--   
--   If used in conjunction with the Applicative instance for <a>Maybe</a>,
--   you can chain Maybe computations, with a possible "early return" in
--   case of <a>Nothing</a>.
--   
--   <pre>
--   &gt;&gt;&gt; Just 2 *&gt; Just 3
--   Just 3
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; Nothing *&gt; Just 3
--   Nothing
--   </pre>
--   
--   Of course a more interesting use case would be to have effectful
--   computations instead of just returning pure values.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Char
--   
--   &gt;&gt;&gt; import Text.ParserCombinators.ReadP
--   
--   &gt;&gt;&gt; let p = string "my name is " *&gt; munch1 isAlpha &lt;* eof
--   
--   &gt;&gt;&gt; readP_to_S p "my name is Simon"
--   [("Simon","")]
--   </pre>
(*>) :: Applicative f => f a -> f b -> f b

-- | Sequence actions, discarding the value of the second argument.
(<*) :: Applicative f => f a -> f b -> f a
infixl 4 <*>
infixl 4 *>
infixl 4 <*

-- | A type <tt>f</tt> is a Functor if it provides a function <tt>fmap</tt>
--   which, given any types <tt>a</tt> and <tt>b</tt> lets you apply any
--   function from <tt>(a -&gt; b)</tt> to turn an <tt>f a</tt> into an
--   <tt>f b</tt>, preserving the structure of <tt>f</tt>. Furthermore
--   <tt>f</tt> needs to adhere to the following:
--   
--   <ul>
--   <li><i>Identity</i> <tt><a>fmap</a> <a>id</a> == <a>id</a></tt></li>
--   <li><i>Composition</i> <tt><a>fmap</a> (f . g) == <a>fmap</a> f .
--   <a>fmap</a> g</tt></li>
--   </ul>
--   
--   Note, that the second law follows from the free theorem of the type
--   <a>fmap</a> and the first law, so you need only check that the former
--   condition holds. See
--   <a>https://www.schoolofhaskell.com/user/edwardk/snippets/fmap</a> or
--   <a>https://github.com/quchen/articles/blob/master/second_functor_law.md</a>
--   for an explanation.
class () => Functor (f :: Type -> Type)

-- | <a>fmap</a> is used to apply a function of type <tt>(a -&gt; b)</tt>
--   to a value of type <tt>f a</tt>, where f is a functor, to produce a
--   value of type <tt>f b</tt>. Note that for any type constructor with
--   more than one parameter (e.g., <tt>Either</tt>), only the last type
--   parameter can be modified with <a>fmap</a> (e.g., <tt>b</tt> in
--   `Either a b`).
--   
--   Some type constructors with two parameters or more have a
--   <tt><a>Bifunctor</a></tt> instance that allows both the last and the
--   penultimate parameters to be mapped over.
--   
--   <h4><b>Examples</b></h4>
--   
--   Convert from a <tt><a>Maybe</a> Int</tt> to a <tt>Maybe String</tt>
--   using <a>show</a>:
--   
--   <pre>
--   &gt;&gt;&gt; fmap show Nothing
--   Nothing
--   
--   &gt;&gt;&gt; fmap show (Just 3)
--   Just "3"
--   </pre>
--   
--   Convert from an <tt><a>Either</a> Int Int</tt> to an <tt>Either Int
--   String</tt> using <a>show</a>:
--   
--   <pre>
--   &gt;&gt;&gt; fmap show (Left 17)
--   Left 17
--   
--   &gt;&gt;&gt; fmap show (Right 17)
--   Right "17"
--   </pre>
--   
--   Double each element of a list:
--   
--   <pre>
--   &gt;&gt;&gt; fmap (*2) [1,2,3]
--   [2,4,6]
--   </pre>
--   
--   Apply <a>even</a> to the second element of a pair:
--   
--   <pre>
--   &gt;&gt;&gt; fmap even (2,2)
--   (2,True)
--   </pre>
--   
--   It may seem surprising that the function is only applied to the last
--   element of the tuple compared to the list example above which applies
--   it to every element in the list. To understand, remember that tuples
--   are type constructors with multiple type parameters: a tuple of 3
--   elements <tt>(a,b,c)</tt> can also be written <tt>(,,) a b c</tt> and
--   its <tt>Functor</tt> instance is defined for <tt>Functor ((,,) a
--   b)</tt> (i.e., only the third parameter is free to be mapped over with
--   <tt>fmap</tt>).
--   
--   It explains why <tt>fmap</tt> can be used with tuples containing
--   values of different types as in the following example:
--   
--   <pre>
--   &gt;&gt;&gt; fmap even ("hello", 1.0, 4)
--   ("hello",1.0,True)
--   </pre>
fmap :: Functor f => (a -> b) -> f a -> f b

-- | Replace all locations in the input with the same value. The default
--   definition is <tt><a>fmap</a> . <a>const</a></tt>, but this may be
--   overridden with a more efficient version.
--   
--   <h4><b>Examples</b></h4>
--   
--   Perform a computation with <a>Maybe</a> and replace the result with a
--   constant value if it is <a>Just</a>:
--   
--   <pre>
--   &gt;&gt;&gt; 'a' &lt;$ Just 2
--   Just 'a'
--   
--   &gt;&gt;&gt; 'a' &lt;$ Nothing
--   Nothing
--   </pre>
(<$) :: Functor f => a -> f b -> f a
infixl 4 <$

-- | The <a>Monad</a> class defines the basic operations over a
--   <i>monad</i>, a concept from a branch of mathematics known as
--   <i>category theory</i>. From the perspective of a Haskell programmer,
--   however, it is best to think of a monad as an <i>abstract datatype</i>
--   of actions. Haskell's <tt>do</tt> expressions provide a convenient
--   syntax for writing monadic expressions.
--   
--   Instances of <a>Monad</a> should satisfy the following:
--   
--   <ul>
--   <li><i>Left identity</i> <tt><a>return</a> a <a>&gt;&gt;=</a> k = k
--   a</tt></li>
--   <li><i>Right identity</i> <tt>m <a>&gt;&gt;=</a> <a>return</a> =
--   m</tt></li>
--   <li><i>Associativity</i> <tt>m <a>&gt;&gt;=</a> (\x -&gt; k x
--   <a>&gt;&gt;=</a> h) = (m <a>&gt;&gt;=</a> k) <a>&gt;&gt;=</a>
--   h</tt></li>
--   </ul>
--   
--   Furthermore, the <a>Monad</a> and <a>Applicative</a> operations should
--   relate as follows:
--   
--   <ul>
--   <li><pre><a>pure</a> = <a>return</a></pre></li>
--   <li><pre>m1 <a>&lt;*&gt;</a> m2 = m1 <a>&gt;&gt;=</a> (\x1 -&gt; m2
--   <a>&gt;&gt;=</a> (\x2 -&gt; <a>return</a> (x1 x2)))</pre></li>
--   </ul>
--   
--   The above laws imply:
--   
--   <ul>
--   <li><pre><a>fmap</a> f xs = xs <a>&gt;&gt;=</a> <a>return</a> .
--   f</pre></li>
--   <li><pre>(<a>&gt;&gt;</a>) = (<a>*&gt;</a>)</pre></li>
--   </ul>
--   
--   and that <a>pure</a> and (<a>&lt;*&gt;</a>) satisfy the applicative
--   functor laws.
--   
--   The instances of <a>Monad</a> for lists, <a>Maybe</a> and <a>IO</a>
--   defined in the <a>Prelude</a> satisfy these laws.
class Applicative m => Monad (m :: Type -> Type)

-- | Sequentially compose two actions, passing any value produced by the
--   first as an argument to the second.
--   
--   '<tt>as <a>&gt;&gt;=</a> bs</tt>' can be understood as the <tt>do</tt>
--   expression
--   
--   <pre>
--   do a &lt;- as
--      bs a
--   </pre>
(>>=) :: Monad m => m a -> (a -> m b) -> m b

-- | Sequentially compose two actions, discarding any value produced by the
--   first, like sequencing operators (such as the semicolon) in imperative
--   languages.
--   
--   '<tt>as <a>&gt;&gt;</a> bs</tt>' can be understood as the <tt>do</tt>
--   expression
--   
--   <pre>
--   do as
--      bs
--   </pre>
(>>) :: Monad m => m a -> m b -> m b

-- | Inject a value into the monadic type.
return :: Monad m => a -> m a
infixl 1 >>=
infixl 1 >>

-- | Functors representing data structures that can be transformed to
--   structures of the <i>same shape</i> by performing an
--   <a>Applicative</a> (or, therefore, <a>Monad</a>) action on each
--   element from left to right.
--   
--   A more detailed description of what <i>same shape</i> means, the
--   various methods, how traversals are constructed, and example advanced
--   use-cases can be found in the <b>Overview</b> section of
--   <a>Data.Traversable#overview</a>.
--   
--   For the class laws see the <b>Laws</b> section of
--   <a>Data.Traversable#laws</a>.
class (Functor t, Foldable t) => Traversable (t :: Type -> Type)

-- | Map each element of a structure to an action, evaluate these actions
--   from left to right, and collect the results. For a version that
--   ignores the results see <a>traverse_</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   In the first two examples we show each evaluated action mapping to the
--   output structure.
--   
--   <pre>
--   &gt;&gt;&gt; traverse Just [1,2,3,4]
--   Just [1,2,3,4]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; traverse id [Right 1, Right 2, Right 3, Right 4]
--   Right [1,2,3,4]
--   </pre>
--   
--   In the next examples, we show that <a>Nothing</a> and <a>Left</a>
--   values short circuit the created structure.
--   
--   <pre>
--   &gt;&gt;&gt; traverse (const Nothing) [1,2,3,4]
--   Nothing
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; traverse (\x -&gt; if odd x then Just x else Nothing)  [1,2,3,4]
--   Nothing
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; traverse id [Right 1, Right 2, Right 3, Right 4, Left 0]
--   Left 0
--   </pre>
traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b)

-- | Evaluate each action in the structure from left to right, and collect
--   the results. For a version that ignores the results see
--   <a>sequenceA_</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   For the first two examples we show sequenceA fully evaluating a a
--   structure and collecting the results.
--   
--   <pre>
--   &gt;&gt;&gt; sequenceA [Just 1, Just 2, Just 3]
--   Just [1,2,3]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; sequenceA [Right 1, Right 2, Right 3]
--   Right [1,2,3]
--   </pre>
--   
--   The next two example show <a>Nothing</a> and <a>Just</a> will short
--   circuit the resulting structure if present in the input. For more
--   context, check the <a>Traversable</a> instances for <a>Either</a> and
--   <a>Maybe</a>.
--   
--   <pre>
--   &gt;&gt;&gt; sequenceA [Just 1, Just 2, Just 3, Nothing]
--   Nothing
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; sequenceA [Right 1, Right 2, Right 3, Left 4]
--   Left 4
--   </pre>
sequenceA :: (Traversable t, Applicative f) => t (f a) -> f (t a)

-- | Map each element of a structure to a monadic action, evaluate these
--   actions from left to right, and collect the results. For a version
--   that ignores the results see <a>mapM_</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   <a>mapM</a> is literally a <a>traverse</a> with a type signature
--   restricted to <a>Monad</a>. Its implementation may be more efficient
--   due to additional power of <a>Monad</a>.
mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)

-- | Evaluate each monadic action in the structure from left to right, and
--   collect the results. For a version that ignores the results see
--   <a>sequence_</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   The first two examples are instances where the input and and output of
--   <a>sequence</a> are isomorphic.
--   
--   <pre>
--   &gt;&gt;&gt; sequence $ Right [1,2,3,4]
--   [Right 1,Right 2,Right 3,Right 4]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; sequence $ [Right 1,Right 2,Right 3,Right 4]
--   Right [1,2,3,4]
--   </pre>
--   
--   The following examples demonstrate short circuit behavior for
--   <a>sequence</a>.
--   
--   <pre>
--   &gt;&gt;&gt; sequence $ Left [1,2,3,4]
--   Left [1,2,3,4]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; sequence $ [Left 0, Right 1,Right 2,Right 3,Right 4]
--   Left 0
--   </pre>
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)

-- | The Foldable class represents data structures that can be reduced to a
--   summary value one element at a time. Strict left-associative folds are
--   a good fit for space-efficient reduction, while lazy right-associative
--   folds are a good fit for corecursive iteration, or for folds that
--   short-circuit after processing an initial subsequence of the
--   structure's elements.
--   
--   Instances can be derived automatically by enabling the
--   <tt>DeriveFoldable</tt> extension. For example, a derived instance for
--   a binary tree might be:
--   
--   <pre>
--   {-# LANGUAGE DeriveFoldable #-}
--   data Tree a = Empty
--               | Leaf a
--               | Node (Tree a) a (Tree a)
--       deriving Foldable
--   </pre>
--   
--   A more detailed description can be found in the <b>Overview</b>
--   section of <a>Data.Foldable#overview</a>.
--   
--   For the class laws see the <b>Laws</b> section of
--   <a>Data.Foldable#laws</a>.
class () => Foldable (t :: Type -> Type)

-- | Map each element of the structure into a monoid, and combine the
--   results with <tt>(<a>&lt;&gt;</a>)</tt>. This fold is
--   right-associative and lazy in the accumulator. For strict
--   left-associative folds consider <a>foldMap'</a> instead.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; foldMap Sum [1, 3, 5]
--   Sum {getSum = 9}
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldMap Product [1, 3, 5]
--   Product {getProduct = 15}
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldMap (replicate 3) [1, 2, 3]
--   [1,1,1,2,2,2,3,3,3]
--   </pre>
--   
--   When a Monoid's <tt>(<a>&lt;&gt;</a>)</tt> is lazy in its second
--   argument, <a>foldMap</a> can return a result even from an unbounded
--   structure. For example, lazy accumulation enables
--   <a>Data.ByteString.Builder</a> to efficiently serialise large data
--   structures and produce the output incrementally:
--   
--   <pre>
--   &gt;&gt;&gt; import qualified Data.ByteString.Lazy as L
--   
--   &gt;&gt;&gt; import qualified Data.ByteString.Builder as B
--   
--   &gt;&gt;&gt; let bld :: Int -&gt; B.Builder; bld i = B.intDec i &lt;&gt; B.word8 0x20
--   
--   &gt;&gt;&gt; let lbs = B.toLazyByteString $ foldMap bld [0..]
--   
--   &gt;&gt;&gt; L.take 64 lbs
--   "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24"
--   </pre>
foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m

-- | Right-associative fold of a structure, lazy in the accumulator.
--   
--   In the case of lists, <a>foldr</a>, when applied to a binary operator,
--   a starting value (typically the right-identity of the operator), and a
--   list, reduces the list using the binary operator, from right to left:
--   
--   <pre>
--   foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
--   </pre>
--   
--   Note that since the head of the resulting expression is produced by an
--   application of the operator to the first element of the list, given an
--   operator lazy in its right argument, <a>foldr</a> can produce a
--   terminating expression from an unbounded list.
--   
--   For a general <a>Foldable</a> structure this should be semantically
--   identical to,
--   
--   <pre>
--   foldr f z = <a>foldr</a> f z . <a>toList</a>
--   </pre>
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; foldr (||) False [False, True, False]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr (||) False []
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr (\c acc -&gt; acc ++ [c]) "foo" ['a', 'b', 'c', 'd']
--   "foodcba"
--   </pre>
--   
--   <h5>Infinite structures</h5>
--   
--   ⚠️ Applying <a>foldr</a> to infinite structures usually doesn't
--   terminate.
--   
--   It may still terminate under one of the following conditions:
--   
--   <ul>
--   <li>the folding function is short-circuiting</li>
--   <li>the folding function is lazy on its second argument</li>
--   </ul>
--   
--   <h6>Short-circuiting</h6>
--   
--   <tt>(<a>||</a>)</tt> short-circuits on <a>True</a> values, so the
--   following terminates because there is a <a>True</a> value finitely far
--   from the left side:
--   
--   <pre>
--   &gt;&gt;&gt; foldr (||) False (True : repeat False)
--   True
--   </pre>
--   
--   But the following doesn't terminate:
--   
--   <pre>
--   &gt;&gt;&gt; foldr (||) False (repeat False ++ [True])
--   * Hangs forever *
--   </pre>
--   
--   <h6>Laziness in the second argument</h6>
--   
--   Applying <a>foldr</a> to infinite structures terminates when the
--   operator is lazy in its second argument (the initial accumulator is
--   never used in this case, and so could be left <a>undefined</a>, but
--   <tt>[]</tt> is more clear):
--   
--   <pre>
--   &gt;&gt;&gt; take 5 $ foldr (\i acc -&gt; i : fmap (+3) acc) [] (repeat 1)
--   [1,4,7,10,13]
--   </pre>
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b

-- | A variant of <a>foldr</a> that has no base case, and thus may only be
--   applied to non-empty structures.
--   
--   This function is non-total and will raise a runtime exception if the
--   structure happens to be empty.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (+) [1..4]
--   10
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (+) []
--   Exception: Prelude.foldr1: empty list
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (+) Nothing
--   *** Exception: foldr1: empty structure
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (-) [1..4]
--   -2
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (&amp;&amp;) [True, False, True, True]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (||) [False, False, True, True]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (+) [1..]
--   * Hangs forever *
--   </pre>
foldr1 :: Foldable t => (a -> a -> a) -> t a -> a

-- | Does the element occur in the structure?
--   
--   Note: <a>elem</a> is often used in infix form.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` []
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` [1,2]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` [1,2,3,4,5]
--   True
--   </pre>
--   
--   For infinite structures, the default implementation of <a>elem</a>
--   terminates if the sought-after value exists at a finite distance from
--   the left side of the structure:
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` [1..]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` ([4..] ++ [3])
--   * Hangs forever *
--   </pre>
elem :: (Foldable t, Eq a) => a -> t a -> Bool

-- | The largest element of a non-empty structure.
--   
--   This function is non-total and will raise a runtime exception if the
--   structure happens to be empty. A structure that supports random access
--   and maintains its elements in order should provide a specialised
--   implementation to return the maximum in faster than linear time.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; maximum [1..10]
--   10
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; maximum []
--   *** Exception: Prelude.maximum: empty list
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; maximum Nothing
--   *** Exception: maximum: empty structure
--   </pre>
--   
--   WARNING: This function is partial for possibly-empty structures like
--   lists.
maximum :: (Foldable t, Ord a) => t a -> a

-- | The least element of a non-empty structure.
--   
--   This function is non-total and will raise a runtime exception if the
--   structure happens to be empty. A structure that supports random access
--   and maintains its elements in order should provide a specialised
--   implementation to return the minimum in faster than linear time.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; minimum [1..10]
--   1
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; minimum []
--   *** Exception: Prelude.minimum: empty list
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; minimum Nothing
--   *** Exception: minimum: empty structure
--   </pre>
--   
--   WARNING: This function is partial for possibly-empty structures like
--   lists.
minimum :: (Foldable t, Ord a) => t a -> a

-- | The <a>product</a> function computes the product of the numbers of a
--   structure.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; product []
--   1
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; product [42]
--   42
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; product [1..10]
--   3628800
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; product [4.1, 2.0, 1.7]
--   13.939999999999998
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; product [1..]
--   * Hangs forever *
--   </pre>
product :: (Foldable t, Num a) => t a -> a
infix 4 `elem`

-- | The <a>Either</a> type represents values with two possibilities: a
--   value of type <tt><a>Either</a> a b</tt> is either <tt><a>Left</a>
--   a</tt> or <tt><a>Right</a> b</tt>.
--   
--   The <a>Either</a> type is sometimes used to represent a value which is
--   either correct or an error; by convention, the <a>Left</a> constructor
--   is used to hold an error value and the <a>Right</a> constructor is
--   used to hold a correct value (mnemonic: "right" also means "correct").
--   
--   <h4><b>Examples</b></h4>
--   
--   The type <tt><a>Either</a> <a>String</a> <a>Int</a></tt> is the type
--   of values which can be either a <a>String</a> or an <a>Int</a>. The
--   <a>Left</a> constructor can be used only on <a>String</a>s, and the
--   <a>Right</a> constructor can be used only on <a>Int</a>s:
--   
--   <pre>
--   &gt;&gt;&gt; let s = Left "foo" :: Either String Int
--   
--   &gt;&gt;&gt; s
--   Left "foo"
--   
--   &gt;&gt;&gt; let n = Right 3 :: Either String Int
--   
--   &gt;&gt;&gt; n
--   Right 3
--   
--   &gt;&gt;&gt; :type s
--   s :: Either String Int
--   
--   &gt;&gt;&gt; :type n
--   n :: Either String Int
--   </pre>
--   
--   The <a>fmap</a> from our <a>Functor</a> instance will ignore
--   <a>Left</a> values, but will apply the supplied function to values
--   contained in a <a>Right</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let s = Left "foo" :: Either String Int
--   
--   &gt;&gt;&gt; let n = Right 3 :: Either String Int
--   
--   &gt;&gt;&gt; fmap (*2) s
--   Left "foo"
--   
--   &gt;&gt;&gt; fmap (*2) n
--   Right 6
--   </pre>
--   
--   The <a>Monad</a> instance for <a>Either</a> allows us to chain
--   together multiple actions which may fail, and fail overall if any of
--   the individual steps failed. First we'll write a function that can
--   either parse an <a>Int</a> from a <a>Char</a>, or fail.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Char ( digitToInt, isDigit )
--   
--   &gt;&gt;&gt; :{
--       let parseEither :: Char -&gt; Either String Int
--           parseEither c
--             | isDigit c = Right (digitToInt c)
--             | otherwise = Left "parse error"
--   
--   &gt;&gt;&gt; :}
--   </pre>
--   
--   The following should work, since both <tt>'1'</tt> and <tt>'2'</tt>
--   can be parsed as <a>Int</a>s.
--   
--   <pre>
--   &gt;&gt;&gt; :{
--       let parseMultiple :: Either String Int
--           parseMultiple = do
--             x &lt;- parseEither '1'
--             y &lt;- parseEither '2'
--             return (x + y)
--   
--   &gt;&gt;&gt; :}
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; parseMultiple
--   Right 3
--   </pre>
--   
--   But the following should fail overall, since the first operation where
--   we attempt to parse <tt>'m'</tt> as an <a>Int</a> will fail:
--   
--   <pre>
--   &gt;&gt;&gt; :{
--       let parseMultiple :: Either String Int
--           parseMultiple = do
--             x &lt;- parseEither 'm'
--             y &lt;- parseEither '2'
--             return (x + y)
--   
--   &gt;&gt;&gt; :}
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; parseMultiple
--   Left "parse error"
--   </pre>
data () => Either a b
Left :: a -> Either a b
Right :: b -> Either a b

-- | The Haskell 2010 type for exceptions in the <a>IO</a> monad. Any I/O
--   operation may raise an <a>IOException</a> instead of returning a
--   result. For a more general type of exception, including also those
--   that arise in pure code, see <a>Exception</a>.
--   
--   In Haskell 2010, this is an opaque type.
type IOError = IOException

-- | Trigonometric and hyperbolic functions and related functions.
--   
--   The Haskell Report defines no laws for <a>Floating</a>. However,
--   <tt>(<a>+</a>)</tt>, <tt>(<a>*</a>)</tt> and <a>exp</a> are
--   customarily expected to define an exponential field and have the
--   following properties:
--   
--   <ul>
--   <li><tt>exp (a + b)</tt> = <tt>exp a * exp b</tt></li>
--   <li><tt>exp (fromInteger 0)</tt> = <tt>fromInteger 1</tt></li>
--   </ul>
class Fractional a => Floating a
pi :: Floating a => a
exp :: Floating a => a -> a
log :: Floating a => a -> a
sqrt :: Floating a => a -> a
(**) :: Floating a => a -> a -> a
logBase :: Floating a => a -> a -> a
sin :: Floating a => a -> a
cos :: Floating a => a -> a
tan :: Floating a => a -> a
asin :: Floating a => a -> a
acos :: Floating a => a -> a
atan :: Floating a => a -> a
sinh :: Floating a => a -> a
cosh :: Floating a => a -> a
tanh :: Floating a => a -> a
asinh :: Floating a => a -> a
acosh :: Floating a => a -> a
atanh :: Floating a => a -> a
infixr 8 **

-- | Basic numeric class.
--   
--   The Haskell Report defines no laws for <a>Num</a>. However,
--   <tt>(<a>+</a>)</tt> and <tt>(<a>*</a>)</tt> are customarily expected
--   to define a ring and have the following properties:
--   
--   <ul>
--   <li><i><b>Associativity of <tt>(<a>+</a>)</tt></b></i> <tt>(x + y) +
--   z</tt> = <tt>x + (y + z)</tt></li>
--   <li><i><b>Commutativity of <tt>(<a>+</a>)</tt></b></i> <tt>x + y</tt>
--   = <tt>y + x</tt></li>
--   <li><i><b><tt><a>fromInteger</a> 0</tt> is the additive
--   identity</b></i> <tt>x + fromInteger 0</tt> = <tt>x</tt></li>
--   <li><i><b><a>negate</a> gives the additive inverse</b></i> <tt>x +
--   negate x</tt> = <tt>fromInteger 0</tt></li>
--   <li><i><b>Associativity of <tt>(<a>*</a>)</tt></b></i> <tt>(x * y) *
--   z</tt> = <tt>x * (y * z)</tt></li>
--   <li><i><b><tt><a>fromInteger</a> 1</tt> is the multiplicative
--   identity</b></i> <tt>x * fromInteger 1</tt> = <tt>x</tt> and
--   <tt>fromInteger 1 * x</tt> = <tt>x</tt></li>
--   <li><i><b>Distributivity of <tt>(<a>*</a>)</tt> with respect to
--   <tt>(<a>+</a>)</tt></b></i> <tt>a * (b + c)</tt> = <tt>(a * b) + (a *
--   c)</tt> and <tt>(b + c) * a</tt> = <tt>(b * a) + (c * a)</tt></li>
--   <li><i><b>Coherence with <tt>toInteger</tt></b></i> if the type also
--   implements <a>Integral</a>, then <a>fromInteger</a> is a left inverse
--   for <a>toInteger</a>, i.e. <tt>fromInteger (toInteger i) ==
--   i</tt></li>
--   </ul>
--   
--   Note that it <i>isn't</i> customarily expected that a type instance of
--   both <a>Num</a> and <a>Ord</a> implement an ordered ring. Indeed, in
--   <tt>base</tt> only <a>Integer</a> and <a>Rational</a> do.
class () => Num a
(+) :: Num a => a -> a -> a
(-) :: Num a => a -> a -> a
(*) :: Num a => a -> a -> a

-- | Unary negation.
negate :: Num a => a -> a

-- | Absolute value.
abs :: Num a => a -> a

-- | Sign of a number. The functions <a>abs</a> and <a>signum</a> should
--   satisfy the law:
--   
--   <pre>
--   abs x * signum x == x
--   </pre>
--   
--   For real numbers, the <a>signum</a> is either <tt>-1</tt> (negative),
--   <tt>0</tt> (zero) or <tt>1</tt> (positive).
signum :: Num a => a -> a

-- | Conversion from an <a>Integer</a>. An integer literal represents the
--   application of the function <a>fromInteger</a> to the appropriate
--   value of type <a>Integer</a>, so such literals have type
--   <tt>(<a>Num</a> a) =&gt; a</tt>.
fromInteger :: Num a => Integer -> a
infixl 6 -
infixl 6 +
infixl 7 *

-- | Efficient, machine-independent access to the components of a
--   floating-point number.
class (RealFrac a, Floating a) => RealFloat a

-- | a constant function, returning the radix of the representation (often
--   <tt>2</tt>)
floatRadix :: RealFloat a => a -> Integer

-- | a constant function, returning the number of digits of
--   <a>floatRadix</a> in the significand
floatDigits :: RealFloat a => a -> Int

-- | a constant function, returning the lowest and highest values the
--   exponent may assume
floatRange :: RealFloat a => a -> (Int, Int)

-- | The function <a>decodeFloat</a> applied to a real floating-point
--   number returns the significand expressed as an <a>Integer</a> and an
--   appropriately scaled exponent (an <a>Int</a>). If
--   <tt><a>decodeFloat</a> x</tt> yields <tt>(m,n)</tt>, then <tt>x</tt>
--   is equal in value to <tt>m*b^^n</tt>, where <tt>b</tt> is the
--   floating-point radix, and furthermore, either <tt>m</tt> and
--   <tt>n</tt> are both zero or else <tt>b^(d-1) &lt;= <a>abs</a> m &lt;
--   b^d</tt>, where <tt>d</tt> is the value of <tt><a>floatDigits</a>
--   x</tt>. In particular, <tt><a>decodeFloat</a> 0 = (0,0)</tt>. If the
--   type contains a negative zero, also <tt><a>decodeFloat</a> (-0.0) =
--   (0,0)</tt>. <i>The result of</i> <tt><a>decodeFloat</a> x</tt> <i>is
--   unspecified if either of</i> <tt><a>isNaN</a> x</tt> <i>or</i>
--   <tt><a>isInfinite</a> x</tt> <i>is</i> <a>True</a>.
decodeFloat :: RealFloat a => a -> (Integer, Int)

-- | <a>encodeFloat</a> performs the inverse of <a>decodeFloat</a> in the
--   sense that for finite <tt>x</tt> with the exception of <tt>-0.0</tt>,
--   <tt><a>uncurry</a> <a>encodeFloat</a> (<a>decodeFloat</a> x) = x</tt>.
--   <tt><a>encodeFloat</a> m n</tt> is one of the two closest
--   representable floating-point numbers to <tt>m*b^^n</tt> (or
--   <tt>±Infinity</tt> if overflow occurs); usually the closer, but if
--   <tt>m</tt> contains too many bits, the result may be rounded in the
--   wrong direction.
encodeFloat :: RealFloat a => Integer -> Int -> a

-- | <a>exponent</a> corresponds to the second component of
--   <a>decodeFloat</a>. <tt><a>exponent</a> 0 = 0</tt> and for finite
--   nonzero <tt>x</tt>, <tt><a>exponent</a> x = snd (<a>decodeFloat</a> x)
--   + <a>floatDigits</a> x</tt>. If <tt>x</tt> is a finite floating-point
--   number, it is equal in value to <tt><a>significand</a> x * b ^^
--   <a>exponent</a> x</tt>, where <tt>b</tt> is the floating-point radix.
--   The behaviour is unspecified on infinite or <tt>NaN</tt> values.
exponent :: RealFloat a => a -> Int

-- | The first component of <a>decodeFloat</a>, scaled to lie in the open
--   interval (<tt>-1</tt>,<tt>1</tt>), either <tt>0.0</tt> or of absolute
--   value <tt>&gt;= 1/b</tt>, where <tt>b</tt> is the floating-point
--   radix. The behaviour is unspecified on infinite or <tt>NaN</tt>
--   values.
significand :: RealFloat a => a -> a

-- | multiplies a floating-point number by an integer power of the radix
scaleFloat :: RealFloat a => Int -> a -> a

-- | <a>True</a> if the argument is an IEEE "not-a-number" (NaN) value
isNaN :: RealFloat a => a -> Bool

-- | <a>True</a> if the argument is an IEEE infinity or negative infinity
isInfinite :: RealFloat a => a -> Bool

-- | <a>True</a> if the argument is too small to be represented in
--   normalized format
isDenormalized :: RealFloat a => a -> Bool

-- | <a>True</a> if the argument is an IEEE negative zero
isNegativeZero :: RealFloat a => a -> Bool

-- | <a>True</a> if the argument is an IEEE floating point number
isIEEE :: RealFloat a => a -> Bool

-- | a version of arctangent taking two real floating-point arguments. For
--   real floating <tt>x</tt> and <tt>y</tt>, <tt><a>atan2</a> y x</tt>
--   computes the angle (from the positive x-axis) of the vector from the
--   origin to the point <tt>(x,y)</tt>. <tt><a>atan2</a> y x</tt> returns
--   a value in the range [<tt>-pi</tt>, <tt>pi</tt>]. It follows the
--   Common Lisp semantics for the origin when signed zeroes are supported.
--   <tt><a>atan2</a> y 1</tt>, with <tt>y</tt> in a type that is
--   <a>RealFloat</a>, should return the same value as <tt><a>atan</a>
--   y</tt>. A default definition of <a>atan2</a> is provided, but
--   implementors can provide a more accurate implementation.
atan2 :: RealFloat a => a -> a -> a

-- | When a value is bound in <tt>do</tt>-notation, the pattern on the left
--   hand side of <tt>&lt;-</tt> might not match. In this case, this class
--   provides a function to recover.
--   
--   A <a>Monad</a> without a <a>MonadFail</a> instance may only be used in
--   conjunction with pattern that always match, such as newtypes, tuples,
--   data types with only a single data constructor, and irrefutable
--   patterns (<tt>~pat</tt>).
--   
--   Instances of <a>MonadFail</a> should satisfy the following law:
--   <tt>fail s</tt> should be a left zero for <a>&gt;&gt;=</a>,
--   
--   <pre>
--   fail s &gt;&gt;= f  =  fail s
--   </pre>
--   
--   If your <a>Monad</a> is also <a>MonadPlus</a>, a popular definition is
--   
--   <pre>
--   fail _ = mzero
--   </pre>
--   
--   <tt>fail s</tt> should be an action that runs in the monad itself, not
--   an exception (except in instances of <tt>MonadIO</tt>). In particular,
--   <tt>fail</tt> should not be implemented in terms of <tt>error</tt>.
class Monad m => MonadFail (m :: Type -> Type)
fail :: MonadFail m => String -> m a

-- | The <tt>shows</tt> functions return a function that prepends the
--   output <a>String</a> to an existing <a>String</a>. This allows
--   constant-time concatenation of results using function composition.
type ShowS = String -> String

-- | A parser for a type <tt>a</tt>, represented as a function that takes a
--   <a>String</a> and returns a list of possible parses as
--   <tt>(a,<a>String</a>)</tt> pairs.
--   
--   Note that this kind of backtracking parser is very inefficient;
--   reading a large structure may be quite slow (cf <a>ReadP</a>).
type ReadS a = String -> [(a, String)]

-- | File and directory names are values of type <a>String</a>, whose
--   precise meaning is operating system dependent. Files can be opened,
--   yielding a handle which can then be used to operate on the contents of
--   that file.
type FilePath = String

-- | General coercion to <a>Fractional</a> types.
--   
--   WARNING: This function goes through the <a>Rational</a> type, which
--   does not have values for <tt>NaN</tt> for example. This means it does
--   not round-trip.
--   
--   For <a>Double</a> it also behaves differently with or without -O0:
--   
--   <pre>
--   Prelude&gt; realToFrac nan -- With -O0
--   -Infinity
--   Prelude&gt; realToFrac nan
--   NaN
--   </pre>
realToFrac :: (Real a, Fractional b) => a -> b

-- | Application operator. This operator is redundant, since ordinary
--   application <tt>(f x)</tt> means the same as <tt>(f <a>$</a> x)</tt>.
--   However, <a>$</a> has low, right-associative binding precedence, so it
--   sometimes allows parentheses to be omitted; for example:
--   
--   <pre>
--   f $ g $ h x  =  f (g (h x))
--   </pre>
--   
--   It is also useful in higher-order situations, such as <tt><a>map</a>
--   (<a>$</a> 0) xs</tt>, or <tt><a>zipWith</a> (<a>$</a>) fs xs</tt>.
--   
--   Note that <tt>(<a>$</a>)</tt> is representation-polymorphic in its
--   result type, so that <tt>foo <a>$</a> True</tt> where <tt>foo :: Bool
--   -&gt; Int#</tt> is well-typed.
($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b
infixr 0 $

-- | <a>otherwise</a> is defined as the value <a>True</a>. It helps to make
--   guards more readable. eg.
--   
--   <pre>
--   f x | x &lt; 0     = ...
--       | otherwise = ...
--   </pre>
otherwise :: Bool

-- | Append two lists, i.e.,
--   
--   <pre>
--   [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
--   [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
--   </pre>
--   
--   If the first list is not finite, the result is the first list.
--   
--   WARNING: This function takes linear time in the number of elements of
--   the first list.
(++) :: [a] -> [a] -> [a]
infixr 5 ++

-- | &lt;math&gt;. <a>map</a> <tt>f xs</tt> is the list obtained by
--   applying <tt>f</tt> to each element of <tt>xs</tt>, i.e.,
--   
--   <pre>
--   map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
--   map f [x1, x2, ...] == [f x1, f x2, ...]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; map (+1) [1, 2, 3]
--   [2,3,4]
--   </pre>
map :: (a -> b) -> [a] -> [b]

-- | Determines whether all elements of the structure satisfy the
--   predicate.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) []
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) [1,2]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) [1,2,3,4,5]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) [1..]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) [4..]
--   * Hangs forever *
--   </pre>
all :: Foldable t => (a -> Bool) -> t a -> Bool

-- | <a>error</a> stops execution and displays an error message.
error :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => [Char] -> a

-- | &lt;math&gt;. <a>zipWith</a> generalises <a>zip</a> by zipping with
--   the function given as the first argument, instead of a tupling
--   function.
--   
--   <pre>
--   zipWith (,) xs ys == zip xs ys
--   zipWith f [x1,x2,x3..] [y1,y2,y3..] == [f x1 y1, f x2 y2, f x3 y3..]
--   </pre>
--   
--   For example, <tt><a>zipWith</a> (+)</tt> is applied to two lists to
--   produce the list of corresponding sums:
--   
--   <pre>
--   &gt;&gt;&gt; zipWith (+) [1, 2, 3] [4, 5, 6]
--   [5,7,9]
--   </pre>
--   
--   <a>zipWith</a> is right-lazy:
--   
--   <pre>
--   &gt;&gt;&gt; let f = undefined
--   
--   &gt;&gt;&gt; zipWith f [] undefined
--   []
--   </pre>
--   
--   <a>zipWith</a> is capable of list fusion, but it is restricted to its
--   first list argument and its resulting list.
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
even :: Integral a => a -> Bool

-- | An infix synonym for <a>fmap</a>.
--   
--   The name of this operator is an allusion to <a>$</a>. Note the
--   similarities between their types:
--   
--   <pre>
--    ($)  ::              (a -&gt; b) -&gt;   a -&gt;   b
--   (&lt;$&gt;) :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
--   </pre>
--   
--   Whereas <a>$</a> is function application, <a>&lt;$&gt;</a> is function
--   application lifted over a <a>Functor</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Convert from a <tt><a>Maybe</a> <a>Int</a></tt> to a <tt><a>Maybe</a>
--   <a>String</a></tt> using <a>show</a>:
--   
--   <pre>
--   &gt;&gt;&gt; show &lt;$&gt; Nothing
--   Nothing
--   
--   &gt;&gt;&gt; show &lt;$&gt; Just 3
--   Just "3"
--   </pre>
--   
--   Convert from an <tt><a>Either</a> <a>Int</a> <a>Int</a></tt> to an
--   <tt><a>Either</a> <a>Int</a></tt> <a>String</a> using <a>show</a>:
--   
--   <pre>
--   &gt;&gt;&gt; show &lt;$&gt; Left 17
--   Left 17
--   
--   &gt;&gt;&gt; show &lt;$&gt; Right 17
--   Right "17"
--   </pre>
--   
--   Double each element of a list:
--   
--   <pre>
--   &gt;&gt;&gt; (*2) &lt;$&gt; [1,2,3]
--   [2,4,6]
--   </pre>
--   
--   Apply <a>even</a> to the second element of a pair:
--   
--   <pre>
--   &gt;&gt;&gt; even &lt;$&gt; (2,2)
--   (2,True)
--   </pre>
(<$>) :: Functor f => (a -> b) -> f a -> f b
infixl 4 <$>

-- | Extract the first component of a pair.
fst :: (a, b) -> a

-- | <a>uncurry</a> converts a curried function to a function on pairs.
--   
--   <h4><b>Examples</b></h4>
--   
--   <pre>
--   &gt;&gt;&gt; uncurry (+) (1,2)
--   3
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; uncurry ($) (show, 1)
--   "1"
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; map (uncurry max) [(1,2), (3,4), (6,8)]
--   [2,4,8]
--   </pre>
uncurry :: (a -> b -> c) -> (a, b) -> c

-- | Identity function.
--   
--   <pre>
--   id x = x
--   </pre>
id :: a -> a

-- | &lt;math&gt;. Extract the first element of a list, which must be
--   non-empty.
--   
--   <pre>
--   &gt;&gt;&gt; head [1, 2, 3]
--   1
--   
--   &gt;&gt;&gt; head [1..]
--   1
--   
--   &gt;&gt;&gt; head []
--   *** Exception: Prelude.head: empty list
--   </pre>
--   
--   WARNING: This function is partial. You can use case-matching,
--   <a>uncons</a> or <a>listToMaybe</a> instead.
head :: HasCallStack => [a] -> a

-- | The computation <a>writeFile</a> <tt>file str</tt> function writes the
--   string <tt>str</tt>, to the file <tt>file</tt>.
writeFile :: FilePath -> String -> IO ()

-- | Read a line from the standard input device (same as <a>hGetLine</a>
--   <a>stdin</a>).
getLine :: IO String

-- | The same as <a>putStr</a>, but adds a newline character.
putStrLn :: String -> IO ()

-- | &lt;math&gt;. <a>filter</a>, applied to a predicate and a list,
--   returns the list of those elements that satisfy the predicate; i.e.,
--   
--   <pre>
--   filter p xs = [ x | x &lt;- xs, p x]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; filter odd [1, 2, 3]
--   [1,3]
--   </pre>
filter :: (a -> Bool) -> [a] -> [a]

-- | <a>cycle</a> ties a finite list into a circular one, or equivalently,
--   the infinite repetition of the original list. It is the identity on
--   infinite lists.
--   
--   <pre>
--   &gt;&gt;&gt; cycle []
--   *** Exception: Prelude.cycle: empty list
--   
--   &gt;&gt;&gt; cycle [42]
--   [42,42,42,42,42,42,42,42,42,42...
--   
--   &gt;&gt;&gt; cycle [2, 5, 7]
--   [2,5,7,2,5,7,2,5,7,2,5,7...
--   </pre>
cycle :: HasCallStack => [a] -> [a]

-- | The value of <tt><a>seq</a> a b</tt> is bottom if <tt>a</tt> is
--   bottom, and otherwise equal to <tt>b</tt>. In other words, it
--   evaluates the first argument <tt>a</tt> to weak head normal form
--   (WHNF). <a>seq</a> is usually introduced to improve performance by
--   avoiding unneeded laziness.
--   
--   A note on evaluation order: the expression <tt><a>seq</a> a b</tt>
--   does <i>not</i> guarantee that <tt>a</tt> will be evaluated before
--   <tt>b</tt>. The only guarantee given by <a>seq</a> is that the both
--   <tt>a</tt> and <tt>b</tt> will be evaluated before <a>seq</a> returns
--   a value. In particular, this means that <tt>b</tt> may be evaluated
--   before <tt>a</tt>. If you need to guarantee a specific order of
--   evaluation, you must use the function <tt>pseq</tt> from the
--   "parallel" package.
seq :: forall {r :: RuntimeRep} a (b :: TYPE r). a -> b -> b
infixr 0 `seq`

-- | The concatenation of all the elements of a container of lists.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; concat (Just [1, 2, 3])
--   [1,2,3]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; concat (Left 42)
--   []
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; concat [[1, 2, 3], [4, 5], [6], []]
--   [1,2,3,4,5,6]
--   </pre>
concat :: Foldable t => t [a] -> [a]

-- | &lt;math&gt;. <a>zip</a> takes two lists and returns a list of
--   corresponding pairs.
--   
--   <pre>
--   &gt;&gt;&gt; zip [1, 2] ['a', 'b']
--   [(1,'a'),(2,'b')]
--   </pre>
--   
--   If one input list is shorter than the other, excess elements of the
--   longer list are discarded, even if one of the lists is infinite:
--   
--   <pre>
--   &gt;&gt;&gt; zip [1] ['a', 'b']
--   [(1,'a')]
--   
--   &gt;&gt;&gt; zip [1, 2] ['a']
--   [(1,'a')]
--   
--   &gt;&gt;&gt; zip [] [1..]
--   []
--   
--   &gt;&gt;&gt; zip [1..] []
--   []
--   </pre>
--   
--   <a>zip</a> is right-lazy:
--   
--   <pre>
--   &gt;&gt;&gt; zip [] undefined
--   []
--   
--   &gt;&gt;&gt; zip undefined []
--   *** Exception: Prelude.undefined
--   ...
--   </pre>
--   
--   <a>zip</a> is capable of list fusion, but it is restricted to its
--   first list argument and its resulting list.
zip :: [a] -> [b] -> [(a, b)]

-- | The <a>print</a> function outputs a value of any printable type to the
--   standard output device. Printable types are those that are instances
--   of class <a>Show</a>; <a>print</a> converts values to strings for
--   output using the <a>show</a> operation and adds a newline.
--   
--   For example, a program to print the first 20 integers and their powers
--   of 2 could be written as:
--   
--   <pre>
--   main = print ([(n, 2^n) | n &lt;- [0..19]])
--   </pre>
print :: Show a => a -> IO ()

-- | raise a number to a non-negative integral power
(^) :: (Num a, Integral b) => a -> b -> a
infixr 8 ^

-- | Boolean "and", lazy in the second argument
(&&) :: Bool -> Bool -> Bool
infixr 3 &&

-- | Boolean "or", lazy in the second argument
(||) :: Bool -> Bool -> Bool
infixr 2 ||

-- | Boolean "not"
not :: Bool -> Bool

-- | A variant of <a>error</a> that does not produce a stack trace.
errorWithoutStackTrace :: forall (r :: RuntimeRep) (a :: TYPE r). [Char] -> a

-- | A special case of <a>error</a>. It is expected that compilers will
--   recognize this and insert error messages which are more appropriate to
--   the context in which <a>undefined</a> appears.
undefined :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => a

-- | Same as <a>&gt;&gt;=</a>, but with the arguments interchanged.
(=<<) :: Monad m => (a -> m b) -> m a -> m b
infixr 1 =<<

-- | <tt>const x y</tt> always evaluates to <tt>x</tt>, ignoring its second
--   argument.
--   
--   <pre>
--   &gt;&gt;&gt; const 42 "hello"
--   42
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; map (const 42) [0..3]
--   [42,42,42,42]
--   </pre>
const :: a -> b -> a

-- | Function composition.
(.) :: (b -> c) -> (a -> b) -> a -> c
infixr 9 .

-- | <tt><a>flip</a> f</tt> takes its (first) two arguments in the reverse
--   order of <tt>f</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; flip (++) "hello" "world"
--   "worldhello"
--   </pre>
flip :: (a -> b -> c) -> b -> a -> c

-- | Strict (call-by-value) application operator. It takes a function and
--   an argument, evaluates the argument to weak head normal form (WHNF),
--   then calls the function with that value.
($!) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b
infixr 0 $!

-- | <tt><a>until</a> p f</tt> yields the result of applying <tt>f</tt>
--   until <tt>p</tt> holds.
until :: (a -> Bool) -> (a -> a) -> a -> a

-- | <a>asTypeOf</a> is a type-restricted version of <a>const</a>. It is
--   usually used as an infix operator, and its typing forces its first
--   argument (which is usually overloaded) to have the same type as the
--   second.
asTypeOf :: a -> a -> a

-- | the same as <tt><a>flip</a> (<a>-</a>)</tt>.
--   
--   Because <tt>-</tt> is treated specially in the Haskell grammar,
--   <tt>(-</tt> <i>e</i><tt>)</tt> is not a section, but an application of
--   prefix negation. However, <tt>(<a>subtract</a></tt>
--   <i>exp</i><tt>)</tt> is equivalent to the disallowed section.
subtract :: Num a => a -> a -> a

-- | The <a>maybe</a> function takes a default value, a function, and a
--   <a>Maybe</a> value. If the <a>Maybe</a> value is <a>Nothing</a>, the
--   function returns the default value. Otherwise, it applies the function
--   to the value inside the <a>Just</a> and returns the result.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; maybe False odd (Just 3)
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; maybe False odd Nothing
--   False
--   </pre>
--   
--   Read an integer from a string using <a>readMaybe</a>. If we succeed,
--   return twice the integer; that is, apply <tt>(*2)</tt> to it. If
--   instead we fail to parse an integer, return <tt>0</tt> by default:
--   
--   <pre>
--   &gt;&gt;&gt; import Text.Read ( readMaybe )
--   
--   &gt;&gt;&gt; maybe 0 (*2) (readMaybe "5")
--   10
--   
--   &gt;&gt;&gt; maybe 0 (*2) (readMaybe "")
--   0
--   </pre>
--   
--   Apply <a>show</a> to a <tt>Maybe Int</tt>. If we have <tt>Just n</tt>,
--   we want to show the underlying <a>Int</a> <tt>n</tt>. But if we have
--   <a>Nothing</a>, we return the empty string instead of (for example)
--   "Nothing":
--   
--   <pre>
--   &gt;&gt;&gt; maybe "" show (Just 5)
--   "5"
--   
--   &gt;&gt;&gt; maybe "" show Nothing
--   ""
--   </pre>
maybe :: b -> (a -> b) -> Maybe a -> b

-- | &lt;math&gt;. Extract the elements after the head of a list, which
--   must be non-empty.
--   
--   <pre>
--   &gt;&gt;&gt; tail [1, 2, 3]
--   [2,3]
--   
--   &gt;&gt;&gt; tail [1]
--   []
--   
--   &gt;&gt;&gt; tail []
--   *** Exception: Prelude.tail: empty list
--   </pre>
--   
--   WARNING: This function is partial. You can use case-matching or
--   <a>uncons</a> instead.
tail :: HasCallStack => [a] -> [a]

-- | &lt;math&gt;. Extract the last element of a list, which must be finite
--   and non-empty.
--   
--   <pre>
--   &gt;&gt;&gt; last [1, 2, 3]
--   3
--   
--   &gt;&gt;&gt; last [1..]
--   * Hangs forever *
--   
--   &gt;&gt;&gt; last []
--   *** Exception: Prelude.last: empty list
--   </pre>
--   
--   WARNING: This function is partial. You can use <a>reverse</a> with
--   case-matching, <a>uncons</a> or <a>listToMaybe</a> instead.
last :: HasCallStack => [a] -> a

-- | &lt;math&gt;. Return all the elements of a list except the last one.
--   The list must be non-empty.
--   
--   <pre>
--   &gt;&gt;&gt; init [1, 2, 3]
--   [1,2]
--   
--   &gt;&gt;&gt; init [1]
--   []
--   
--   &gt;&gt;&gt; init []
--   *** Exception: Prelude.init: empty list
--   </pre>
--   
--   WARNING: This function is partial. You can use <a>reverse</a> with
--   case-matching or <a>uncons</a> instead.
init :: HasCallStack => [a] -> [a]

-- | &lt;math&gt;. <a>scanl</a> is similar to <a>foldl</a>, but returns a
--   list of successive reduced values from the left:
--   
--   <pre>
--   scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]
--   </pre>
--   
--   Note that
--   
--   <pre>
--   last (scanl f z xs) == foldl f z xs
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; scanl (+) 0 [1..4]
--   [0,1,3,6,10]
--   
--   &gt;&gt;&gt; scanl (+) 42 []
--   [42]
--   
--   &gt;&gt;&gt; scanl (-) 100 [1..4]
--   [100,99,97,94,90]
--   
--   &gt;&gt;&gt; scanl (\reversedString nextChar -&gt; nextChar : reversedString) "foo" ['a', 'b', 'c', 'd']
--   ["foo","afoo","bafoo","cbafoo","dcbafoo"]
--   
--   &gt;&gt;&gt; scanl (+) 0 [1..]
--   * Hangs forever *
--   </pre>
scanl :: (b -> a -> b) -> b -> [a] -> [b]

-- | &lt;math&gt;. <a>scanl1</a> is a variant of <a>scanl</a> that has no
--   starting value argument:
--   
--   <pre>
--   scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; scanl1 (+) [1..4]
--   [1,3,6,10]
--   
--   &gt;&gt;&gt; scanl1 (+) []
--   []
--   
--   &gt;&gt;&gt; scanl1 (-) [1..4]
--   [1,-1,-4,-8]
--   
--   &gt;&gt;&gt; scanl1 (&amp;&amp;) [True, False, True, True]
--   [True,False,False,False]
--   
--   &gt;&gt;&gt; scanl1 (||) [False, False, True, True]
--   [False,False,True,True]
--   
--   &gt;&gt;&gt; scanl1 (+) [1..]
--   * Hangs forever *
--   </pre>
scanl1 :: (a -> a -> a) -> [a] -> [a]

-- | &lt;math&gt;. <a>scanr</a> is the right-to-left dual of <a>scanl</a>.
--   Note that the order of parameters on the accumulating function are
--   reversed compared to <a>scanl</a>. Also note that
--   
--   <pre>
--   head (scanr f z xs) == foldr f z xs.
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; scanr (+) 0 [1..4]
--   [10,9,7,4,0]
--   
--   &gt;&gt;&gt; scanr (+) 42 []
--   [42]
--   
--   &gt;&gt;&gt; scanr (-) 100 [1..4]
--   [98,-97,99,-96,100]
--   
--   &gt;&gt;&gt; scanr (\nextChar reversedString -&gt; nextChar : reversedString) "foo" ['a', 'b', 'c', 'd']
--   ["abcdfoo","bcdfoo","cdfoo","dfoo","foo"]
--   
--   &gt;&gt;&gt; force $ scanr (+) 0 [1..]
--   *** Exception: stack overflow
--   </pre>
scanr :: (a -> b -> b) -> b -> [a] -> [b]

-- | &lt;math&gt;. <a>scanr1</a> is a variant of <a>scanr</a> that has no
--   starting value argument.
--   
--   <pre>
--   &gt;&gt;&gt; scanr1 (+) [1..4]
--   [10,9,7,4]
--   
--   &gt;&gt;&gt; scanr1 (+) []
--   []
--   
--   &gt;&gt;&gt; scanr1 (-) [1..4]
--   [-2,3,-1,4]
--   
--   &gt;&gt;&gt; scanr1 (&amp;&amp;) [True, False, True, True]
--   [False,False,True,True]
--   
--   &gt;&gt;&gt; scanr1 (||) [True, True, False, False]
--   [True,True,False,False]
--   
--   &gt;&gt;&gt; force $ scanr1 (+) [1..]
--   *** Exception: stack overflow
--   </pre>
scanr1 :: (a -> a -> a) -> [a] -> [a]

-- | <a>iterate</a> <tt>f x</tt> returns an infinite list of repeated
--   applications of <tt>f</tt> to <tt>x</tt>:
--   
--   <pre>
--   iterate f x == [x, f x, f (f x), ...]
--   </pre>
--   
--   Note that <a>iterate</a> is lazy, potentially leading to thunk
--   build-up if the consumer doesn't force each iterate. See
--   <a>iterate'</a> for a strict variant of this function.
--   
--   <pre>
--   &gt;&gt;&gt; take 10 $ iterate not True
--   [True,False,True,False...
--   
--   &gt;&gt;&gt; take 10 $ iterate (+3) 42
--   [42,45,48,51,54,57,60,63...
--   </pre>
iterate :: (a -> a) -> a -> [a]

-- | <a>repeat</a> <tt>x</tt> is an infinite list, with <tt>x</tt> the
--   value of every element.
--   
--   <pre>
--   &gt;&gt;&gt; repeat 17
--   [17,17,17,17,17,17,17,17,17...
--   </pre>
repeat :: a -> [a]

-- | <a>replicate</a> <tt>n x</tt> is a list of length <tt>n</tt> with
--   <tt>x</tt> the value of every element. It is an instance of the more
--   general <a>genericReplicate</a>, in which <tt>n</tt> may be of any
--   integral type.
--   
--   <pre>
--   &gt;&gt;&gt; replicate 0 True
--   []
--   
--   &gt;&gt;&gt; replicate (-1) True
--   []
--   
--   &gt;&gt;&gt; replicate 4 True
--   [True,True,True,True]
--   </pre>
replicate :: Int -> a -> [a]

-- | <a>takeWhile</a>, applied to a predicate <tt>p</tt> and a list
--   <tt>xs</tt>, returns the longest prefix (possibly empty) of
--   <tt>xs</tt> of elements that satisfy <tt>p</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; takeWhile (&lt; 3) [1,2,3,4,1,2,3,4]
--   [1,2]
--   
--   &gt;&gt;&gt; takeWhile (&lt; 9) [1,2,3]
--   [1,2,3]
--   
--   &gt;&gt;&gt; takeWhile (&lt; 0) [1,2,3]
--   []
--   </pre>
takeWhile :: (a -> Bool) -> [a] -> [a]

-- | <a>dropWhile</a> <tt>p xs</tt> returns the suffix remaining after
--   <a>takeWhile</a> <tt>p xs</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; dropWhile (&lt; 3) [1,2,3,4,5,1,2,3]
--   [3,4,5,1,2,3]
--   
--   &gt;&gt;&gt; dropWhile (&lt; 9) [1,2,3]
--   []
--   
--   &gt;&gt;&gt; dropWhile (&lt; 0) [1,2,3]
--   [1,2,3]
--   </pre>
dropWhile :: (a -> Bool) -> [a] -> [a]

-- | <a>take</a> <tt>n</tt>, applied to a list <tt>xs</tt>, returns the
--   prefix of <tt>xs</tt> of length <tt>n</tt>, or <tt>xs</tt> itself if
--   <tt>n &gt;= <a>length</a> xs</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 "Hello World!"
--   "Hello"
--   
--   &gt;&gt;&gt; take 3 [1,2,3,4,5]
--   [1,2,3]
--   
--   &gt;&gt;&gt; take 3 [1,2]
--   [1,2]
--   
--   &gt;&gt;&gt; take 3 []
--   []
--   
--   &gt;&gt;&gt; take (-1) [1,2]
--   []
--   
--   &gt;&gt;&gt; take 0 [1,2]
--   []
--   </pre>
--   
--   It is an instance of the more general <a>genericTake</a>, in which
--   <tt>n</tt> may be of any integral type.
take :: Int -> [a] -> [a]

-- | <a>drop</a> <tt>n xs</tt> returns the suffix of <tt>xs</tt> after the
--   first <tt>n</tt> elements, or <tt>[]</tt> if <tt>n &gt;= <a>length</a>
--   xs</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; drop 6 "Hello World!"
--   "World!"
--   
--   &gt;&gt;&gt; drop 3 [1,2,3,4,5]
--   [4,5]
--   
--   &gt;&gt;&gt; drop 3 [1,2]
--   []
--   
--   &gt;&gt;&gt; drop 3 []
--   []
--   
--   &gt;&gt;&gt; drop (-1) [1,2]
--   [1,2]
--   
--   &gt;&gt;&gt; drop 0 [1,2]
--   [1,2]
--   </pre>
--   
--   It is an instance of the more general <a>genericDrop</a>, in which
--   <tt>n</tt> may be of any integral type.
drop :: Int -> [a] -> [a]

-- | <a>splitAt</a> <tt>n xs</tt> returns a tuple where first element is
--   <tt>xs</tt> prefix of length <tt>n</tt> and second element is the
--   remainder of the list:
--   
--   <pre>
--   &gt;&gt;&gt; splitAt 6 "Hello World!"
--   ("Hello ","World!")
--   
--   &gt;&gt;&gt; splitAt 3 [1,2,3,4,5]
--   ([1,2,3],[4,5])
--   
--   &gt;&gt;&gt; splitAt 1 [1,2,3]
--   ([1],[2,3])
--   
--   &gt;&gt;&gt; splitAt 3 [1,2,3]
--   ([1,2,3],[])
--   
--   &gt;&gt;&gt; splitAt 4 [1,2,3]
--   ([1,2,3],[])
--   
--   &gt;&gt;&gt; splitAt 0 [1,2,3]
--   ([],[1,2,3])
--   
--   &gt;&gt;&gt; splitAt (-1) [1,2,3]
--   ([],[1,2,3])
--   </pre>
--   
--   It is equivalent to <tt>(<a>take</a> n xs, <a>drop</a> n xs)</tt> when
--   <tt>n</tt> is not <tt>_|_</tt> (<tt>splitAt _|_ xs = _|_</tt>).
--   <a>splitAt</a> is an instance of the more general
--   <a>genericSplitAt</a>, in which <tt>n</tt> may be of any integral
--   type.
splitAt :: Int -> [a] -> ([a], [a])

-- | <a>span</a>, applied to a predicate <tt>p</tt> and a list <tt>xs</tt>,
--   returns a tuple where first element is longest prefix (possibly empty)
--   of <tt>xs</tt> of elements that satisfy <tt>p</tt> and second element
--   is the remainder of the list:
--   
--   <pre>
--   &gt;&gt;&gt; span (&lt; 3) [1,2,3,4,1,2,3,4]
--   ([1,2],[3,4,1,2,3,4])
--   
--   &gt;&gt;&gt; span (&lt; 9) [1,2,3]
--   ([1,2,3],[])
--   
--   &gt;&gt;&gt; span (&lt; 0) [1,2,3]
--   ([],[1,2,3])
--   </pre>
--   
--   <a>span</a> <tt>p xs</tt> is equivalent to <tt>(<a>takeWhile</a> p xs,
--   <a>dropWhile</a> p xs)</tt>
span :: (a -> Bool) -> [a] -> ([a], [a])

-- | <a>break</a>, applied to a predicate <tt>p</tt> and a list
--   <tt>xs</tt>, returns a tuple where first element is longest prefix
--   (possibly empty) of <tt>xs</tt> of elements that <i>do not satisfy</i>
--   <tt>p</tt> and second element is the remainder of the list:
--   
--   <pre>
--   &gt;&gt;&gt; break (&gt; 3) [1,2,3,4,1,2,3,4]
--   ([1,2,3],[4,1,2,3,4])
--   
--   &gt;&gt;&gt; break (&lt; 9) [1,2,3]
--   ([],[1,2,3])
--   
--   &gt;&gt;&gt; break (&gt; 9) [1,2,3]
--   ([1,2,3],[])
--   </pre>
--   
--   <a>break</a> <tt>p</tt> is equivalent to <tt><a>span</a> (<a>not</a> .
--   p)</tt>.
break :: (a -> Bool) -> [a] -> ([a], [a])

-- | <a>reverse</a> <tt>xs</tt> returns the elements of <tt>xs</tt> in
--   reverse order. <tt>xs</tt> must be finite.
--   
--   <pre>
--   &gt;&gt;&gt; reverse []
--   []
--   
--   &gt;&gt;&gt; reverse [42]
--   [42]
--   
--   &gt;&gt;&gt; reverse [2,5,7]
--   [7,5,2]
--   
--   &gt;&gt;&gt; reverse [1..]
--   * Hangs forever *
--   </pre>
reverse :: [a] -> [a]

-- | <a>and</a> returns the conjunction of a container of Bools. For the
--   result to be <a>True</a>, the container must be finite; <a>False</a>,
--   however, results from a <a>False</a> value finitely far from the left
--   end.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; and []
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and [True]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and [False]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and [True, True, False]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and (False : repeat True) -- Infinite list [False,True,True,True,...
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and (repeat True)
--   * Hangs forever *
--   </pre>
and :: Foldable t => t Bool -> Bool

-- | <a>or</a> returns the disjunction of a container of Bools. For the
--   result to be <a>False</a>, the container must be finite; <a>True</a>,
--   however, results from a <a>True</a> value finitely far from the left
--   end.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; or []
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or [True]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or [False]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or [True, True, False]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or (True : repeat False) -- Infinite list [True,False,False,False,...
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or (repeat False)
--   * Hangs forever *
--   </pre>
or :: Foldable t => t Bool -> Bool

-- | Determines whether any element of the structure satisfies the
--   predicate.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) []
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) [1,2]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) [1,2,3,4,5]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) [1..]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) [0, -1..]
--   * Hangs forever *
--   </pre>
any :: Foldable t => (a -> Bool) -> t a -> Bool

-- | <a>notElem</a> is the negation of <a>elem</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` []
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` [1,2]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` [1,2,3,4,5]
--   False
--   </pre>
--   
--   For infinite structures, <a>notElem</a> terminates if the value exists
--   at a finite distance from the left side of the structure:
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` [1..]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` ([4..] ++ [3])
--   * Hangs forever *
--   </pre>
notElem :: (Foldable t, Eq a) => a -> t a -> Bool
infix 4 `notElem`

-- | &lt;math&gt;. <a>lookup</a> <tt>key assocs</tt> looks up a key in an
--   association list. For the result to be <a>Nothing</a>, the list must
--   be finite.
--   
--   <pre>
--   &gt;&gt;&gt; lookup 2 []
--   Nothing
--   
--   &gt;&gt;&gt; lookup 2 [(1, "first")]
--   Nothing
--   
--   &gt;&gt;&gt; lookup 2 [(1, "first"), (2, "second"), (3, "third")]
--   Just "second"
--   </pre>
lookup :: Eq a => a -> [(a, b)] -> Maybe b

-- | Map a function over all the elements of a container and concatenate
--   the resulting lists.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; concatMap (take 3) [[1..], [10..], [100..], [1000..]]
--   [1,2,3,10,11,12,100,101,102,1000,1001,1002]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; concatMap (take 3) (Just [1..])
--   [1,2,3]
--   </pre>
concatMap :: Foldable t => (a -> [b]) -> t a -> [b]

-- | List index (subscript) operator, starting from 0. It is an instance of
--   the more general <a>genericIndex</a>, which takes an index of any
--   integral type.
--   
--   <pre>
--   &gt;&gt;&gt; ['a', 'b', 'c'] !! 0
--   'a'
--   
--   &gt;&gt;&gt; ['a', 'b', 'c'] !! 2
--   'c'
--   
--   &gt;&gt;&gt; ['a', 'b', 'c'] !! 3
--   *** Exception: Prelude.!!: index too large
--   
--   &gt;&gt;&gt; ['a', 'b', 'c'] !! (-1)
--   *** Exception: Prelude.!!: negative index
--   </pre>
--   
--   WARNING: This function is partial. You can use <a>atMay</a> instead.
(!!) :: HasCallStack => [a] -> Int -> a
infixl 9 !!

-- | <a>zip3</a> takes three lists and returns a list of triples, analogous
--   to <a>zip</a>. It is capable of list fusion, but it is restricted to
--   its first list argument and its resulting list.
zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]

-- | The <a>zipWith3</a> function takes a function which combines three
--   elements, as well as three lists and returns a list of the function
--   applied to corresponding elements, analogous to <a>zipWith</a>. It is
--   capable of list fusion, but it is restricted to its first list
--   argument and its resulting list.
--   
--   <pre>
--   zipWith3 (,,) xs ys zs == zip3 xs ys zs
--   zipWith3 f [x1,x2,x3..] [y1,y2,y3..] [z1,z2,z3..] == [f x1 y1 z1, f x2 y2 z2, f x3 y3 z3..]
--   </pre>
zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]

-- | <a>unzip</a> transforms a list of pairs into a list of first
--   components and a list of second components.
--   
--   <pre>
--   &gt;&gt;&gt; unzip []
--   ([],[])
--   
--   &gt;&gt;&gt; unzip [(1, 'a'), (2, 'b')]
--   ([1,2],"ab")
--   </pre>
unzip :: [(a, b)] -> ([a], [b])

-- | The <a>unzip3</a> function takes a list of triples and returns three
--   lists, analogous to <a>unzip</a>.
--   
--   <pre>
--   &gt;&gt;&gt; unzip3 []
--   ([],[],[])
--   
--   &gt;&gt;&gt; unzip3 [(1, 'a', True), (2, 'b', False)]
--   ([1,2],"ab",[True,False])
--   </pre>
unzip3 :: [(a, b, c)] -> ([a], [b], [c])

-- | equivalent to <a>showsPrec</a> with a precedence of 0.
shows :: Show a => a -> ShowS

-- | utility function converting a <a>Char</a> to a show function that
--   simply prepends the character unchanged.
showChar :: Char -> ShowS

-- | utility function converting a <a>String</a> to a show function that
--   simply prepends the string unchanged.
showString :: String -> ShowS

-- | utility function that surrounds the inner show function with
--   parentheses when the <a>Bool</a> parameter is <a>True</a>.
showParen :: Bool -> ShowS -> ShowS
odd :: Integral a => a -> Bool

-- | raise a number to an integral power
(^^) :: (Fractional a, Integral b) => a -> b -> a
infixr 8 ^^

-- | <tt><a>gcd</a> x y</tt> is the non-negative factor of both <tt>x</tt>
--   and <tt>y</tt> of which every common factor of <tt>x</tt> and
--   <tt>y</tt> is also a factor; for example <tt><a>gcd</a> 4 2 = 2</tt>,
--   <tt><a>gcd</a> (-4) 6 = 2</tt>, <tt><a>gcd</a> 0 4</tt> = <tt>4</tt>.
--   <tt><a>gcd</a> 0 0</tt> = <tt>0</tt>. (That is, the common divisor
--   that is "greatest" in the divisibility preordering.)
--   
--   Note: Since for signed fixed-width integer types, <tt><a>abs</a>
--   <a>minBound</a> &lt; 0</tt>, the result may be negative if one of the
--   arguments is <tt><a>minBound</a></tt> (and necessarily is if the other
--   is <tt>0</tt> or <tt><a>minBound</a></tt>) for such types.
gcd :: Integral a => a -> a -> a

-- | <tt><a>lcm</a> x y</tt> is the smallest positive integer that both
--   <tt>x</tt> and <tt>y</tt> divide.
lcm :: Integral a => a -> a -> a

-- | Extract the second component of a pair.
snd :: (a, b) -> b

-- | <a>curry</a> converts an uncurried function to a curried function.
--   
--   <h4><b>Examples</b></h4>
--   
--   <pre>
--   &gt;&gt;&gt; curry fst 1 2
--   1
--   </pre>
curry :: ((a, b) -> c) -> a -> b -> c

-- | The <a>lex</a> function reads a single lexeme from the input,
--   discarding initial white space, and returning the characters that
--   constitute the lexeme. If the input string contains only white space,
--   <a>lex</a> returns a single successful `lexeme' consisting of the
--   empty string. (Thus <tt><a>lex</a> "" = [("","")]</tt>.) If there is
--   no legal lexeme at the beginning of the input string, <a>lex</a> fails
--   (i.e. returns <tt>[]</tt>).
--   
--   This lexer is not completely faithful to the Haskell lexical syntax in
--   the following respects:
--   
--   <ul>
--   <li>Qualified names are not handled properly</li>
--   <li>Octal and hexadecimal numerics are not recognized as a single
--   token</li>
--   <li>Comments are not treated properly</li>
--   </ul>
lex :: ReadS String

-- | <tt><a>readParen</a> <a>True</a> p</tt> parses what <tt>p</tt> parses,
--   but surrounded with parentheses.
--   
--   <tt><a>readParen</a> <a>False</a> p</tt> parses what <tt>p</tt>
--   parses, but optionally surrounded with parentheses.
readParen :: Bool -> ReadS a -> ReadS a

-- | Case analysis for the <a>Either</a> type. If the value is
--   <tt><a>Left</a> a</tt>, apply the first function to <tt>a</tt>; if it
--   is <tt><a>Right</a> b</tt>, apply the second function to <tt>b</tt>.
--   
--   <h4><b>Examples</b></h4>
--   
--   We create two values of type <tt><a>Either</a> <a>String</a>
--   <a>Int</a></tt>, one using the <a>Left</a> constructor and another
--   using the <a>Right</a> constructor. Then we apply "either" the
--   <a>length</a> function (if we have a <a>String</a>) or the "times-two"
--   function (if we have an <a>Int</a>):
--   
--   <pre>
--   &gt;&gt;&gt; let s = Left "foo" :: Either String Int
--   
--   &gt;&gt;&gt; let n = Right 3 :: Either String Int
--   
--   &gt;&gt;&gt; either length (*2) s
--   3
--   
--   &gt;&gt;&gt; either length (*2) n
--   6
--   </pre>
either :: (a -> c) -> (b -> c) -> Either a b -> c

-- | equivalent to <a>readsPrec</a> with a precedence of 0.
reads :: Read a => ReadS a

-- | The <a>read</a> function reads input from a string, which must be
--   completely consumed by the input process. <a>read</a> fails with an
--   <a>error</a> if the parse is unsuccessful, and it is therefore
--   discouraged from being used in real applications. Use <a>readMaybe</a>
--   or <a>readEither</a> for safe alternatives.
--   
--   <pre>
--   &gt;&gt;&gt; read "123" :: Int
--   123
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; read "hello" :: Int
--   *** Exception: Prelude.read: no parse
--   </pre>
read :: Read a => String -> a

-- | Evaluate each monadic action in the structure from left to right, and
--   ignore the results. For a version that doesn't ignore the results see
--   <a>sequence</a>.
--   
--   <a>sequence_</a> is just like <a>sequenceA_</a>, but specialised to
--   monadic actions.
sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()

-- | Splits the argument into a list of <i>lines</i> stripped of their
--   terminating <tt>\n</tt> characters. The <tt>\n</tt> terminator is
--   optional in a final non-empty line of the argument string.
--   
--   For example:
--   
--   <pre>
--   &gt;&gt;&gt; lines ""           -- empty input contains no lines
--   []
--   
--   &gt;&gt;&gt; lines "\n"         -- single empty line
--   [""]
--   
--   &gt;&gt;&gt; lines "one"        -- single unterminated line
--   ["one"]
--   
--   &gt;&gt;&gt; lines "one\n"      -- single non-empty line
--   ["one"]
--   
--   &gt;&gt;&gt; lines "one\n\n"    -- second line is empty
--   ["one",""]
--   
--   &gt;&gt;&gt; lines "one\ntwo"   -- second line is unterminated
--   ["one","two"]
--   
--   &gt;&gt;&gt; lines "one\ntwo\n" -- two non-empty lines
--   ["one","two"]
--   </pre>
--   
--   When the argument string is empty, or ends in a <tt>\n</tt> character,
--   it can be recovered by passing the result of <a>lines</a> to the
--   <a>unlines</a> function. Otherwise, <a>unlines</a> appends the missing
--   terminating <tt>\n</tt>. This makes <tt>unlines . lines</tt>
--   <i>idempotent</i>:
--   
--   <pre>
--   (unlines . lines) . (unlines . lines) = (unlines . lines)
--   </pre>
lines :: String -> [String]

-- | Appends a <tt>\n</tt> character to each input string, then
--   concatenates the results. Equivalent to <tt><tt>foldMap</tt> (s -&gt;
--   s <a>++</a> "\n")</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; unlines ["Hello", "World", "!"]
--   "Hello\nWorld\n!\n"
--   </pre>
--   
--   Note that <tt><a>unlines</a> <a>.</a> <a>lines</a> <a>/=</a>
--   <a>id</a></tt> when the input is not <tt>\n</tt>-terminated:
--   
--   <pre>
--   &gt;&gt;&gt; unlines . lines $ "foo\nbar"
--   "foo\nbar\n"
--   </pre>
unlines :: [String] -> String

-- | <a>words</a> breaks a string up into a list of words, which were
--   delimited by white space (as defined by <a>isSpace</a>). This function
--   trims any white spaces at the beginning and at the end.
--   
--   <pre>
--   &gt;&gt;&gt; words "Lorem ipsum\ndolor"
--   ["Lorem","ipsum","dolor"]
--   
--   &gt;&gt;&gt; words " foo bar "
--   ["foo","bar"]
--   </pre>
words :: String -> [String]

-- | <a>unwords</a> joins words with separating spaces (U+0020 SPACE).
--   
--   <pre>
--   &gt;&gt;&gt; unwords ["Lorem", "ipsum", "dolor"]
--   "Lorem ipsum dolor"
--   </pre>
--   
--   <a>unwords</a> is neither left nor right inverse of <a>words</a>:
--   
--   <pre>
--   &gt;&gt;&gt; words (unwords [" "])
--   []
--   
--   &gt;&gt;&gt; unwords (words "foo\nbar")
--   "foo bar"
--   </pre>
unwords :: [String] -> String

-- | Construct an <a>IOException</a> value with a string describing the
--   error. The <tt>fail</tt> method of the <a>IO</a> instance of the
--   <a>Monad</a> class raises a <a>userError</a>, thus:
--   
--   <pre>
--   instance Monad IO where
--     ...
--     fail s = ioError (userError s)
--   </pre>
userError :: String -> IOError

-- | Raise an <a>IOException</a> in the <a>IO</a> monad.
ioError :: IOError -> IO a

-- | Write a character to the standard output device (same as
--   <a>hPutChar</a> <a>stdout</a>).
putChar :: Char -> IO ()

-- | Write a string to the standard output device (same as <a>hPutStr</a>
--   <a>stdout</a>).
putStr :: String -> IO ()

-- | Read a character from the standard input device (same as
--   <a>hGetChar</a> <a>stdin</a>).
getChar :: IO Char

-- | The <a>getContents</a> operation returns all user input as a single
--   string, which is read lazily as it is needed (same as
--   <a>hGetContents</a> <a>stdin</a>).
getContents :: IO String

-- | The <a>interact</a> function takes a function of type
--   <tt>String-&gt;String</tt> as its argument. The entire input from the
--   standard input device is passed to this function as its argument, and
--   the resulting string is output on the standard output device.
interact :: (String -> String) -> IO ()

-- | The <a>readLn</a> function combines <a>getLine</a> and <a>readIO</a>.
readLn :: Read a => IO a

-- | The <a>readIO</a> function is similar to <a>read</a> except that it
--   signals parse failure to the <a>IO</a> monad instead of terminating
--   the program.
readIO :: Read a => String -> IO a

-- | A type <tt>f</tt> is a Functor if it provides a function <tt>fmap</tt>
--   which, given any types <tt>a</tt> and <tt>b</tt> lets you apply any
--   function from <tt>(a -&gt; b)</tt> to turn an <tt>f a</tt> into an
--   <tt>f b</tt>, preserving the structure of <tt>f</tt>. Furthermore
--   <tt>f</tt> needs to adhere to the following:
--   
--   <ul>
--   <li><i>Identity</i> <tt><a>fmap</a> <a>id</a> == <a>id</a></tt></li>
--   <li><i>Composition</i> <tt><a>fmap</a> (f . g) == <a>fmap</a> f .
--   <a>fmap</a> g</tt></li>
--   </ul>
--   
--   Note, that the second law follows from the free theorem of the type
--   <a>fmap</a> and the first law, so you need only check that the former
--   condition holds. See
--   <a>https://www.schoolofhaskell.com/user/edwardk/snippets/fmap</a> or
--   <a>https://github.com/quchen/articles/blob/master/second_functor_law.md</a>
--   for an explanation.
class () => Functor (f :: Type -> Type)

-- | <a>fmap</a> is used to apply a function of type <tt>(a -&gt; b)</tt>
--   to a value of type <tt>f a</tt>, where f is a functor, to produce a
--   value of type <tt>f b</tt>. Note that for any type constructor with
--   more than one parameter (e.g., <tt>Either</tt>), only the last type
--   parameter can be modified with <a>fmap</a> (e.g., <tt>b</tt> in
--   `Either a b`).
--   
--   Some type constructors with two parameters or more have a
--   <tt><a>Bifunctor</a></tt> instance that allows both the last and the
--   penultimate parameters to be mapped over.
--   
--   <h4><b>Examples</b></h4>
--   
--   Convert from a <tt><a>Maybe</a> Int</tt> to a <tt>Maybe String</tt>
--   using <a>show</a>:
--   
--   <pre>
--   &gt;&gt;&gt; fmap show Nothing
--   Nothing
--   
--   &gt;&gt;&gt; fmap show (Just 3)
--   Just "3"
--   </pre>
--   
--   Convert from an <tt><a>Either</a> Int Int</tt> to an <tt>Either Int
--   String</tt> using <a>show</a>:
--   
--   <pre>
--   &gt;&gt;&gt; fmap show (Left 17)
--   Left 17
--   
--   &gt;&gt;&gt; fmap show (Right 17)
--   Right "17"
--   </pre>
--   
--   Double each element of a list:
--   
--   <pre>
--   &gt;&gt;&gt; fmap (*2) [1,2,3]
--   [2,4,6]
--   </pre>
--   
--   Apply <a>even</a> to the second element of a pair:
--   
--   <pre>
--   &gt;&gt;&gt; fmap even (2,2)
--   (2,True)
--   </pre>
--   
--   It may seem surprising that the function is only applied to the last
--   element of the tuple compared to the list example above which applies
--   it to every element in the list. To understand, remember that tuples
--   are type constructors with multiple type parameters: a tuple of 3
--   elements <tt>(a,b,c)</tt> can also be written <tt>(,,) a b c</tt> and
--   its <tt>Functor</tt> instance is defined for <tt>Functor ((,,) a
--   b)</tt> (i.e., only the third parameter is free to be mapped over with
--   <tt>fmap</tt>).
--   
--   It explains why <tt>fmap</tt> can be used with tuples containing
--   values of different types as in the following example:
--   
--   <pre>
--   &gt;&gt;&gt; fmap even ("hello", 1.0, 4)
--   ("hello",1.0,True)
--   </pre>
fmap :: Functor f => (a -> b) -> f a -> f b

-- | Replace all locations in the input with the same value. The default
--   definition is <tt><a>fmap</a> . <a>const</a></tt>, but this may be
--   overridden with a more efficient version.
--   
--   <h4><b>Examples</b></h4>
--   
--   Perform a computation with <a>Maybe</a> and replace the result with a
--   constant value if it is <a>Just</a>:
--   
--   <pre>
--   &gt;&gt;&gt; 'a' &lt;$ Just 2
--   Just 'a'
--   
--   &gt;&gt;&gt; 'a' &lt;$ Nothing
--   Nothing
--   </pre>
(<$) :: Functor f => a -> f b -> f a
infixl 4 <$

-- | The <a>Monad</a> class defines the basic operations over a
--   <i>monad</i>, a concept from a branch of mathematics known as
--   <i>category theory</i>. From the perspective of a Haskell programmer,
--   however, it is best to think of a monad as an <i>abstract datatype</i>
--   of actions. Haskell's <tt>do</tt> expressions provide a convenient
--   syntax for writing monadic expressions.
--   
--   Instances of <a>Monad</a> should satisfy the following:
--   
--   <ul>
--   <li><i>Left identity</i> <tt><a>return</a> a <a>&gt;&gt;=</a> k = k
--   a</tt></li>
--   <li><i>Right identity</i> <tt>m <a>&gt;&gt;=</a> <a>return</a> =
--   m</tt></li>
--   <li><i>Associativity</i> <tt>m <a>&gt;&gt;=</a> (\x -&gt; k x
--   <a>&gt;&gt;=</a> h) = (m <a>&gt;&gt;=</a> k) <a>&gt;&gt;=</a>
--   h</tt></li>
--   </ul>
--   
--   Furthermore, the <a>Monad</a> and <a>Applicative</a> operations should
--   relate as follows:
--   
--   <ul>
--   <li><pre><a>pure</a> = <a>return</a></pre></li>
--   <li><pre>m1 <a>&lt;*&gt;</a> m2 = m1 <a>&gt;&gt;=</a> (\x1 -&gt; m2
--   <a>&gt;&gt;=</a> (\x2 -&gt; <a>return</a> (x1 x2)))</pre></li>
--   </ul>
--   
--   The above laws imply:
--   
--   <ul>
--   <li><pre><a>fmap</a> f xs = xs <a>&gt;&gt;=</a> <a>return</a> .
--   f</pre></li>
--   <li><pre>(<a>&gt;&gt;</a>) = (<a>*&gt;</a>)</pre></li>
--   </ul>
--   
--   and that <a>pure</a> and (<a>&lt;*&gt;</a>) satisfy the applicative
--   functor laws.
--   
--   The instances of <a>Monad</a> for lists, <a>Maybe</a> and <a>IO</a>
--   defined in the <a>Prelude</a> satisfy these laws.
class Applicative m => Monad (m :: Type -> Type)

-- | Sequentially compose two actions, passing any value produced by the
--   first as an argument to the second.
--   
--   '<tt>as <a>&gt;&gt;=</a> bs</tt>' can be understood as the <tt>do</tt>
--   expression
--   
--   <pre>
--   do a &lt;- as
--      bs a
--   </pre>
(>>=) :: Monad m => m a -> (a -> m b) -> m b

-- | Sequentially compose two actions, discarding any value produced by the
--   first, like sequencing operators (such as the semicolon) in imperative
--   languages.
--   
--   '<tt>as <a>&gt;&gt;</a> bs</tt>' can be understood as the <tt>do</tt>
--   expression
--   
--   <pre>
--   do as
--      bs
--   </pre>
(>>) :: Monad m => m a -> m b -> m b

-- | Inject a value into the monadic type.
return :: Monad m => a -> m a
infixl 1 >>=
infixl 1 >>

-- | Monads that also support choice and failure.
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type)

-- | The identity of <a>mplus</a>. It should also satisfy the equations
--   
--   <pre>
--   mzero &gt;&gt;= f  =  mzero
--   v &gt;&gt; mzero   =  mzero
--   </pre>
--   
--   The default definition is
--   
--   <pre>
--   mzero = <a>empty</a>
--   </pre>
mzero :: MonadPlus m => m a

-- | An associative operation. The default definition is
--   
--   <pre>
--   mplus = (<a>&lt;|&gt;</a>)
--   </pre>
mplus :: MonadPlus m => m a -> m a -> m a

-- | When a value is bound in <tt>do</tt>-notation, the pattern on the left
--   hand side of <tt>&lt;-</tt> might not match. In this case, this class
--   provides a function to recover.
--   
--   A <a>Monad</a> without a <a>MonadFail</a> instance may only be used in
--   conjunction with pattern that always match, such as newtypes, tuples,
--   data types with only a single data constructor, and irrefutable
--   patterns (<tt>~pat</tt>).
--   
--   Instances of <a>MonadFail</a> should satisfy the following law:
--   <tt>fail s</tt> should be a left zero for <a>&gt;&gt;=</a>,
--   
--   <pre>
--   fail s &gt;&gt;= f  =  fail s
--   </pre>
--   
--   If your <a>Monad</a> is also <a>MonadPlus</a>, a popular definition is
--   
--   <pre>
--   fail _ = mzero
--   </pre>
--   
--   <tt>fail s</tt> should be an action that runs in the monad itself, not
--   an exception (except in instances of <tt>MonadIO</tt>). In particular,
--   <tt>fail</tt> should not be implemented in terms of <tt>error</tt>.
class Monad m => MonadFail (m :: Type -> Type)
fail :: MonadFail m => String -> m a

-- | <tt><a>void</a> value</tt> discards or ignores the result of
--   evaluation, such as the return value of an <a>IO</a> action.
--   
--   <h4><b>Examples</b></h4>
--   
--   Replace the contents of a <tt><a>Maybe</a> <a>Int</a></tt> with unit:
--   
--   <pre>
--   &gt;&gt;&gt; void Nothing
--   Nothing
--   
--   &gt;&gt;&gt; void (Just 3)
--   Just ()
--   </pre>
--   
--   Replace the contents of an <tt><a>Either</a> <a>Int</a>
--   <a>Int</a></tt> with unit, resulting in an <tt><a>Either</a>
--   <a>Int</a> <tt>()</tt></tt>:
--   
--   <pre>
--   &gt;&gt;&gt; void (Left 8675309)
--   Left 8675309
--   
--   &gt;&gt;&gt; void (Right 8675309)
--   Right ()
--   </pre>
--   
--   Replace every element of a list with unit:
--   
--   <pre>
--   &gt;&gt;&gt; void [1,2,3]
--   [(),(),()]
--   </pre>
--   
--   Replace the second element of a pair with unit:
--   
--   <pre>
--   &gt;&gt;&gt; void (1,2)
--   (1,())
--   </pre>
--   
--   Discard the result of an <a>IO</a> action:
--   
--   <pre>
--   &gt;&gt;&gt; mapM print [1,2]
--   1
--   2
--   [(),()]
--   
--   &gt;&gt;&gt; void $ mapM print [1,2]
--   1
--   2
--   </pre>
void :: Functor f => f a -> f ()

-- | The <a>join</a> function is the conventional monad join operator. It
--   is used to remove one level of monadic structure, projecting its bound
--   argument into the outer level.
--   
--   '<tt><a>join</a> bss</tt>' can be understood as the <tt>do</tt>
--   expression
--   
--   <pre>
--   do bs &lt;- bss
--      bs
--   </pre>
--   
--   <h4><b>Examples</b></h4>
--   
--   A common use of <a>join</a> is to run an <a>IO</a> computation
--   returned from an <a>STM</a> transaction, since <a>STM</a> transactions
--   can't perform <a>IO</a> directly. Recall that
--   
--   <pre>
--   <a>atomically</a> :: STM a -&gt; IO a
--   </pre>
--   
--   is used to run <a>STM</a> transactions atomically. So, by specializing
--   the types of <a>atomically</a> and <a>join</a> to
--   
--   <pre>
--   <a>atomically</a> :: STM (IO b) -&gt; IO (IO b)
--   <a>join</a>       :: IO (IO b)  -&gt; IO b
--   </pre>
--   
--   we can compose them as
--   
--   <pre>
--   <a>join</a> . <a>atomically</a> :: STM (IO b) -&gt; IO b
--   </pre>
--   
--   to run an <a>STM</a> transaction and the <a>IO</a> action it returns.
join :: Monad m => m (m a) -> m a

-- | Map each element of a structure to a monadic action, evaluate these
--   actions from left to right, and collect the results. For a version
--   that ignores the results see <a>mapM_</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   <a>mapM</a> is literally a <a>traverse</a> with a type signature
--   restricted to <a>Monad</a>. Its implementation may be more efficient
--   due to additional power of <a>Monad</a>.
mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)

-- | Evaluate each monadic action in the structure from left to right, and
--   collect the results. For a version that ignores the results see
--   <a>sequence_</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   The first two examples are instances where the input and and output of
--   <a>sequence</a> are isomorphic.
--   
--   <pre>
--   &gt;&gt;&gt; sequence $ Right [1,2,3,4]
--   [Right 1,Right 2,Right 3,Right 4]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; sequence $ [Right 1,Right 2,Right 3,Right 4]
--   Right [1,2,3,4]
--   </pre>
--   
--   The following examples demonstrate short circuit behavior for
--   <a>sequence</a>.
--   
--   <pre>
--   &gt;&gt;&gt; sequence $ Left [1,2,3,4]
--   Left [1,2,3,4]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; sequence $ [Left 0, Right 1,Right 2,Right 3,Right 4]
--   Left 0
--   </pre>
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)

-- | <a>forM</a> is <a>mapM</a> with its arguments flipped. For a version
--   that ignores the results see <a>forM_</a>.
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)

-- | Repeat an action indefinitely.
--   
--   <h4><b>Examples</b></h4>
--   
--   A common use of <a>forever</a> is to process input from network
--   sockets, <a>Handle</a>s, and channels (e.g. <a>MVar</a> and
--   <a>Chan</a>).
--   
--   For example, here is how we might implement an <a>echo server</a>,
--   using <a>forever</a> both to listen for client connections on a
--   network socket and to echo client input on client connection handles:
--   
--   <pre>
--   echoServer :: Socket -&gt; IO ()
--   echoServer socket = <a>forever</a> $ do
--     client &lt;- accept socket
--     <a>forkFinally</a> (echo client) (\_ -&gt; hClose client)
--     where
--       echo :: Handle -&gt; IO ()
--       echo client = <a>forever</a> $
--         hGetLine client &gt;&gt;= hPutStrLn client
--   </pre>
--   
--   Note that "forever" isn't necessarily non-terminating. If the action
--   is in a <tt><a>MonadPlus</a></tt> and short-circuits after some number
--   of iterations. then <tt><a>forever</a></tt> actually returns
--   <a>mzero</a>, effectively short-circuiting its caller.
forever :: Applicative f => f a -> f b

-- | Promote a function to a monad.
liftM :: Monad m => (a1 -> r) -> m a1 -> m r

-- | Conditional failure of <a>Alternative</a> computations. Defined by
--   
--   <pre>
--   guard True  = <a>pure</a> ()
--   guard False = <a>empty</a>
--   </pre>
--   
--   <h4><b>Examples</b></h4>
--   
--   Common uses of <a>guard</a> include conditionally signaling an error
--   in an error monad and conditionally rejecting the current choice in an
--   <a>Alternative</a>-based parser.
--   
--   As an example of signaling an error in the error monad <a>Maybe</a>,
--   consider a safe division function <tt>safeDiv x y</tt> that returns
--   <a>Nothing</a> when the denominator <tt>y</tt> is zero and
--   <tt><a>Just</a> (x `div` y)</tt> otherwise. For example:
--   
--   <pre>
--   &gt;&gt;&gt; safeDiv 4 0
--   Nothing
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; safeDiv 4 2
--   Just 2
--   </pre>
--   
--   A definition of <tt>safeDiv</tt> using guards, but not <a>guard</a>:
--   
--   <pre>
--   safeDiv :: Int -&gt; Int -&gt; Maybe Int
--   safeDiv x y | y /= 0    = Just (x `div` y)
--               | otherwise = Nothing
--   </pre>
--   
--   A definition of <tt>safeDiv</tt> using <a>guard</a> and <a>Monad</a>
--   <tt>do</tt>-notation:
--   
--   <pre>
--   safeDiv :: Int -&gt; Int -&gt; Maybe Int
--   safeDiv x y = do
--     guard (y /= 0)
--     return (x `div` y)
--   </pre>
guard :: Alternative f => Bool -> f ()

-- | Same as <a>&gt;&gt;=</a>, but with the arguments interchanged.
(=<<) :: Monad m => (a -> m b) -> m a -> m b
infixr 1 =<<

-- | Conditional execution of <a>Applicative</a> expressions. For example,
--   
--   <pre>
--   when debug (putStrLn "Debugging")
--   </pre>
--   
--   will output the string <tt>Debugging</tt> if the Boolean value
--   <tt>debug</tt> is <a>True</a>, and otherwise do nothing.
when :: Applicative f => Bool -> f () -> f ()

-- | Promote a function to a monad, scanning the monadic arguments from
--   left to right. For example,
--   
--   <pre>
--   liftM2 (+) [0,1] [0,2] = [0,2,1,3]
--   liftM2 (+) (Just 1) Nothing = Nothing
--   </pre>
liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r

-- | Promote a function to a monad, scanning the monadic arguments from
--   left to right (cf. <a>liftM2</a>).
liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r

-- | Promote a function to a monad, scanning the monadic arguments from
--   left to right (cf. <a>liftM2</a>).
liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r

-- | Promote a function to a monad, scanning the monadic arguments from
--   left to right (cf. <a>liftM2</a>).
liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r

-- | In many situations, the <a>liftM</a> operations can be replaced by
--   uses of <a>ap</a>, which promotes function application.
--   
--   <pre>
--   return f `ap` x1 `ap` ... `ap` xn
--   </pre>
--   
--   is equivalent to
--   
--   <pre>
--   liftMn f x1 x2 ... xn
--   </pre>
ap :: Monad m => m (a -> b) -> m a -> m b

-- | Evaluate each monadic action in the structure from left to right, and
--   ignore the results. For a version that doesn't ignore the results see
--   <a>sequence</a>.
--   
--   <a>sequence_</a> is just like <a>sequenceA_</a>, but specialised to
--   monadic actions.
sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()

-- | The sum of a collection of actions using <a>(&lt;|&gt;)</a>,
--   generalizing <a>concat</a>.
--   
--   <a>msum</a> is just like <a>asum</a>, but specialised to
--   <a>MonadPlus</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage, using the <a>MonadPlus</a> instance for <a>Maybe</a>:
--   
--   <pre>
--   &gt;&gt;&gt; msum [Just "Hello", Nothing, Just "World"]
--   Just "Hello"
--   </pre>
msum :: (Foldable t, MonadPlus m) => t (m a) -> m a

-- | This generalizes the list-based <a>filter</a> function.
filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a]

-- | Left-to-right composition of Kleisli arrows.
--   
--   '<tt>(bs <a>&gt;=&gt;</a> cs) a</tt>' can be understood as the
--   <tt>do</tt> expression
--   
--   <pre>
--   do b &lt;- bs a
--      cs b
--   </pre>
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
infixr 1 >=>

-- | Right-to-left composition of Kleisli arrows.
--   <tt>(<a>&gt;=&gt;</a>)</tt>, with the arguments flipped.
--   
--   Note how this operator resembles function composition
--   <tt>(<a>.</a>)</tt>:
--   
--   <pre>
--   (.)   ::            (b -&gt;   c) -&gt; (a -&gt;   b) -&gt; a -&gt;   c
--   (&lt;=&lt;) :: Monad m =&gt; (b -&gt; m c) -&gt; (a -&gt; m b) -&gt; a -&gt; m c
--   </pre>
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
infixr 1 <=<

-- | The <a>mapAndUnzipM</a> function maps its first argument over a list,
--   returning the result as a pair of lists. This function is mainly used
--   with complicated data structures or a state monad.
mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])

-- | The <a>zipWithM</a> function generalizes <a>zipWith</a> to arbitrary
--   applicative functors.
zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]

-- | <a>zipWithM_</a> is the extension of <a>zipWithM</a> which ignores the
--   final result.
zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()

-- | The <a>foldM</a> function is analogous to <a>foldl</a>, except that
--   its result is encapsulated in a monad. Note that <a>foldM</a> works
--   from left-to-right over the list arguments. This could be an issue
--   where <tt>(<a>&gt;&gt;</a>)</tt> and the `folded function' are not
--   commutative.
--   
--   <pre>
--   foldM f a1 [x1, x2, ..., xm]
--   
--   ==
--   
--   do
--     a2 &lt;- f a1 x1
--     a3 &lt;- f a2 x2
--     ...
--     f am xm
--   </pre>
--   
--   If right-to-left evaluation is required, the input list should be
--   reversed.
--   
--   Note: <a>foldM</a> is the same as <a>foldlM</a>
foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b

-- | Like <a>foldM</a>, but discards the result.
foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()

-- | <tt><a>replicateM</a> n act</tt> performs the action <tt>act</tt>
--   <tt>n</tt> times, and then returns the list of results:
--   
--   <h4><b>Examples</b></h4>
--   
--   <pre>
--   &gt;&gt;&gt; import Control.Monad.State
--   
--   &gt;&gt;&gt; runState (replicateM 3 $ state $ \s -&gt; (s, s + 1)) 1
--   ([1,2,3],4)
--   </pre>
replicateM :: Applicative m => Int -> m a -> m [a]

-- | Like <a>replicateM</a>, but discards the result.
--   
--   <h4><b>Examples</b></h4>
--   
--   <pre>
--   &gt;&gt;&gt; replicateM_ 3 (putStrLn "a")
--   a
--   a
--   a
--   </pre>
replicateM_ :: Applicative m => Int -> m a -> m ()

-- | The reverse of <a>when</a>.
unless :: Applicative f => Bool -> f () -> f ()

-- | Strict version of <a>&lt;$&gt;</a>.
(<$!>) :: Monad m => (a -> b) -> m a -> m b
infixl 4 <$!>

-- | Direct <a>MonadPlus</a> equivalent of <a>filter</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   The <a>filter</a> function is just <a>mfilter</a> specialized to the
--   list monad:
--   
--   <pre>
--   <a>filter</a> = ( <a>mfilter</a> :: (a -&gt; Bool) -&gt; [a] -&gt; [a] )
--   </pre>
--   
--   An example using <a>mfilter</a> with the <a>Maybe</a> monad:
--   
--   <pre>
--   &gt;&gt;&gt; mfilter odd (Just 1)
--   Just 1
--   
--   &gt;&gt;&gt; mfilter odd (Just 2)
--   Nothing
--   </pre>
mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a

-- | The <a>sort</a> function implements a stable sorting algorithm. It is
--   a special case of <a>sortBy</a>, which allows the programmer to supply
--   their own comparison function.
--   
--   Elements are arranged from lowest to highest, keeping duplicates in
--   the order they appeared in the input.
--   
--   <pre>
--   &gt;&gt;&gt; sort [1,6,4,3,2,5]
--   [1,2,3,4,5,6]
--   </pre>
--   
--   The argument must be finite.
sort :: Ord a => [a] -> [a]

-- | &lt;math&gt;. <a>delete</a> <tt>x</tt> removes the first occurrence of
--   <tt>x</tt> from its list argument. For example,
--   
--   <pre>
--   &gt;&gt;&gt; delete 'a' "banana"
--   "bnana"
--   </pre>
--   
--   It is a special case of <a>deleteBy</a>, which allows the programmer
--   to supply their own equality test.
delete :: Eq a => a -> [a] -> [a]

-- | Append two lists, i.e.,
--   
--   <pre>
--   [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
--   [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
--   </pre>
--   
--   If the first list is not finite, the result is the first list.
--   
--   WARNING: This function takes linear time in the number of elements of
--   the first list.
(++) :: [a] -> [a] -> [a]
infixr 5 ++

-- | Right-associative fold of a structure, lazy in the accumulator.
--   
--   In the case of lists, <a>foldr</a>, when applied to a binary operator,
--   a starting value (typically the right-identity of the operator), and a
--   list, reduces the list using the binary operator, from right to left:
--   
--   <pre>
--   foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
--   </pre>
--   
--   Note that since the head of the resulting expression is produced by an
--   application of the operator to the first element of the list, given an
--   operator lazy in its right argument, <a>foldr</a> can produce a
--   terminating expression from an unbounded list.
--   
--   For a general <a>Foldable</a> structure this should be semantically
--   identical to,
--   
--   <pre>
--   foldr f z = <a>foldr</a> f z . <a>toList</a>
--   </pre>
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; foldr (||) False [False, True, False]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr (||) False []
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr (\c acc -&gt; acc ++ [c]) "foo" ['a', 'b', 'c', 'd']
--   "foodcba"
--   </pre>
--   
--   <h5>Infinite structures</h5>
--   
--   ⚠️ Applying <a>foldr</a> to infinite structures usually doesn't
--   terminate.
--   
--   It may still terminate under one of the following conditions:
--   
--   <ul>
--   <li>the folding function is short-circuiting</li>
--   <li>the folding function is lazy on its second argument</li>
--   </ul>
--   
--   <h6>Short-circuiting</h6>
--   
--   <tt>(<a>||</a>)</tt> short-circuits on <a>True</a> values, so the
--   following terminates because there is a <a>True</a> value finitely far
--   from the left side:
--   
--   <pre>
--   &gt;&gt;&gt; foldr (||) False (True : repeat False)
--   True
--   </pre>
--   
--   But the following doesn't terminate:
--   
--   <pre>
--   &gt;&gt;&gt; foldr (||) False (repeat False ++ [True])
--   * Hangs forever *
--   </pre>
--   
--   <h6>Laziness in the second argument</h6>
--   
--   Applying <a>foldr</a> to infinite structures terminates when the
--   operator is lazy in its second argument (the initial accumulator is
--   never used in this case, and so could be left <a>undefined</a>, but
--   <tt>[]</tt> is more clear):
--   
--   <pre>
--   &gt;&gt;&gt; take 5 $ foldr (\i acc -&gt; i : fmap (+3) acc) [] (repeat 1)
--   [1,4,7,10,13]
--   </pre>
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b

-- | Left-associative fold of a structure but with strict application of
--   the operator.
--   
--   This ensures that each step of the fold is forced to Weak Head Normal
--   Form before being applied, avoiding the collection of thunks that
--   would otherwise occur. This is often what you want to strictly reduce
--   a finite structure to a single strict result (e.g. <a>sum</a>).
--   
--   For a general <a>Foldable</a> structure this should be semantically
--   identical to,
--   
--   <pre>
--   foldl' f z = <a>foldl'</a> f z . <a>toList</a>
--   </pre>
foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b

-- | The <a>product</a> function computes the product of the numbers of a
--   structure.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; product []
--   1
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; product [42]
--   42
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; product [1..10]
--   3628800
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; product [4.1, 2.0, 1.7]
--   13.939999999999998
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; product [1..]
--   * Hangs forever *
--   </pre>
product :: (Foldable t, Num a) => t a -> a

-- | A variant of <a>foldr</a> that has no base case, and thus may only be
--   applied to non-empty structures.
--   
--   This function is non-total and will raise a runtime exception if the
--   structure happens to be empty.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (+) [1..4]
--   10
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (+) []
--   Exception: Prelude.foldr1: empty list
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (+) Nothing
--   *** Exception: foldr1: empty structure
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (-) [1..4]
--   -2
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (&amp;&amp;) [True, False, True, True]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (||) [False, False, True, True]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; foldr1 (+) [1..]
--   * Hangs forever *
--   </pre>
foldr1 :: Foldable t => (a -> a -> a) -> t a -> a

-- | The largest element of a non-empty structure.
--   
--   This function is non-total and will raise a runtime exception if the
--   structure happens to be empty. A structure that supports random access
--   and maintains its elements in order should provide a specialised
--   implementation to return the maximum in faster than linear time.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; maximum [1..10]
--   10
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; maximum []
--   *** Exception: Prelude.maximum: empty list
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; maximum Nothing
--   *** Exception: maximum: empty structure
--   </pre>
--   
--   WARNING: This function is partial for possibly-empty structures like
--   lists.
maximum :: (Foldable t, Ord a) => t a -> a

-- | The least element of a non-empty structure.
--   
--   This function is non-total and will raise a runtime exception if the
--   structure happens to be empty. A structure that supports random access
--   and maintains its elements in order should provide a specialised
--   implementation to return the minimum in faster than linear time.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; minimum [1..10]
--   1
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; minimum []
--   *** Exception: Prelude.minimum: empty list
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; minimum Nothing
--   *** Exception: minimum: empty structure
--   </pre>
--   
--   WARNING: This function is partial for possibly-empty structures like
--   lists.
minimum :: (Foldable t, Ord a) => t a -> a

-- | Does the element occur in the structure?
--   
--   Note: <a>elem</a> is often used in infix form.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` []
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` [1,2]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` [1,2,3,4,5]
--   True
--   </pre>
--   
--   For infinite structures, the default implementation of <a>elem</a>
--   terminates if the sought-after value exists at a finite distance from
--   the left side of the structure:
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` [1..]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `elem` ([4..] ++ [3])
--   * Hangs forever *
--   </pre>
elem :: (Foldable t, Eq a) => a -> t a -> Bool
infix 4 `elem`

-- | &lt;math&gt;. <a>map</a> <tt>f xs</tt> is the list obtained by
--   applying <tt>f</tt> to each element of <tt>xs</tt>, i.e.,
--   
--   <pre>
--   map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
--   map f [x1, x2, ...] == [f x1, f x2, ...]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; map (+1) [1, 2, 3]
--   [2,3,4]
--   </pre>
map :: (a -> b) -> [a] -> [b]

-- | List index (subscript) operator, starting from 0. Returns
--   <a>Nothing</a> if the index is out of bounds
--   
--   <pre>
--   &gt;&gt;&gt; ['a', 'b', 'c'] !? 0
--   Just 'a'
--   
--   &gt;&gt;&gt; ['a', 'b', 'c'] !? 2
--   Just 'c'
--   
--   &gt;&gt;&gt; ['a', 'b', 'c'] !? 3
--   Nothing
--   
--   &gt;&gt;&gt; ['a', 'b', 'c'] !? (-1)
--   Nothing
--   </pre>
--   
--   This is the total variant of the partial <a>!!</a> operator.
--   
--   WARNING: This function takes linear time in the index.
(!?) :: [a] -> Int -> Maybe a
infixl 9 !?

-- | Determines whether all elements of the structure satisfy the
--   predicate.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) []
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) [1,2]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) [1,2,3,4,5]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) [1..]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; all (&gt; 3) [4..]
--   * Hangs forever *
--   </pre>
all :: Foldable t => (a -> Bool) -> t a -> Bool

-- | &lt;math&gt;. <a>zipWith</a> generalises <a>zip</a> by zipping with
--   the function given as the first argument, instead of a tupling
--   function.
--   
--   <pre>
--   zipWith (,) xs ys == zip xs ys
--   zipWith f [x1,x2,x3..] [y1,y2,y3..] == [f x1 y1, f x2 y2, f x3 y3..]
--   </pre>
--   
--   For example, <tt><a>zipWith</a> (+)</tt> is applied to two lists to
--   produce the list of corresponding sums:
--   
--   <pre>
--   &gt;&gt;&gt; zipWith (+) [1, 2, 3] [4, 5, 6]
--   [5,7,9]
--   </pre>
--   
--   <a>zipWith</a> is right-lazy:
--   
--   <pre>
--   &gt;&gt;&gt; let f = undefined
--   
--   &gt;&gt;&gt; zipWith f [] undefined
--   []
--   </pre>
--   
--   <a>zipWith</a> is capable of list fusion, but it is restricted to its
--   first list argument and its resulting list.
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]

-- | The <a>sortBy</a> function is the non-overloaded version of
--   <a>sort</a>. The argument must be finite.
--   
--   <pre>
--   &gt;&gt;&gt; sortBy (\(a,_) (b,_) -&gt; compare a b) [(2, "world"), (4, "!"), (1, "Hello")]
--   [(1,"Hello"),(2,"world"),(4,"!")]
--   </pre>
--   
--   The supplied comparison relation is supposed to be reflexive and
--   antisymmetric, otherwise, e. g., for <tt>_ _ -&gt; GT</tt>, the
--   ordered list simply does not exist. The relation is also expected to
--   be transitive: if it is not then <a>sortBy</a> might fail to find an
--   ordered permutation, even if it exists.
sortBy :: (a -> a -> Ordering) -> [a] -> [a]

-- | &lt;math&gt;. The <a>genericLength</a> function is an overloaded
--   version of <a>length</a>. In particular, instead of returning an
--   <a>Int</a>, it returns any type which is an instance of <a>Num</a>. It
--   is, however, less efficient than <a>length</a>.
--   
--   <pre>
--   &gt;&gt;&gt; genericLength [1, 2, 3] :: Int
--   3
--   
--   &gt;&gt;&gt; genericLength [1, 2, 3] :: Float
--   3.0
--   </pre>
--   
--   Users should take care to pick a return type that is wide enough to
--   contain the full length of the list. If the width is insufficient, the
--   overflow behaviour will depend on the <tt>(+)</tt> implementation in
--   the selected <a>Num</a> instance. The following example overflows
--   because the actual list length of 200 lies outside of the
--   <tt>Int8</tt> range of <tt>-128..127</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; genericLength [1..200] :: Int8
--   -56
--   </pre>
genericLength :: Num i => [a] -> i

-- | The largest element of a non-empty structure with respect to the given
--   comparison function.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; maximumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
--   "Longest"
--   </pre>
--   
--   WARNING: This function is partial for possibly-empty structures like
--   lists.
maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a

-- | The least element of a non-empty structure with respect to the given
--   comparison function.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; minimumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
--   "!"
--   </pre>
--   
--   WARNING: This function is partial for possibly-empty structures like
--   lists.
minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a

-- | The <a>genericReplicate</a> function is an overloaded version of
--   <a>replicate</a>, which accepts any <a>Integral</a> value as the
--   number of repetitions to make.
genericReplicate :: Integral i => i -> a -> [a]

-- | The <a>genericTake</a> function is an overloaded version of
--   <a>take</a>, which accepts any <a>Integral</a> value as the number of
--   elements to take.
genericTake :: Integral i => i -> [a] -> [a]

-- | The <a>genericDrop</a> function is an overloaded version of
--   <a>drop</a>, which accepts any <a>Integral</a> value as the number of
--   elements to drop.
genericDrop :: Integral i => i -> [a] -> [a]

-- | The <a>genericSplitAt</a> function is an overloaded version of
--   <a>splitAt</a>, which accepts any <a>Integral</a> value as the
--   position at which to split.
genericSplitAt :: Integral i => i -> [a] -> ([a], [a])

-- | The <a>genericIndex</a> function is an overloaded version of
--   <a>!!</a>, which accepts any <a>Integral</a> value as the index.
genericIndex :: Integral i => [a] -> i -> a

-- | &lt;math&gt;. Extract the first element of a list, which must be
--   non-empty.
--   
--   <pre>
--   &gt;&gt;&gt; head [1, 2, 3]
--   1
--   
--   &gt;&gt;&gt; head [1..]
--   1
--   
--   &gt;&gt;&gt; head []
--   *** Exception: Prelude.head: empty list
--   </pre>
--   
--   WARNING: This function is partial. You can use case-matching,
--   <a>uncons</a> or <a>listToMaybe</a> instead.
head :: HasCallStack => [a] -> a

-- | The <a>group</a> function takes a list and returns a list of lists
--   such that the concatenation of the result is equal to the argument.
--   Moreover, each sublist in the result is non-empty and all elements are
--   equal to the first one. For example,
--   
--   <pre>
--   &gt;&gt;&gt; group "Mississippi"
--   ["M","i","ss","i","ss","i","pp","i"]
--   </pre>
--   
--   <a>group</a> is a special case of <a>groupBy</a>, which allows the
--   programmer to supply their own equality test.
--   
--   It's often preferable to use <tt>Data.List.NonEmpty.</tt><a>group</a>,
--   which provides type-level guarantees of non-emptiness of inner lists.
group :: Eq a => [a] -> [[a]]

-- | The <a>groupBy</a> function is the non-overloaded version of
--   <a>group</a>.
--   
--   When a supplied relation is not transitive, it is important to
--   remember that equality is checked against the first element in the
--   group, not against the nearest neighbour:
--   
--   <pre>
--   &gt;&gt;&gt; groupBy (\a b -&gt; b - a &lt; 5) [0..19]
--   [[0,1,2,3,4],[5,6,7,8,9],[10,11,12,13,14],[15,16,17,18,19]]
--   </pre>
--   
--   It's often preferable to use
--   <tt>Data.List.NonEmpty.</tt><a>groupBy</a>, which provides type-level
--   guarantees of non-emptiness of inner lists.
groupBy :: (a -> a -> Bool) -> [a] -> [[a]]

-- | &lt;math&gt;. <a>filter</a>, applied to a predicate and a list,
--   returns the list of those elements that satisfy the predicate; i.e.,
--   
--   <pre>
--   filter p xs = [ x | x &lt;- xs, p x]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; filter odd [1, 2, 3]
--   [1,3]
--   </pre>
filter :: (a -> Bool) -> [a] -> [a]

-- | The <a>unfoldr</a> function is a `dual' to <a>foldr</a>: while
--   <a>foldr</a> reduces a list to a summary value, <a>unfoldr</a> builds
--   a list from a seed value. The function takes the element and returns
--   <a>Nothing</a> if it is done producing the list or returns <a>Just</a>
--   <tt>(a,b)</tt>, in which case, <tt>a</tt> is a prepended to the list
--   and <tt>b</tt> is used as the next element in a recursive call. For
--   example,
--   
--   <pre>
--   iterate f == unfoldr (\x -&gt; Just (x, f x))
--   </pre>
--   
--   In some cases, <a>unfoldr</a> can undo a <a>foldr</a> operation:
--   
--   <pre>
--   unfoldr f' (foldr f z xs) == xs
--   </pre>
--   
--   if the following holds:
--   
--   <pre>
--   f' (f x y) = Just (x,y)
--   f' z       = Nothing
--   </pre>
--   
--   A simple use of unfoldr:
--   
--   <pre>
--   &gt;&gt;&gt; unfoldr (\b -&gt; if b == 0 then Nothing else Just (b, b-1)) 10
--   [10,9,8,7,6,5,4,3,2,1]
--   </pre>
unfoldr :: (b -> Maybe (a, b)) -> b -> [a]

-- | The <a>transpose</a> function transposes the rows and columns of its
--   argument. For example,
--   
--   <pre>
--   &gt;&gt;&gt; transpose [[1,2,3],[4,5,6]]
--   [[1,4],[2,5],[3,6]]
--   </pre>
--   
--   If some of the rows are shorter than the following rows, their
--   elements are skipped:
--   
--   <pre>
--   &gt;&gt;&gt; transpose [[10,11],[20],[],[30,31,32]]
--   [[10,20,30],[11,31],[32]]
--   </pre>
--   
--   For this reason the outer list must be finite; otherwise
--   <a>transpose</a> hangs:
--   
--   <pre>
--   &gt;&gt;&gt; transpose (repeat [])
--   * Hangs forever *
--   </pre>
transpose :: [[a]] -> [[a]]

-- | Sort a list by comparing the results of a key function applied to each
--   element. <tt><a>sortOn</a> f</tt> is equivalent to <tt><a>sortBy</a>
--   (<a>comparing</a> f)</tt>, but has the performance advantage of only
--   evaluating <tt>f</tt> once for each element in the input list. This is
--   called the decorate-sort-undecorate paradigm, or <a>Schwartzian
--   transform</a>.
--   
--   Elements are arranged from lowest to highest, keeping duplicates in
--   the order they appeared in the input.
--   
--   <pre>
--   &gt;&gt;&gt; sortOn fst [(2, "world"), (4, "!"), (1, "Hello")]
--   [(1,"Hello"),(2,"world"),(4,"!")]
--   </pre>
--   
--   The argument must be finite.
sortOn :: Ord b => (a -> b) -> [a] -> [a]

-- | <a>cycle</a> ties a finite list into a circular one, or equivalently,
--   the infinite repetition of the original list. It is the identity on
--   infinite lists.
--   
--   <pre>
--   &gt;&gt;&gt; cycle []
--   *** Exception: Prelude.cycle: empty list
--   
--   &gt;&gt;&gt; cycle [42]
--   [42,42,42,42,42,42,42,42,42,42...
--   
--   &gt;&gt;&gt; cycle [2, 5, 7]
--   [2,5,7,2,5,7,2,5,7,2,5,7...
--   </pre>
cycle :: HasCallStack => [a] -> [a]

-- | The concatenation of all the elements of a container of lists.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; concat (Just [1, 2, 3])
--   [1,2,3]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; concat (Left 42)
--   []
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; concat [[1, 2, 3], [4, 5], [6], []]
--   [1,2,3,4,5,6]
--   </pre>
concat :: Foldable t => t [a] -> [a]

-- | &lt;math&gt;. <a>zip</a> takes two lists and returns a list of
--   corresponding pairs.
--   
--   <pre>
--   &gt;&gt;&gt; zip [1, 2] ['a', 'b']
--   [(1,'a'),(2,'b')]
--   </pre>
--   
--   If one input list is shorter than the other, excess elements of the
--   longer list are discarded, even if one of the lists is infinite:
--   
--   <pre>
--   &gt;&gt;&gt; zip [1] ['a', 'b']
--   [(1,'a')]
--   
--   &gt;&gt;&gt; zip [1, 2] ['a']
--   [(1,'a')]
--   
--   &gt;&gt;&gt; zip [] [1..]
--   []
--   
--   &gt;&gt;&gt; zip [1..] []
--   []
--   </pre>
--   
--   <a>zip</a> is right-lazy:
--   
--   <pre>
--   &gt;&gt;&gt; zip [] undefined
--   []
--   
--   &gt;&gt;&gt; zip undefined []
--   *** Exception: Prelude.undefined
--   ...
--   </pre>
--   
--   <a>zip</a> is capable of list fusion, but it is restricted to its
--   first list argument and its resulting list.
zip :: [a] -> [b] -> [(a, b)]

-- | &lt;math&gt;. Decompose a list into its head and tail.
--   
--   <ul>
--   <li>If the list is empty, returns <a>Nothing</a>.</li>
--   <li>If the list is non-empty, returns <tt><a>Just</a> (x, xs)</tt>,
--   where <tt>x</tt> is the head of the list and <tt>xs</tt> its
--   tail.</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; uncons []
--   Nothing
--   
--   &gt;&gt;&gt; uncons [1]
--   Just (1,[])
--   
--   &gt;&gt;&gt; uncons [1, 2, 3]
--   Just (1,[2,3])
--   </pre>
uncons :: [a] -> Maybe (a, [a])

-- | &lt;math&gt;. Extract the elements after the head of a list, which
--   must be non-empty.
--   
--   <pre>
--   &gt;&gt;&gt; tail [1, 2, 3]
--   [2,3]
--   
--   &gt;&gt;&gt; tail [1]
--   []
--   
--   &gt;&gt;&gt; tail []
--   *** Exception: Prelude.tail: empty list
--   </pre>
--   
--   WARNING: This function is partial. You can use case-matching or
--   <a>uncons</a> instead.
tail :: HasCallStack => [a] -> [a]

-- | &lt;math&gt;. Extract the last element of a list, which must be finite
--   and non-empty.
--   
--   <pre>
--   &gt;&gt;&gt; last [1, 2, 3]
--   3
--   
--   &gt;&gt;&gt; last [1..]
--   * Hangs forever *
--   
--   &gt;&gt;&gt; last []
--   *** Exception: Prelude.last: empty list
--   </pre>
--   
--   WARNING: This function is partial. You can use <a>reverse</a> with
--   case-matching, <a>uncons</a> or <a>listToMaybe</a> instead.
last :: HasCallStack => [a] -> a

-- | &lt;math&gt;. Return all the elements of a list except the last one.
--   The list must be non-empty.
--   
--   <pre>
--   &gt;&gt;&gt; init [1, 2, 3]
--   [1,2]
--   
--   &gt;&gt;&gt; init [1]
--   []
--   
--   &gt;&gt;&gt; init []
--   *** Exception: Prelude.init: empty list
--   </pre>
--   
--   WARNING: This function is partial. You can use <a>reverse</a> with
--   case-matching or <a>uncons</a> instead.
init :: HasCallStack => [a] -> [a]

-- | A strict version of <a>foldl1</a>.
foldl1' :: HasCallStack => (a -> a -> a) -> [a] -> a

-- | &lt;math&gt;. <a>scanl</a> is similar to <a>foldl</a>, but returns a
--   list of successive reduced values from the left:
--   
--   <pre>
--   scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]
--   </pre>
--   
--   Note that
--   
--   <pre>
--   last (scanl f z xs) == foldl f z xs
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; scanl (+) 0 [1..4]
--   [0,1,3,6,10]
--   
--   &gt;&gt;&gt; scanl (+) 42 []
--   [42]
--   
--   &gt;&gt;&gt; scanl (-) 100 [1..4]
--   [100,99,97,94,90]
--   
--   &gt;&gt;&gt; scanl (\reversedString nextChar -&gt; nextChar : reversedString) "foo" ['a', 'b', 'c', 'd']
--   ["foo","afoo","bafoo","cbafoo","dcbafoo"]
--   
--   &gt;&gt;&gt; scanl (+) 0 [1..]
--   * Hangs forever *
--   </pre>
scanl :: (b -> a -> b) -> b -> [a] -> [b]

-- | &lt;math&gt;. <a>scanl1</a> is a variant of <a>scanl</a> that has no
--   starting value argument:
--   
--   <pre>
--   scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; scanl1 (+) [1..4]
--   [1,3,6,10]
--   
--   &gt;&gt;&gt; scanl1 (+) []
--   []
--   
--   &gt;&gt;&gt; scanl1 (-) [1..4]
--   [1,-1,-4,-8]
--   
--   &gt;&gt;&gt; scanl1 (&amp;&amp;) [True, False, True, True]
--   [True,False,False,False]
--   
--   &gt;&gt;&gt; scanl1 (||) [False, False, True, True]
--   [False,False,True,True]
--   
--   &gt;&gt;&gt; scanl1 (+) [1..]
--   * Hangs forever *
--   </pre>
scanl1 :: (a -> a -> a) -> [a] -> [a]

-- | &lt;math&gt;. A strict version of <a>scanl</a>.
scanl' :: (b -> a -> b) -> b -> [a] -> [b]

-- | &lt;math&gt;. <a>scanr</a> is the right-to-left dual of <a>scanl</a>.
--   Note that the order of parameters on the accumulating function are
--   reversed compared to <a>scanl</a>. Also note that
--   
--   <pre>
--   head (scanr f z xs) == foldr f z xs.
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; scanr (+) 0 [1..4]
--   [10,9,7,4,0]
--   
--   &gt;&gt;&gt; scanr (+) 42 []
--   [42]
--   
--   &gt;&gt;&gt; scanr (-) 100 [1..4]
--   [98,-97,99,-96,100]
--   
--   &gt;&gt;&gt; scanr (\nextChar reversedString -&gt; nextChar : reversedString) "foo" ['a', 'b', 'c', 'd']
--   ["abcdfoo","bcdfoo","cdfoo","dfoo","foo"]
--   
--   &gt;&gt;&gt; force $ scanr (+) 0 [1..]
--   *** Exception: stack overflow
--   </pre>
scanr :: (a -> b -> b) -> b -> [a] -> [b]

-- | &lt;math&gt;. <a>scanr1</a> is a variant of <a>scanr</a> that has no
--   starting value argument.
--   
--   <pre>
--   &gt;&gt;&gt; scanr1 (+) [1..4]
--   [10,9,7,4]
--   
--   &gt;&gt;&gt; scanr1 (+) []
--   []
--   
--   &gt;&gt;&gt; scanr1 (-) [1..4]
--   [-2,3,-1,4]
--   
--   &gt;&gt;&gt; scanr1 (&amp;&amp;) [True, False, True, True]
--   [False,False,True,True]
--   
--   &gt;&gt;&gt; scanr1 (||) [True, True, False, False]
--   [True,True,False,False]
--   
--   &gt;&gt;&gt; force $ scanr1 (+) [1..]
--   *** Exception: stack overflow
--   </pre>
scanr1 :: (a -> a -> a) -> [a] -> [a]

-- | <a>iterate</a> <tt>f x</tt> returns an infinite list of repeated
--   applications of <tt>f</tt> to <tt>x</tt>:
--   
--   <pre>
--   iterate f x == [x, f x, f (f x), ...]
--   </pre>
--   
--   Note that <a>iterate</a> is lazy, potentially leading to thunk
--   build-up if the consumer doesn't force each iterate. See
--   <a>iterate'</a> for a strict variant of this function.
--   
--   <pre>
--   &gt;&gt;&gt; take 10 $ iterate not True
--   [True,False,True,False...
--   
--   &gt;&gt;&gt; take 10 $ iterate (+3) 42
--   [42,45,48,51,54,57,60,63...
--   </pre>
iterate :: (a -> a) -> a -> [a]

-- | <a>iterate'</a> is the strict version of <a>iterate</a>.
--   
--   It forces the result of each application of the function to weak head
--   normal form (WHNF) before proceeding.
iterate' :: (a -> a) -> a -> [a]

-- | <a>repeat</a> <tt>x</tt> is an infinite list, with <tt>x</tt> the
--   value of every element.
--   
--   <pre>
--   &gt;&gt;&gt; repeat 17
--   [17,17,17,17,17,17,17,17,17...
--   </pre>
repeat :: a -> [a]

-- | <a>replicate</a> <tt>n x</tt> is a list of length <tt>n</tt> with
--   <tt>x</tt> the value of every element. It is an instance of the more
--   general <a>genericReplicate</a>, in which <tt>n</tt> may be of any
--   integral type.
--   
--   <pre>
--   &gt;&gt;&gt; replicate 0 True
--   []
--   
--   &gt;&gt;&gt; replicate (-1) True
--   []
--   
--   &gt;&gt;&gt; replicate 4 True
--   [True,True,True,True]
--   </pre>
replicate :: Int -> a -> [a]

-- | <a>takeWhile</a>, applied to a predicate <tt>p</tt> and a list
--   <tt>xs</tt>, returns the longest prefix (possibly empty) of
--   <tt>xs</tt> of elements that satisfy <tt>p</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; takeWhile (&lt; 3) [1,2,3,4,1,2,3,4]
--   [1,2]
--   
--   &gt;&gt;&gt; takeWhile (&lt; 9) [1,2,3]
--   [1,2,3]
--   
--   &gt;&gt;&gt; takeWhile (&lt; 0) [1,2,3]
--   []
--   </pre>
takeWhile :: (a -> Bool) -> [a] -> [a]

-- | <a>dropWhile</a> <tt>p xs</tt> returns the suffix remaining after
--   <a>takeWhile</a> <tt>p xs</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; dropWhile (&lt; 3) [1,2,3,4,5,1,2,3]
--   [3,4,5,1,2,3]
--   
--   &gt;&gt;&gt; dropWhile (&lt; 9) [1,2,3]
--   []
--   
--   &gt;&gt;&gt; dropWhile (&lt; 0) [1,2,3]
--   [1,2,3]
--   </pre>
dropWhile :: (a -> Bool) -> [a] -> [a]

-- | <a>take</a> <tt>n</tt>, applied to a list <tt>xs</tt>, returns the
--   prefix of <tt>xs</tt> of length <tt>n</tt>, or <tt>xs</tt> itself if
--   <tt>n &gt;= <a>length</a> xs</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 "Hello World!"
--   "Hello"
--   
--   &gt;&gt;&gt; take 3 [1,2,3,4,5]
--   [1,2,3]
--   
--   &gt;&gt;&gt; take 3 [1,2]
--   [1,2]
--   
--   &gt;&gt;&gt; take 3 []
--   []
--   
--   &gt;&gt;&gt; take (-1) [1,2]
--   []
--   
--   &gt;&gt;&gt; take 0 [1,2]
--   []
--   </pre>
--   
--   It is an instance of the more general <a>genericTake</a>, in which
--   <tt>n</tt> may be of any integral type.
take :: Int -> [a] -> [a]

-- | <a>drop</a> <tt>n xs</tt> returns the suffix of <tt>xs</tt> after the
--   first <tt>n</tt> elements, or <tt>[]</tt> if <tt>n &gt;= <a>length</a>
--   xs</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; drop 6 "Hello World!"
--   "World!"
--   
--   &gt;&gt;&gt; drop 3 [1,2,3,4,5]
--   [4,5]
--   
--   &gt;&gt;&gt; drop 3 [1,2]
--   []
--   
--   &gt;&gt;&gt; drop 3 []
--   []
--   
--   &gt;&gt;&gt; drop (-1) [1,2]
--   [1,2]
--   
--   &gt;&gt;&gt; drop 0 [1,2]
--   [1,2]
--   </pre>
--   
--   It is an instance of the more general <a>genericDrop</a>, in which
--   <tt>n</tt> may be of any integral type.
drop :: Int -> [a] -> [a]

-- | <a>splitAt</a> <tt>n xs</tt> returns a tuple where first element is
--   <tt>xs</tt> prefix of length <tt>n</tt> and second element is the
--   remainder of the list:
--   
--   <pre>
--   &gt;&gt;&gt; splitAt 6 "Hello World!"
--   ("Hello ","World!")
--   
--   &gt;&gt;&gt; splitAt 3 [1,2,3,4,5]
--   ([1,2,3],[4,5])
--   
--   &gt;&gt;&gt; splitAt 1 [1,2,3]
--   ([1],[2,3])
--   
--   &gt;&gt;&gt; splitAt 3 [1,2,3]
--   ([1,2,3],[])
--   
--   &gt;&gt;&gt; splitAt 4 [1,2,3]
--   ([1,2,3],[])
--   
--   &gt;&gt;&gt; splitAt 0 [1,2,3]
--   ([],[1,2,3])
--   
--   &gt;&gt;&gt; splitAt (-1) [1,2,3]
--   ([],[1,2,3])
--   </pre>
--   
--   It is equivalent to <tt>(<a>take</a> n xs, <a>drop</a> n xs)</tt> when
--   <tt>n</tt> is not <tt>_|_</tt> (<tt>splitAt _|_ xs = _|_</tt>).
--   <a>splitAt</a> is an instance of the more general
--   <a>genericSplitAt</a>, in which <tt>n</tt> may be of any integral
--   type.
splitAt :: Int -> [a] -> ([a], [a])

-- | <a>span</a>, applied to a predicate <tt>p</tt> and a list <tt>xs</tt>,
--   returns a tuple where first element is longest prefix (possibly empty)
--   of <tt>xs</tt> of elements that satisfy <tt>p</tt> and second element
--   is the remainder of the list:
--   
--   <pre>
--   &gt;&gt;&gt; span (&lt; 3) [1,2,3,4,1,2,3,4]
--   ([1,2],[3,4,1,2,3,4])
--   
--   &gt;&gt;&gt; span (&lt; 9) [1,2,3]
--   ([1,2,3],[])
--   
--   &gt;&gt;&gt; span (&lt; 0) [1,2,3]
--   ([],[1,2,3])
--   </pre>
--   
--   <a>span</a> <tt>p xs</tt> is equivalent to <tt>(<a>takeWhile</a> p xs,
--   <a>dropWhile</a> p xs)</tt>
span :: (a -> Bool) -> [a] -> ([a], [a])

-- | <a>break</a>, applied to a predicate <tt>p</tt> and a list
--   <tt>xs</tt>, returns a tuple where first element is longest prefix
--   (possibly empty) of <tt>xs</tt> of elements that <i>do not satisfy</i>
--   <tt>p</tt> and second element is the remainder of the list:
--   
--   <pre>
--   &gt;&gt;&gt; break (&gt; 3) [1,2,3,4,1,2,3,4]
--   ([1,2,3],[4,1,2,3,4])
--   
--   &gt;&gt;&gt; break (&lt; 9) [1,2,3]
--   ([],[1,2,3])
--   
--   &gt;&gt;&gt; break (&gt; 9) [1,2,3]
--   ([1,2,3],[])
--   </pre>
--   
--   <a>break</a> <tt>p</tt> is equivalent to <tt><a>span</a> (<a>not</a> .
--   p)</tt>.
break :: (a -> Bool) -> [a] -> ([a], [a])

-- | <a>reverse</a> <tt>xs</tt> returns the elements of <tt>xs</tt> in
--   reverse order. <tt>xs</tt> must be finite.
--   
--   <pre>
--   &gt;&gt;&gt; reverse []
--   []
--   
--   &gt;&gt;&gt; reverse [42]
--   [42]
--   
--   &gt;&gt;&gt; reverse [2,5,7]
--   [7,5,2]
--   
--   &gt;&gt;&gt; reverse [1..]
--   * Hangs forever *
--   </pre>
reverse :: [a] -> [a]

-- | <a>and</a> returns the conjunction of a container of Bools. For the
--   result to be <a>True</a>, the container must be finite; <a>False</a>,
--   however, results from a <a>False</a> value finitely far from the left
--   end.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; and []
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and [True]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and [False]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and [True, True, False]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and (False : repeat True) -- Infinite list [False,True,True,True,...
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; and (repeat True)
--   * Hangs forever *
--   </pre>
and :: Foldable t => t Bool -> Bool

-- | <a>or</a> returns the disjunction of a container of Bools. For the
--   result to be <a>False</a>, the container must be finite; <a>True</a>,
--   however, results from a <a>True</a> value finitely far from the left
--   end.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; or []
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or [True]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or [False]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or [True, True, False]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or (True : repeat False) -- Infinite list [True,False,False,False,...
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; or (repeat False)
--   * Hangs forever *
--   </pre>
or :: Foldable t => t Bool -> Bool

-- | Determines whether any element of the structure satisfies the
--   predicate.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) []
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) [1,2]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) [1,2,3,4,5]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) [1..]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; any (&gt; 3) [0, -1..]
--   * Hangs forever *
--   </pre>
any :: Foldable t => (a -> Bool) -> t a -> Bool

-- | <a>notElem</a> is the negation of <a>elem</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` []
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` [1,2]
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` [1,2,3,4,5]
--   False
--   </pre>
--   
--   For infinite structures, <a>notElem</a> terminates if the value exists
--   at a finite distance from the left side of the structure:
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` [1..]
--   False
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; 3 `notElem` ([4..] ++ [3])
--   * Hangs forever *
--   </pre>
notElem :: (Foldable t, Eq a) => a -> t a -> Bool
infix 4 `notElem`

-- | &lt;math&gt;. <a>lookup</a> <tt>key assocs</tt> looks up a key in an
--   association list. For the result to be <a>Nothing</a>, the list must
--   be finite.
--   
--   <pre>
--   &gt;&gt;&gt; lookup 2 []
--   Nothing
--   
--   &gt;&gt;&gt; lookup 2 [(1, "first")]
--   Nothing
--   
--   &gt;&gt;&gt; lookup 2 [(1, "first"), (2, "second"), (3, "third")]
--   Just "second"
--   </pre>
lookup :: Eq a => a -> [(a, b)] -> Maybe b

-- | Map a function over all the elements of a container and concatenate
--   the resulting lists.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; concatMap (take 3) [[1..], [10..], [100..], [1000..]]
--   [1,2,3,10,11,12,100,101,102,1000,1001,1002]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; concatMap (take 3) (Just [1..])
--   [1,2,3]
--   </pre>
concatMap :: Foldable t => (a -> [b]) -> t a -> [b]

-- | List index (subscript) operator, starting from 0. It is an instance of
--   the more general <a>genericIndex</a>, which takes an index of any
--   integral type.
--   
--   <pre>
--   &gt;&gt;&gt; ['a', 'b', 'c'] !! 0
--   'a'
--   
--   &gt;&gt;&gt; ['a', 'b', 'c'] !! 2
--   'c'
--   
--   &gt;&gt;&gt; ['a', 'b', 'c'] !! 3
--   *** Exception: Prelude.!!: index too large
--   
--   &gt;&gt;&gt; ['a', 'b', 'c'] !! (-1)
--   *** Exception: Prelude.!!: negative index
--   </pre>
--   
--   WARNING: This function is partial. You can use <a>atMay</a> instead.
(!!) :: HasCallStack => [a] -> Int -> a
infixl 9 !!

-- | <a>zip3</a> takes three lists and returns a list of triples, analogous
--   to <a>zip</a>. It is capable of list fusion, but it is restricted to
--   its first list argument and its resulting list.
zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]

-- | The <a>zipWith3</a> function takes a function which combines three
--   elements, as well as three lists and returns a list of the function
--   applied to corresponding elements, analogous to <a>zipWith</a>. It is
--   capable of list fusion, but it is restricted to its first list
--   argument and its resulting list.
--   
--   <pre>
--   zipWith3 (,,) xs ys zs == zip3 xs ys zs
--   zipWith3 f [x1,x2,x3..] [y1,y2,y3..] [z1,z2,z3..] == [f x1 y1 z1, f x2 y2 z2, f x3 y3 z3..]
--   </pre>
zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]

-- | <a>unzip</a> transforms a list of pairs into a list of first
--   components and a list of second components.
--   
--   <pre>
--   &gt;&gt;&gt; unzip []
--   ([],[])
--   
--   &gt;&gt;&gt; unzip [(1, 'a'), (2, 'b')]
--   ([1,2],"ab")
--   </pre>
unzip :: [(a, b)] -> ([a], [b])

-- | The <a>unzip3</a> function takes a list of triples and returns three
--   lists, analogous to <a>unzip</a>.
--   
--   <pre>
--   &gt;&gt;&gt; unzip3 []
--   ([],[],[])
--   
--   &gt;&gt;&gt; unzip3 [(1, 'a', True), (2, 'b', False)]
--   ([1,2],"ab",[True,False])
--   </pre>
unzip3 :: [(a, b, c)] -> ([a], [b], [c])

-- | The <a>find</a> function takes a predicate and a structure and returns
--   the leftmost element of the structure matching the predicate, or
--   <a>Nothing</a> if there is no such element.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; find (&gt; 42) [0, 5..]
--   Just 45
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; find (&gt; 12) [1..7]
--   Nothing
--   </pre>
find :: Foldable t => (a -> Bool) -> t a -> Maybe a

-- | The <a>dropWhileEnd</a> function drops the largest suffix of a list in
--   which the given predicate holds for all elements. For example:
--   
--   <pre>
--   &gt;&gt;&gt; dropWhileEnd isSpace "foo\n"
--   "foo"
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; dropWhileEnd isSpace "foo bar"
--   "foo bar"
--   </pre>
--   
--   <pre>
--   dropWhileEnd isSpace ("foo\n" ++ undefined) == "foo" ++ undefined
--   </pre>
dropWhileEnd :: (a -> Bool) -> [a] -> [a]

-- | &lt;math&gt;. The <a>stripPrefix</a> function drops the given prefix
--   from a list. It returns <a>Nothing</a> if the list did not start with
--   the prefix given, or <a>Just</a> the list after the prefix, if it
--   does.
--   
--   <pre>
--   &gt;&gt;&gt; stripPrefix "foo" "foobar"
--   Just "bar"
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; stripPrefix "foo" "foo"
--   Just ""
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; stripPrefix "foo" "barfoo"
--   Nothing
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; stripPrefix "foo" "barfoobaz"
--   Nothing
--   </pre>
stripPrefix :: Eq a => [a] -> [a] -> Maybe [a]

-- | The <a>elemIndex</a> function returns the index of the first element
--   in the given list which is equal (by <a>==</a>) to the query element,
--   or <a>Nothing</a> if there is no such element. For the result to be
--   <a>Nothing</a>, the list must be finite.
--   
--   <pre>
--   &gt;&gt;&gt; elemIndex 4 [0..]
--   Just 4
--   </pre>
elemIndex :: Eq a => a -> [a] -> Maybe Int

-- | The <a>elemIndices</a> function extends <a>elemIndex</a>, by returning
--   the indices of all elements equal to the query element, in ascending
--   order.
--   
--   <pre>
--   &gt;&gt;&gt; elemIndices 'o' "Hello World"
--   [4,7]
--   </pre>
elemIndices :: Eq a => a -> [a] -> [Int]

-- | The <a>findIndex</a> function takes a predicate and a list and returns
--   the index of the first element in the list satisfying the predicate,
--   or <a>Nothing</a> if there is no such element. For the result to be
--   <a>Nothing</a>, the list must be finite.
--   
--   <pre>
--   &gt;&gt;&gt; findIndex isSpace "Hello World!"
--   Just 5
--   </pre>
findIndex :: (a -> Bool) -> [a] -> Maybe Int

-- | The <a>findIndices</a> function extends <a>findIndex</a>, by returning
--   the indices of all elements satisfying the predicate, in ascending
--   order.
--   
--   <pre>
--   &gt;&gt;&gt; findIndices (`elem` "aeiou") "Hello World!"
--   [1,4,7]
--   </pre>
findIndices :: (a -> Bool) -> [a] -> [Int]

-- | &lt;math&gt;. The <a>isPrefixOf</a> function takes two lists and
--   returns <a>True</a> iff the first list is a prefix of the second.
--   
--   <pre>
--   &gt;&gt;&gt; "Hello" `isPrefixOf` "Hello World!"
--   True
--   
--   &gt;&gt;&gt; "Hello" `isPrefixOf` "Wello Horld!"
--   False
--   </pre>
--   
--   For the result to be <a>True</a>, the first list must be finite;
--   <a>False</a>, however, results from any mismatch:
--   
--   <pre>
--   &gt;&gt;&gt; [0..] `isPrefixOf` [1..]
--   False
--   
--   &gt;&gt;&gt; [0..] `isPrefixOf` [0..99]
--   False
--   
--   &gt;&gt;&gt; [0..99] `isPrefixOf` [0..]
--   True
--   
--   &gt;&gt;&gt; [0..] `isPrefixOf` [0..]
--   * Hangs forever *
--   </pre>
isPrefixOf :: Eq a => [a] -> [a] -> Bool

-- | The <a>isSuffixOf</a> function takes two lists and returns <a>True</a>
--   iff the first list is a suffix of the second.
--   
--   <pre>
--   &gt;&gt;&gt; "ld!" `isSuffixOf` "Hello World!"
--   True
--   
--   &gt;&gt;&gt; "World" `isSuffixOf` "Hello World!"
--   False
--   </pre>
--   
--   The second list must be finite; however the first list may be
--   infinite:
--   
--   <pre>
--   &gt;&gt;&gt; [0..] `isSuffixOf` [0..99]
--   False
--   
--   &gt;&gt;&gt; [0..99] `isSuffixOf` [0..]
--   * Hangs forever *
--   </pre>
isSuffixOf :: Eq a => [a] -> [a] -> Bool

-- | The <a>isInfixOf</a> function takes two lists and returns <a>True</a>
--   iff the first list is contained, wholly and intact, anywhere within
--   the second.
--   
--   <pre>
--   &gt;&gt;&gt; isInfixOf "Haskell" "I really like Haskell."
--   True
--   
--   &gt;&gt;&gt; isInfixOf "Ial" "I really like Haskell."
--   False
--   </pre>
--   
--   For the result to be <a>True</a>, the first list must be finite; for
--   the result to be <a>False</a>, the second list must be finite:
--   
--   <pre>
--   &gt;&gt;&gt; [20..50] `isInfixOf` [0..]
--   True
--   
--   &gt;&gt;&gt; [0..] `isInfixOf` [20..50]
--   False
--   
--   &gt;&gt;&gt; [0..] `isInfixOf` [0..]
--   * Hangs forever *
--   </pre>
isInfixOf :: Eq a => [a] -> [a] -> Bool

-- | &lt;math&gt;. The <a>nub</a> function removes duplicate elements from
--   a list. In particular, it keeps only the first occurrence of each
--   element. (The name <a>nub</a> means `essence'.) It is a special case
--   of <a>nubBy</a>, which allows the programmer to supply their own
--   equality test.
--   
--   <pre>
--   &gt;&gt;&gt; nub [1,2,3,4,3,2,1,2,4,3,5]
--   [1,2,3,4,5]
--   </pre>
--   
--   If the order of outputs does not matter and there exists <tt>instance
--   Ord a</tt>, it's faster to use <a>map</a>
--   <tt>Data.List.NonEmpty.</tt><a>head</a> .
--   <tt>Data.List.NonEmpty.</tt><a>group</a> . <a>sort</a>, which takes
--   only &lt;math&gt; time.
nub :: Eq a => [a] -> [a]

-- | The <a>nubBy</a> function behaves just like <a>nub</a>, except it uses
--   a user-supplied equality predicate instead of the overloaded <a>==</a>
--   function.
--   
--   <pre>
--   &gt;&gt;&gt; nubBy (\x y -&gt; mod x 3 == mod y 3) [1,2,4,5,6]
--   [1,2,6]
--   </pre>
nubBy :: (a -> a -> Bool) -> [a] -> [a]

-- | &lt;math&gt;. The <a>deleteBy</a> function behaves like <a>delete</a>,
--   but takes a user-supplied equality predicate.
--   
--   <pre>
--   &gt;&gt;&gt; deleteBy (&lt;=) 4 [1..10]
--   [1,2,3,5,6,7,8,9,10]
--   </pre>
deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]

-- | The <a>\\</a> function is list difference (non-associative). In the
--   result of <tt>xs</tt> <a>\\</a> <tt>ys</tt>, the first occurrence of
--   each element of <tt>ys</tt> in turn (if any) has been removed from
--   <tt>xs</tt>. Thus <tt>(xs ++ ys) \\ xs == ys</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; "Hello World!" \\ "ell W"
--   "Hoorld!"
--   </pre>
--   
--   It is a special case of <a>deleteFirstsBy</a>, which allows the
--   programmer to supply their own equality test.
--   
--   The second list must be finite, but the first may be infinite.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 ([0..] \\ [2..4])
--   [0,1,5,6,7]
--   
--   &gt;&gt;&gt; take 5 ([0..] \\ [2..])
--   * Hangs forever *
--   </pre>
(\\) :: Eq a => [a] -> [a] -> [a]
infix 5 \\

-- | The <a>union</a> function returns the list union of the two lists. It
--   is a special case of <a>unionBy</a>, which allows the programmer to
--   supply their own equality test. For example,
--   
--   <pre>
--   &gt;&gt;&gt; "dog" `union` "cow"
--   "dogcw"
--   </pre>
--   
--   If equal elements are present in both lists, an element from the first
--   list will be used. If the second list contains equal elements, only
--   the first one will be retained:
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Semigroup
--   
--   &gt;&gt;&gt; union [Arg () "dog"] [Arg () "cow"]
--   [Arg () "dog"]
--   
--   &gt;&gt;&gt; union [] [Arg () "dog", Arg () "cow"]
--   [Arg () "dog"]
--   </pre>
--   
--   However if the first list contains duplicates, so will the result:
--   
--   <pre>
--   &gt;&gt;&gt; "coot" `union` "duck"
--   "cootduk"
--   
--   &gt;&gt;&gt; "duck" `union` "coot"
--   "duckot"
--   </pre>
--   
--   <a>union</a> is productive even if both arguments are infinite.
union :: Eq a => [a] -> [a] -> [a]

-- | The <a>unionBy</a> function is the non-overloaded version of
--   <a>union</a>. Both arguments may be infinite.
unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]

-- | The <a>intersect</a> function takes the list intersection of two
--   lists. It is a special case of <a>intersectBy</a>, which allows the
--   programmer to supply their own equality test. For example,
--   
--   <pre>
--   &gt;&gt;&gt; [1,2,3,4] `intersect` [2,4,6,8]
--   [2,4]
--   </pre>
--   
--   If equal elements are present in both lists, an element from the first
--   list will be used, and all duplicates from the second list quashed:
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Semigroup
--   
--   &gt;&gt;&gt; intersect [Arg () "dog"] [Arg () "cow", Arg () "cat"]
--   [Arg () "dog"]
--   </pre>
--   
--   However if the first list contains duplicates, so will the result.
--   
--   <pre>
--   &gt;&gt;&gt; "coot" `intersect` "heron"
--   "oo"
--   
--   &gt;&gt;&gt; "heron" `intersect` "coot"
--   "o"
--   </pre>
--   
--   If the second list is infinite, <a>intersect</a> either hangs or
--   returns its first argument in full. Otherwise if the first list is
--   infinite, <a>intersect</a> might be productive:
--   
--   <pre>
--   &gt;&gt;&gt; intersect [100..] [0..]
--   [100,101,102,103...
--   
--   &gt;&gt;&gt; intersect [0] [1..]
--   * Hangs forever *
--   
--   &gt;&gt;&gt; intersect [1..] [0]
--   * Hangs forever *
--   
--   &gt;&gt;&gt; intersect (cycle [1..3]) [2]
--   [2,2,2,2...
--   </pre>
intersect :: Eq a => [a] -> [a] -> [a]

-- | The <a>intersectBy</a> function is the non-overloaded version of
--   <a>intersect</a>. It is productive for infinite arguments only if the
--   first one is a subset of the second.
intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]

-- | &lt;math&gt;. The <a>intersperse</a> function takes an element and a
--   list and `intersperses' that element between the elements of the list.
--   For example,
--   
--   <pre>
--   &gt;&gt;&gt; intersperse ',' "abcde"
--   "a,b,c,d,e"
--   </pre>
intersperse :: a -> [a] -> [a]

-- | <a>intercalate</a> <tt>xs xss</tt> is equivalent to <tt>(<a>concat</a>
--   (<a>intersperse</a> xs xss))</tt>. It inserts the list <tt>xs</tt> in
--   between the lists in <tt>xss</tt> and concatenates the result.
--   
--   <pre>
--   &gt;&gt;&gt; intercalate ", " ["Lorem", "ipsum", "dolor"]
--   "Lorem, ipsum, dolor"
--   </pre>
intercalate :: [a] -> [[a]] -> [a]

-- | The <a>partition</a> function takes a predicate and a list, and
--   returns the pair of lists of elements which do and do not satisfy the
--   predicate, respectively; i.e.,
--   
--   <pre>
--   partition p xs == (filter p xs, filter (not . p) xs)
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; partition (`elem` "aeiou") "Hello World!"
--   ("eoo","Hll Wrld!")
--   </pre>
partition :: (a -> Bool) -> [a] -> ([a], [a])

-- | The <a>mapAccumL</a> function behaves like a combination of
--   <a>fmap</a> and <a>foldl</a>; it applies a function to each element of
--   a structure, passing an accumulating parameter from left to right, and
--   returning a final value of this accumulator together with the new
--   structure.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; mapAccumL (\a b -&gt; (a + b, a)) 0 [1..10]
--   (55,[0,1,3,6,10,15,21,28,36,45])
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; mapAccumL (\a b -&gt; (a &lt;&gt; show b, a)) "0" [1..5]
--   ("012345",["0","01","012","0123","01234"])
--   </pre>
mapAccumL :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b)

-- | The <a>mapAccumR</a> function behaves like a combination of
--   <a>fmap</a> and <a>foldr</a>; it applies a function to each element of
--   a structure, passing an accumulating parameter from right to left, and
--   returning a final value of this accumulator together with the new
--   structure.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; mapAccumR (\a b -&gt; (a + b, a)) 0 [1..10]
--   (55,[54,52,49,45,40,34,27,19,10,0])
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; mapAccumR (\a b -&gt; (a &lt;&gt; show b, a)) "0" [1..5]
--   ("054321",["05432","0543","054","05","0"])
--   </pre>
mapAccumR :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b)

-- | &lt;math&gt;. The <a>insert</a> function takes an element and a list
--   and inserts the element into the list at the first position where it
--   is less than or equal to the next element. In particular, if the list
--   is sorted before the call, the result will also be sorted. It is a
--   special case of <a>insertBy</a>, which allows the programmer to supply
--   their own comparison function.
--   
--   <pre>
--   &gt;&gt;&gt; insert 4 [1,2,3,5,6,7]
--   [1,2,3,4,5,6,7]
--   </pre>
insert :: Ord a => a -> [a] -> [a]

-- | &lt;math&gt;. The non-overloaded version of <a>insert</a>.
insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]

-- | The <a>zip4</a> function takes four lists and returns a list of
--   quadruples, analogous to <a>zip</a>. It is capable of list fusion, but
--   it is restricted to its first list argument and its resulting list.
zip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]

-- | The <a>zip5</a> function takes five lists and returns a list of
--   five-tuples, analogous to <a>zip</a>. It is capable of list fusion,
--   but it is restricted to its first list argument and its resulting
--   list.
zip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]

-- | The <a>zip6</a> function takes six lists and returns a list of
--   six-tuples, analogous to <a>zip</a>. It is capable of list fusion, but
--   it is restricted to its first list argument and its resulting list.
zip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]

-- | The <a>zip7</a> function takes seven lists and returns a list of
--   seven-tuples, analogous to <a>zip</a>. It is capable of list fusion,
--   but it is restricted to its first list argument and its resulting
--   list.
zip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)]

-- | The <a>zipWith4</a> function takes a function which combines four
--   elements, as well as four lists and returns a list of their point-wise
--   combination, analogous to <a>zipWith</a>. It is capable of list
--   fusion, but it is restricted to its first list argument and its
--   resulting list.
zipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]

-- | The <a>zipWith5</a> function takes a function which combines five
--   elements, as well as five lists and returns a list of their point-wise
--   combination, analogous to <a>zipWith</a>. It is capable of list
--   fusion, but it is restricted to its first list argument and its
--   resulting list.
zipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f]

-- | The <a>zipWith6</a> function takes a function which combines six
--   elements, as well as six lists and returns a list of their point-wise
--   combination, analogous to <a>zipWith</a>. It is capable of list
--   fusion, but it is restricted to its first list argument and its
--   resulting list.
zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]

-- | The <a>zipWith7</a> function takes a function which combines seven
--   elements, as well as seven lists and returns a list of their
--   point-wise combination, analogous to <a>zipWith</a>. It is capable of
--   list fusion, but it is restricted to its first list argument and its
--   resulting list.
zipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]

-- | The <a>unzip4</a> function takes a list of quadruples and returns four
--   lists, analogous to <a>unzip</a>.
unzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d])

-- | The <a>unzip5</a> function takes a list of five-tuples and returns
--   five lists, analogous to <a>unzip</a>.
unzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e])

-- | The <a>unzip6</a> function takes a list of six-tuples and returns six
--   lists, analogous to <a>unzip</a>.
unzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f])

-- | The <a>unzip7</a> function takes a list of seven-tuples and returns
--   seven lists, analogous to <a>unzip</a>.
unzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g])

-- | The <a>deleteFirstsBy</a> function takes a predicate and two lists and
--   returns the first list with the first occurrence of each element of
--   the second list removed. This is the non-overloaded version of
--   <a>(\\)</a>.
--   
--   The second list must be finite, but the first may be infinite.
deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]

-- | The <a>inits</a> function returns all initial segments of the
--   argument, shortest first. For example,
--   
--   <pre>
--   &gt;&gt;&gt; inits "abc"
--   ["","a","ab","abc"]
--   </pre>
--   
--   Note that <a>inits</a> has the following strictness property:
--   <tt>inits (xs ++ _|_) = inits xs ++ _|_</tt>
--   
--   In particular, <tt>inits _|_ = [] : _|_</tt>
--   
--   <a>inits</a> is semantically equivalent to <tt><a>map</a>
--   <a>reverse</a> . <a>scanl</a> (<a>flip</a> (:)) []</tt>, but under the
--   hood uses a queue to amortize costs of <a>reverse</a>.
inits :: [a] -> [[a]]

-- | &lt;math&gt;. The <a>tails</a> function returns all final segments of
--   the argument, longest first. For example,
--   
--   <pre>
--   &gt;&gt;&gt; tails "abc"
--   ["abc","bc","c",""]
--   </pre>
--   
--   Note that <a>tails</a> has the following strictness property:
--   <tt>tails _|_ = _|_ : _|_</tt>
tails :: [a] -> [[a]]

-- | The <a>subsequences</a> function returns the list of all subsequences
--   of the argument.
--   
--   <pre>
--   &gt;&gt;&gt; subsequences "abc"
--   ["","a","b","ab","c","ac","bc","abc"]
--   </pre>
--   
--   This function is productive on infinite inputs:
--   
--   <pre>
--   &gt;&gt;&gt; take 8 $ subsequences ['a'..]
--   ["","a","b","ab","c","ac","bc","abc"]
--   </pre>
subsequences :: [a] -> [[a]]

-- | The <a>permutations</a> function returns the list of all permutations
--   of the argument.
--   
--   <pre>
--   &gt;&gt;&gt; permutations "abc"
--   ["abc","bac","cba","bca","cab","acb"]
--   </pre>
--   
--   The <a>permutations</a> function is maximally lazy: for each
--   <tt>n</tt>, the value of <tt><a>permutations</a> xs</tt> starts with
--   those permutations that permute <tt><a>take</a> n xs</tt> and keep
--   <tt><a>drop</a> n xs</tt>.
--   
--   This function is productive on infinite inputs:
--   
--   <pre>
--   &gt;&gt;&gt; take 6 $ map (take 3) $ permutations ['a'..]
--   ["abc","bac","cba","bca","cab","acb"]
--   </pre>
--   
--   Note that the order of permutations is not lexicographic. It satisfies
--   the following property:
--   
--   <pre>
--   map (take n) (take (product [1..n]) (permutations ([1..n] ++ undefined))) == permutations [1..n]
--   </pre>
permutations :: [a] -> [[a]]

-- | Produce singleton list.
--   
--   <pre>
--   &gt;&gt;&gt; singleton True
--   [True]
--   </pre>
singleton :: a -> [a]

-- | Splits the argument into a list of <i>lines</i> stripped of their
--   terminating <tt>\n</tt> characters. The <tt>\n</tt> terminator is
--   optional in a final non-empty line of the argument string.
--   
--   For example:
--   
--   <pre>
--   &gt;&gt;&gt; lines ""           -- empty input contains no lines
--   []
--   
--   &gt;&gt;&gt; lines "\n"         -- single empty line
--   [""]
--   
--   &gt;&gt;&gt; lines "one"        -- single unterminated line
--   ["one"]
--   
--   &gt;&gt;&gt; lines "one\n"      -- single non-empty line
--   ["one"]
--   
--   &gt;&gt;&gt; lines "one\n\n"    -- second line is empty
--   ["one",""]
--   
--   &gt;&gt;&gt; lines "one\ntwo"   -- second line is unterminated
--   ["one","two"]
--   
--   &gt;&gt;&gt; lines "one\ntwo\n" -- two non-empty lines
--   ["one","two"]
--   </pre>
--   
--   When the argument string is empty, or ends in a <tt>\n</tt> character,
--   it can be recovered by passing the result of <a>lines</a> to the
--   <a>unlines</a> function. Otherwise, <a>unlines</a> appends the missing
--   terminating <tt>\n</tt>. This makes <tt>unlines . lines</tt>
--   <i>idempotent</i>:
--   
--   <pre>
--   (unlines . lines) . (unlines . lines) = (unlines . lines)
--   </pre>
lines :: String -> [String]

-- | Appends a <tt>\n</tt> character to each input string, then
--   concatenates the results. Equivalent to <tt><tt>foldMap</tt> (s -&gt;
--   s <a>++</a> "\n")</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; unlines ["Hello", "World", "!"]
--   "Hello\nWorld\n!\n"
--   </pre>
--   
--   Note that <tt><a>unlines</a> <a>.</a> <a>lines</a> <a>/=</a>
--   <a>id</a></tt> when the input is not <tt>\n</tt>-terminated:
--   
--   <pre>
--   &gt;&gt;&gt; unlines . lines $ "foo\nbar"
--   "foo\nbar\n"
--   </pre>
unlines :: [String] -> String

-- | <a>words</a> breaks a string up into a list of words, which were
--   delimited by white space (as defined by <a>isSpace</a>). This function
--   trims any white spaces at the beginning and at the end.
--   
--   <pre>
--   &gt;&gt;&gt; words "Lorem ipsum\ndolor"
--   ["Lorem","ipsum","dolor"]
--   
--   &gt;&gt;&gt; words " foo bar "
--   ["foo","bar"]
--   </pre>
words :: String -> [String]

-- | <a>unwords</a> joins words with separating spaces (U+0020 SPACE).
--   
--   <pre>
--   &gt;&gt;&gt; unwords ["Lorem", "ipsum", "dolor"]
--   "Lorem ipsum dolor"
--   </pre>
--   
--   <a>unwords</a> is neither left nor right inverse of <a>words</a>:
--   
--   <pre>
--   &gt;&gt;&gt; words (unwords [" "])
--   []
--   
--   &gt;&gt;&gt; unwords (words "foo\nbar")
--   "foo bar"
--   </pre>
unwords :: [String] -> String

-- | The <a>isSubsequenceOf</a> function takes two lists and returns
--   <a>True</a> if all the elements of the first list occur, in order, in
--   the second. The elements do not have to occur consecutively.
--   
--   <tt><a>isSubsequenceOf</a> x y</tt> is equivalent to <tt><a>elem</a> x
--   (<a>subsequences</a> y)</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; isSubsequenceOf "GHC" "The Glorious Haskell Compiler"
--   True
--   
--   &gt;&gt;&gt; isSubsequenceOf ['a','d'..'z'] ['a'..'z']
--   True
--   
--   &gt;&gt;&gt; isSubsequenceOf [1..10] [10,9..0]
--   False
--   </pre>
--   
--   For the result to be <a>True</a>, the first list must be finite; for
--   the result to be <a>False</a>, the second list must be finite:
--   
--   <pre>
--   &gt;&gt;&gt; [0,2..10] `isSubsequenceOf` [0..]
--   True
--   
--   &gt;&gt;&gt; [0..] `isSubsequenceOf` [0,2..10]
--   False
--   
--   &gt;&gt;&gt; [0,2..] `isSubsequenceOf` [0..]
--   * Hangs forever*
--   </pre>
isSubsequenceOf :: Eq a => [a] -> [a] -> Bool

-- | &lt;math&gt;. Decompose a list into <a>init</a> and <a>last</a>.
--   
--   <ul>
--   <li>If the list is empty, returns <a>Nothing</a>.</li>
--   <li>If the list is non-empty, returns <tt><a>Just</a> (xs, x)</tt>,
--   where <tt>xs</tt> is the <a>init</a>ial part of the list and
--   <tt>x</tt> is its <a>last</a> element.</li>
--   </ul>
--   
--   <i>Since: 4.19.0.0</i>
--   
--   <pre>
--   &gt;&gt;&gt; unsnoc []
--   Nothing
--   
--   &gt;&gt;&gt; unsnoc [1]
--   Just ([],1)
--   
--   &gt;&gt;&gt; unsnoc [1, 2, 3]
--   Just ([1,2],3)
--   </pre>
--   
--   Laziness:
--   
--   <pre>
--   &gt;&gt;&gt; fst &lt;$&gt; unsnoc [undefined]
--   Just []
--   
--   &gt;&gt;&gt; head . fst &lt;$&gt; unsnoc (1 : undefined)
--   Just *** Exception: Prelude.undefined
--   
--   &gt;&gt;&gt; head . fst &lt;$&gt; unsnoc (1 : 2 : undefined)
--   Just 1
--   </pre>
--   
--   <a>unsnoc</a> is dual to <a>uncons</a>: for a finite list <tt>xs</tt>
--   
--   <pre>
--   unsnoc xs = (\(hd, tl) -&gt; (reverse tl, hd)) &lt;$&gt; uncons (reverse xs)
--   </pre>
unsnoc :: [a] -> Maybe ([a], a)

-- | The class of semigroups (types with an associative binary operation).
--   
--   Instances should satisfy the following:
--   
--   <ul>
--   <li><i>Associativity</i> <tt>x <a>&lt;&gt;</a> (y <a>&lt;&gt;</a> z) =
--   (x <a>&lt;&gt;</a> y) <a>&lt;&gt;</a> z</tt></li>
--   </ul>
--   
--   You can alternatively define <a>sconcat</a> instead of
--   (<a>&lt;&gt;</a>), in which case the laws are:
--   
--   <ul>
--   <li><i>Unit</i> <tt><a>sconcat</a> (<a>pure</a> x) = x</tt></li>
--   <li><i>Multiplication</i> <tt><a>sconcat</a> (<a>join</a> xss) =
--   <a>sconcat</a> (<a>fmap</a> <a>sconcat</a> xss)</tt></li>
--   </ul>
class () => Semigroup a

-- | An associative operation.
--   
--   <h4><b>Examples</b></h4>
--   
--   <pre>
--   &gt;&gt;&gt; [1,2,3] &lt;&gt; [4,5,6]
--   [1,2,3,4,5,6]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; Just [1, 2, 3] &lt;&gt; Just [4, 5, 6]
--   Just [1,2,3,4,5,6]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; putStr "Hello, " &lt;&gt; putStrLn "World!"
--   Hello, World!
--   </pre>
(<>) :: Semigroup a => a -> a -> a
infixr 6 <>

-- | If the first argument evaluates to <a>True</a>, then the result is the
--   second argument. Otherwise an <a>AssertionFailed</a> exception is
--   raised, containing a <a>String</a> with the source file and line
--   number of the call to <a>assert</a>.
--   
--   Assertions can normally be turned on or off with a compiler flag (for
--   GHC, assertions are normally on unless optimisation is turned on with
--   <tt>-O</tt> or the <tt>-fignore-asserts</tt> option is given). When
--   assertions are turned off, the first argument to <a>assert</a> is
--   ignored, and the second argument is returned as the result.
assert :: Bool -> a -> a

-- | If the condition fails, display the value blamed for the failure. Used
--   as in
--   
--   <pre>
--   assert (age &lt; 120 `blame` age) $ savings / (120 - age)
--   </pre>
blame :: Show v => Bool -> v -> Bool
infix 1 `blame`

-- | A helper function for <a>error</a>. To be used as in
--   
--   <pre>
--   case xs of
--     0 : _ -&gt; error $ "insignificant zero" `showFailure` xs
--   </pre>
--   
--   Fixing the first argument to <tt>String</tt> instead of anything
--   Showable prevents warnings about defaulting, even when
--   <tt>OverloadedStrings</tt> extension is enabled.
showFailure :: Show v => String -> v -> String
infix 2 `showFailure`

-- | Syntactic sugar for the pair operation, to be used for <a>blame</a> as
--   in
--   
--   <pre>
--   assert (age &lt; 120 `blame` "age too high" `swith` age) $ savings / (120 - age)
--   </pre>
--   
--   Fixing the first component of the pair to <tt>String</tt> prevents
--   warnings about defaulting, even when <tt>OverloadedStrings</tt>
--   extension is enabled.
swith :: String -> v -> (String, v)
infix 2 `swith`

-- | Like <a>all</a>, but if the predicate fails, blame all the list
--   elements and especially those for which it fails. To be used as in
--   
--   <pre>
--   assert (allB (&lt;= height) [yf, y1, y2])
--   </pre>
allB :: Show v => (v -> Bool) -> [v] -> Bool

-- | A space efficient, packed, unboxed Unicode text type.
data () => Text
(<+>) :: Text -> Text -> Text

-- | Show and pack the result.
tshow :: Show a => a -> Text

-- | Integer division, rounding up.
divUp :: Integral a => a -> a -> a
infixl 7 `divUp`
sum :: Num a => [a] -> a
(<$$>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
infixl 4 <$$>
partitionM :: Applicative m => (a -> m Bool) -> [a] -> m ([a], [a])

-- | A version specialized to lists to avoid errors such as taking length
--   of <tt>Maybe [a]</tt> instead of <tt>[a]</tt>. Such errors are hard to
--   detect, because the type of elements of the list is not constrained.
length :: [a] -> Int

-- | A version specialized to lists to avoid errors such as taking null of
--   <tt>Maybe [a]</tt> instead of <tt>[a]</tt>. Such errors are hard to
--   detect, because the type of elements of the list is not constrained.
null :: [a] -> Bool

-- | <pre>
--   comparing p x y = compare (p x) (p y)
--   </pre>
--   
--   Useful combinator for use in conjunction with the <tt>xxxBy</tt>
--   family of functions from <a>Data.List</a>, for example:
--   
--   <pre>
--   ... sortBy (comparing fst) ...
--   </pre>
comparing :: Ord a => (b -> a) -> b -> b -> Ordering

-- | This is the same as <a>from</a> except that the type variables are in
--   the opposite order.
--   
--   <pre>
--   -- Avoid this:
--   from x :: t
--   
--   -- Prefer this:
--   into @t x
--   </pre>
into :: forall target source. From source target => source -> target

-- | Re-exported <a>fromIntegral</a>, but please give it explicit type to
--   make it obvious if wrapping, etc., may occur. Use
--   <a>toIntegralCrash</a> instead, if possible, because it fails instead
--   of wrapping, etc. In general, it may wrap or otherwise lose
--   information.
fromIntegralWrap :: (Integral a, Num b) => a -> b

-- | Re-exported <a>toIntegralSized</a>, but please give it explicit type
--   to make it obvious if wrapping, etc., may occur and to trigger
--   optimization. In general, it may crash.
toIntegralCrash :: (Integral a, Integral b, Bits a, Bits b) => a -> b
intToDouble :: Int -> Double
int64ToDouble :: Int64 -> Double

-- | This has a more specific type (unit result) than normally, to catch
--   errors.
mapM_ :: (Foldable t, Monad m) => (a -> m ()) -> t a -> m ()

-- | This has a more specific type (unit result) than normally, to catch
--   errors.
forM_ :: (Foldable t, Monad m) => t a -> (a -> m ()) -> m ()
vectorUnboxedUnsafeIndex :: Unbox a => Vector a -> Int -> a
unsafeShiftL :: Bits a => a -> Int -> a
unsafeShiftR :: Bits a => a -> Int -> a

-- | Split the input between the two argument arrows and combine their
--   output. Note that this is in general not a functor.
--   
--   The default definition may be overridden with a more efficient version
--   if desired.
(***) :: Arrow a => a b c -> a b' c' -> a (b, b') (c, c')
infixr 3 ***

-- | Fanout: send the input to both argument arrows and combine their
--   output.
--   
--   The default definition may be overridden with a more efficient version
--   if desired.
(&&&) :: Arrow a => a b c -> a b c' -> a b (c, c')
infixr 3 &&&

-- | Send the first component of the input through the argument arrow, and
--   copy the rest unchanged to the output.
first :: Arrow a => a b c -> a (b, d) (c, d)

-- | A mirror image of <a>first</a>.
--   
--   The default definition may be overridden with a more efficient version
--   if desired.
second :: Arrow a => a b c -> a (d, b) (d, c)
instance (GHC.Enum.Enum k, Data.Binary.Class.Binary k, Data.Binary.Class.Binary e) => Data.Binary.Class.Binary (Data.EnumMap.Base.EnumMap k e)
instance (GHC.Enum.Enum k, Data.Binary.Class.Binary k) => Data.Binary.Class.Binary (Data.EnumSet.EnumSet k)
instance Data.Binary.Class.Binary Data.Time.Clock.Internal.NominalDiffTime.NominalDiffTime
instance (Data.Hashable.Class.Hashable k, GHC.Classes.Eq k, Data.Binary.Class.Binary k, Data.Binary.Class.Binary v) => Data.Binary.Class.Binary (Data.HashMap.Internal.HashMap k v)
instance Data.Key.Zip (Data.EnumMap.Base.EnumMap k)
instance GHC.Enum.Enum k => Data.Key.ZipWithKey (Data.EnumMap.Base.EnumMap k)
instance GHC.Enum.Enum k => Data.Key.Keyed (Data.EnumMap.Base.EnumMap k)
instance GHC.Enum.Enum k => Data.Key.FoldableWithKey (Data.EnumMap.Base.EnumMap k)
instance GHC.Enum.Enum k => Data.Key.TraversableWithKey (Data.EnumMap.Base.EnumMap k)
instance GHC.Enum.Enum k => Data.Key.Indexable (Data.EnumMap.Base.EnumMap k)
instance GHC.Enum.Enum k => Data.Key.Lookup (Data.EnumMap.Base.EnumMap k)
instance GHC.Enum.Enum k => Data.Key.Adjustable (Data.EnumMap.Base.EnumMap k)
instance (GHC.Enum.Enum k, Data.Hashable.Class.Hashable k, Data.Hashable.Class.Hashable e) => Data.Hashable.Class.Hashable (Data.EnumMap.Base.EnumMap k e)
instance (GHC.Enum.Enum k, Data.Hashable.Class.Hashable k) => Data.Hashable.Class.Hashable (Data.EnumSet.EnumSet k)
instance Control.DeepSeq.NFData NLP.Miniutter.English.Part
instance Control.DeepSeq.NFData NLP.Miniutter.English.Person
instance Control.DeepSeq.NFData NLP.Miniutter.English.Polarity


-- | A list of entities with relative frequencies of appearance.
module Game.LambdaHack.Core.Frequency

-- | The frequency distribution type. Not normalized (operations may or may
--   not group the same elements and sum their frequencies). However,
--   elements with less than zero frequency are removed upon construction.
--   
--   The <tt>Eq</tt> instance compares raw representations, not relative,
--   normalized frequencies, so operations don't need to preserve the
--   expected equalities.
data Frequency a

-- | Uniform discrete frequency distribution.
uniformFreq :: Text -> [a] -> Frequency a

-- | Takes a name and a list of frequencies and items into the frequency
--   distribution.
toFreq :: Text -> [(Int, a)] -> Frequency a
maxBoundInt32 :: Int

-- | Scale frequency distribution, multiplying it by a positive integer
--   constant.
scaleFreq :: Show a => Int -> Frequency a -> Frequency a

-- | Test if the frequency distribution is empty.
nullFreq :: Frequency a -> Bool

-- | give acces to raw frequency values
runFrequency :: Frequency a -> [(Int, a)]

-- | short description for debug, etc.
nameFrequency :: Frequency a -> Text
instance GHC.Generics.Generic (Game.LambdaHack.Core.Frequency.Frequency a)
instance Data.Traversable.Traversable Game.LambdaHack.Core.Frequency.Frequency
instance Data.Foldable.Foldable Game.LambdaHack.Core.Frequency.Frequency
instance GHC.Classes.Ord a => GHC.Classes.Ord (Game.LambdaHack.Core.Frequency.Frequency a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Game.LambdaHack.Core.Frequency.Frequency a)
instance GHC.Show.Show a => GHC.Show.Show (Game.LambdaHack.Core.Frequency.Frequency a)
instance GHC.Base.Monad Game.LambdaHack.Core.Frequency.Frequency
instance GHC.Base.Functor Game.LambdaHack.Core.Frequency.Frequency
instance GHC.Base.Applicative Game.LambdaHack.Core.Frequency.Frequency
instance GHC.Base.MonadPlus Game.LambdaHack.Core.Frequency.Frequency
instance GHC.Base.Alternative Game.LambdaHack.Core.Frequency.Frequency


-- | Representation of dice scaled with current level depth.
module Game.LambdaHack.Core.Dice

-- | Multiple dice rolls, some scaled with current level depth, in which
--   case the sum of all rolls is scaled in proportion to current depth
--   divided by maximal dungeon depth.
--   
--   The simple dice should have positive number of rolls and number of
--   sides.
--   
--   The <tt>Num</tt> instance doesn't have <tt>abs</tt> nor
--   <tt>signum</tt> defined, because the functions for computing infimum,
--   supremum and mean dice results would be too costly.
data Dice

-- | Absolute depth in the dungeon. When used for the maximum depth of the
--   whole dungeon, this can be different than dungeon size, e.g., when the
--   dungeon is branched, and it can even be different than the length of
--   the longest branch, if levels at some depths are missing.
newtype AbsDepth
AbsDepth :: Int -> AbsDepth

-- | Cast dice scaled with current level depth. When scaling, we round up,
--   so that the value of <tt>1 <a>dL</a> 1</tt> is <tt>1</tt> even at the
--   lowest level, but so is the value of <tt>1 <a>dL</a> depth</tt>.
--   
--   The implementation calls RNG as many times as there are dice rolls,
--   which is costly, so content should prefer to cast fewer dice and then
--   multiply them by a constant. If rounded results are not desired (often
--   they are, to limit the number of distinct item varieties in
--   inventory), another dice may be added to the result.
--   
--   A different possible implementation, with dice represented as
--   <tt>Frequency</tt>, makes only one RNG call per dice, but due to lists
--   lengths proportional to the maximal value of the dice, it's is
--   intractable for 1000d1000 and problematic already for 100d100.
castDice :: forall m. Monad m => ((Int, Int) -> m Int) -> AbsDepth -> AbsDepth -> Dice -> m Int

-- | A die, rolled the given number of times. E.g., <tt>1 <a>d</a> 2</tt>
--   rolls 2-sided die one time.
d :: Int -> Int -> Dice

-- | A die rolled the given number of times, with the result scaled with
--   dungeon level depth.
dL :: Int -> Int -> Dice

-- | A die, starting from zero, ending at one less than second argument,
--   rolled the given number of times. E.g., <tt>1 <a>z</a> 1</tt> always
--   rolls zero.
z :: Int -> Int -> Dice

-- | A die, starting from zero, ending at one less than second argument,
--   rolled the given number of times, with the result scaled with dungeon
--   level depth.
zL :: Int -> Int -> Dice
intToDice :: Int -> Dice
minDice :: Dice -> Dice -> Dice
maxDice :: Dice -> Dice -> Dice

-- | Minimal and maximal possible value of the dice.
--   
--   <tt>divUp</tt> in the implementation corresponds to <tt>ceiling</tt>,
--   applied to results of <tt>meanDice</tt> elsewhere in the code, and
--   prevents treating 1d1-power effects (on shallow levels) as null
--   effects.
infsupDice :: Dice -> (Int, Int)

-- | Maximal value of dice. The scaled part taken assuming median level.
supDice :: Dice -> Int

-- | Minimal value of dice. The scaled part taken assuming median level.
infDice :: Dice -> Int

-- | Mean value of dice. The scaled part taken assuming median level, but
--   not taking into account rounding up, and so too low, especially for
--   dice small compared to depth. To fix this, depth would need to be
--   taken as argument.
meanDice :: Dice -> Double
reduceDice :: Dice -> Maybe Int

-- | Dice for rolling a pair of integer parameters pertaining to,
--   respectively, the X and Y cartesian 2D coordinates.
data DiceXY
DiceXY :: Dice -> Dice -> DiceXY

-- | Maximal value of DiceXY.
supDiceXY :: DiceXY -> (Int, Int)

-- | Minimal value of DiceXY.
infDiceXY :: DiceXY -> (Int, Int)
instance GHC.Classes.Eq Game.LambdaHack.Core.Dice.Dice
instance Data.Binary.Class.Binary Game.LambdaHack.Core.Dice.AbsDepth
instance GHC.Classes.Ord Game.LambdaHack.Core.Dice.AbsDepth
instance GHC.Classes.Eq Game.LambdaHack.Core.Dice.AbsDepth
instance GHC.Show.Show Game.LambdaHack.Core.Dice.AbsDepth
instance GHC.Show.Show Game.LambdaHack.Core.Dice.DiceXY
instance GHC.Show.Show Game.LambdaHack.Core.Dice.Dice
instance GHC.Num.Num Game.LambdaHack.Core.Dice.Dice


-- | Keeping track of forked threads.
module Game.LambdaHack.Common.Thread
forkChild :: MVar [Async ()] -> IO () -> IO ()
waitForChildren :: MVar [Async ()] -> IO ()


-- | Ring buffers.
module Game.LambdaHack.Common.RingBuffer

-- | Ring buffers of a size determined at initialization.
data RingBuffer a
empty :: Int -> a -> RingBuffer a
cons :: a -> RingBuffer a -> RingBuffer a
toList :: RingBuffer a -> [a]
length :: RingBuffer a -> Int
instance GHC.Generics.Generic (Game.LambdaHack.Common.RingBuffer.RingBuffer a)
instance GHC.Show.Show a => GHC.Show.Show (Game.LambdaHack.Common.RingBuffer.RingBuffer a)
instance Data.Binary.Class.Binary a => Data.Binary.Class.Binary (Game.LambdaHack.Common.RingBuffer.RingBuffer a)


-- | Hacks that haven't found their home yet.
module Game.LambdaHack.Common.Misc
data FontDefinition

-- | filename, size, hinting mode
FontProportional :: Text -> Int -> HintingMode -> FontDefinition
FontMonospace :: Text -> Int -> HintingMode -> FontDefinition

-- | extra cell extension
FontMapScalable :: Text -> Int -> HintingMode -> Int -> FontDefinition

-- | size ignored for bitmap fonts and no hinting
FontMapBitmap :: Text -> Int -> FontDefinition
data HintingMode

-- | current libfreetype6 default, thin, large letter spacing
HintingHeavy :: HintingMode

-- | mimics OTF, blurry, thick, tight tracking, accurate shape
HintingLight :: HintingMode
data FontSet
FontSet :: Text -> Text -> Text -> Text -> Text -> FontSet
[fontMapScalable] :: FontSet -> Text
[fontMapBitmap] :: FontSet -> Text
[fontPropRegular] :: FontSet -> Text
[fontPropBold] :: FontSet -> Text
[fontMono] :: FontSet -> Text

-- | Re-exported English phrase creation functions, applied to our custom
--   irregular word sets.
makePhrase :: [Part] -> Text

-- | Re-exported English phrase creation functions, applied to our custom
--   irregular word sets.
makeSentence :: [Part] -> Text

-- | Apply the <tt>WWandW</tt> constructor, first representing repetitions
--   as <tt>CardinalWs</tt>. The parts are not sorted, only grouped, to
--   keep the order. The internal structure of speech parts is compared,
--   not their string rendering, so some coincidental clashes are avoided
--   (and code is simpler).
squashedWWandW :: [Part] -> (Part, Person)

-- | Personal data directory for the game. Depends on the OS and the game,
--   e.g., for LambdaHack under Linux it's <tt>~/.LambdaHack/</tt>.
appDataDir :: IO FilePath

-- | Multiplies by a million.
xM :: Int -> Int64

-- | Multiplies by a million, double precision.
xD :: Double -> Double
minusM :: Int64
minusM1 :: Int64
minusM2 :: Int64
oneM :: Int64
tenthM :: Int64
show64With2 :: Int64 -> Text
workaroundOnMainThreadMVar :: MVar (IO ())
instance GHC.Generics.Generic Game.LambdaHack.Common.Misc.HintingMode
instance GHC.Read.Read Game.LambdaHack.Common.Misc.HintingMode
instance GHC.Classes.Eq Game.LambdaHack.Common.Misc.HintingMode
instance GHC.Show.Show Game.LambdaHack.Common.Misc.HintingMode
instance GHC.Generics.Generic Game.LambdaHack.Common.Misc.FontDefinition
instance GHC.Read.Read Game.LambdaHack.Common.Misc.FontDefinition
instance GHC.Classes.Eq Game.LambdaHack.Common.Misc.FontDefinition
instance GHC.Show.Show Game.LambdaHack.Common.Misc.FontDefinition
instance GHC.Generics.Generic Game.LambdaHack.Common.Misc.FontSet
instance GHC.Read.Read Game.LambdaHack.Common.Misc.FontSet
instance GHC.Classes.Eq Game.LambdaHack.Common.Misc.FontSet
instance GHC.Show.Show Game.LambdaHack.Common.Misc.FontSet
instance Control.DeepSeq.NFData Game.LambdaHack.Common.Misc.FontSet
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Misc.FontSet
instance Control.DeepSeq.NFData Game.LambdaHack.Common.Misc.FontDefinition
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Misc.FontDefinition
instance Control.DeepSeq.NFData Game.LambdaHack.Common.Misc.HintingMode
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Misc.HintingMode


-- | Game time and speed.
module Game.LambdaHack.Common.Time

-- | Game time in ticks. The time dimension. One tick is 1 microsecond (one
--   millionth of a second), one turn is 0.5 s.
data Time
timeTicks :: Time -> Int64

-- | Start of the game time, or zero lenght time interval.
timeZero :: Time

-- | An infinitesimal time period.
timeEpsilon :: Time

-- | At least once per clip all moves are resolved and a frame or a frame
--   delay is generated. Currently one clip is 0.05 s, but it may change,
--   and the code should not depend on this fixed value.
timeClip :: Time

-- | One turn is 0.5 s. The code may depend on that. Actors at normal speed
--   (2 m/s) take one turn to move one tile (1 m by 1 m).
timeTurn :: Time

-- | This many ticks fits in a single second.
timeSecond :: Time

-- | This many clips fit in one turn. Determines the resolution of actor
--   move sampling and display updates.
clipsInTurn :: Int

-- | Absolute time addition, e.g., for summing the total game session time
--   from the times of individual games.
absoluteTimeAdd :: Time -> Time -> Time
absoluteTimeSubtract :: Time -> Time -> Time

-- | Absolute time negation. To be used for reversing time flow, e.g., for
--   comparing absolute times in the reverse order.
absoluteTimeNegate :: Time -> Time

-- | How many time intervals of the latter kind fits in an interval of the
--   former kind.
timeFit :: Time -> Time -> Int

-- | How many time intervals of the latter kind cover an interval of the
--   former kind (rounded up).
timeFitUp :: Time -> Time -> Int
timeRecent5 :: Time -> Time -> Bool

-- | One-dimentional vectors. Introduced to tell apart the 2 uses of Time:
--   as an absolute game time and as an increment.
newtype Delta a
Delta :: a -> Delta a

-- | Shifting an absolute time by a time vector.
timeShift :: Time -> Delta Time -> Time

-- | Time time vector between the second and the first absolute times. The
--   arguments are in the same order as in the underlying scalar
--   subtraction.
timeDeltaToFrom :: Time -> Time -> Delta Time

-- | Addition of time deltas.
timeDeltaAdd :: Delta Time -> Delta Time -> Delta Time

-- | Subtraction of time deltas. The arguments are in the same order as in
--   the underlying scalar subtraction.
timeDeltaSubtract :: Delta Time -> Delta Time -> Delta Time

-- | Reverse a time vector.
timeDeltaReverse :: Delta Time -> Delta Time

-- | Scale the time vector by an <tt>Int</tt> scalar value.
timeDeltaScale :: Delta Time -> Int -> Delta Time

-- | Take the given percent of the time vector.
timeDeltaPercent :: Delta Time -> Int -> Delta Time

-- | Divide a time vector.
timeDeltaDiv :: Delta Time -> Int -> Delta Time

-- | Represent the main 10 thresholds of a time range by digits, given the
--   total length of the time range.
timeDeltaToDigit :: Delta Time -> Delta Time -> Char
timeDeltaInSecondsText :: Delta Time -> Text

-- | Speed in meters per 1 million seconds (m/Ms). Actors at normal speed
--   (2 m/s) take one time turn (0.5 s) to make one step (move one tile,
--   which is 1 m by 1 m).
data Speed

-- | Constructor for content definitions.
toSpeed :: Int -> Speed

-- | Readable representation of speed in the format used in content
--   definitions.
fromSpeed :: Speed -> Int
minSpeed :: Int

-- | Pretty-print speed given in the format used in content definitions.
displaySpeed :: Int -> String

-- | Fast walk speed (2 m/s) that suffices to move one tile in one turn.
speedWalk :: Speed

-- | Limp speed (1 m/s) that suffices to move one tile in two turns. This
--   is the minimal speed for projectiles to fly just one space and drop.
speedLimp :: Speed

-- | Sword thrust speed (10 m/s). Base weapon damages, both melee and
--   ranged, are given assuming this speed and ranged damage is modified
--   accordingly when projectile speeds differ. Differences in melee weapon
--   swing speeds are captured in damage bonuses instead, since many other
--   factors influence total damage.
--   
--   Billiard ball is 25 m<i>s, sword swing at the tip is 35 m</i>s,
--   medieval bow is 70 m<i>s, AK47 is 700 m</i>s.
speedThrust :: Speed

-- | Modify damage when projectiles is at a non-standard speed. Energy and
--   so damage is proportional to the square of speed, hence the formula.
modifyDamageBySpeed :: Int64 -> Speed -> Int64

-- | Scale speed by a scalar value.
speedScale :: Rational -> Speed -> Speed

-- | Speed addition.
speedAdd :: Speed -> Speed -> Speed

-- | The number of time ticks it takes to walk 1 meter at the given speed.
ticksPerMeter :: Speed -> Delta Time

-- | Calculate projectile speed from item weight in grams and velocity
--   percent modifier. See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Item-statistics</a>.
speedFromWeight :: Int -> Int -> Speed

-- | Calculate maximum range taking into account the linger percentage.
rangeFromSpeedAndLinger :: Speed -> Int -> Int

-- | The smallest unit of time. Should not be exported and used elsewhere,
--   because the proportion of turn to tick is an implementation detail.
--   The significance of this detail is only that it determines resolution
--   of the time dimension.
_timeTick :: Time

-- | This many turns fit in a single second.
turnsInSecond :: Int64

-- | Number of seconds in a mega-second.
sInMs :: Int64

-- | The minimal speed is half a meter (half a step across a tile) per
--   second (two standard turns, which the time span during which
--   projectile moves, unless it has modified linger value). This is four
--   times slower than standard human movement speed.
--   
--   It needen't be lower, because <tt>rangeFromSpeed</tt> gives 0 steps
--   with such speed, so the actor's trajectory is empty, so it drops down
--   at once. Twice that speed already moves a normal projectile one step
--   before it stops. It shouldn't be lower or a slow actor would incur
--   such a time debt for performing a single action that he'd be paralyzed
--   for many turns, e.g., leaving his dead body on the screen for very
--   long.
minimalSpeed :: Int64

-- | Calculate maximum range in meters of a projectile from its speed. See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Item-statistics</a>.
--   With this formula, each projectile flies for at most 1 second, that is
--   2 standard turns, and then drops to the ground.
rangeFromSpeed :: Speed -> Int
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Time.Time
instance GHC.Classes.Ord Game.LambdaHack.Common.Time.Time
instance GHC.Classes.Eq Game.LambdaHack.Common.Time.Time
instance GHC.Show.Show Game.LambdaHack.Common.Time.Time
instance GHC.Base.Functor Game.LambdaHack.Common.Time.Delta
instance Data.Binary.Class.Binary a => Data.Binary.Class.Binary (Game.LambdaHack.Common.Time.Delta a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Game.LambdaHack.Common.Time.Delta a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Game.LambdaHack.Common.Time.Delta a)
instance GHC.Show.Show a => GHC.Show.Show (Game.LambdaHack.Common.Time.Delta a)
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Time.Speed
instance GHC.Classes.Ord Game.LambdaHack.Common.Time.Speed
instance GHC.Classes.Eq Game.LambdaHack.Common.Time.Speed
instance GHC.Show.Show Game.LambdaHack.Common.Time.Speed


-- | Saving/loading to files, with serialization and compression.
module Game.LambdaHack.Common.File

-- | Serialize, compress and save data with an EOF marker. The <tt>OK</tt>
--   is used as an EOF marker to ensure any apparent problems with
--   corrupted files are reported to the user ASAP.
encodeEOF :: Binary b => FilePath -> Version -> b -> IO ()

-- | Read, decompress and deserialize data with an EOF marker. The
--   <tt>OK</tt> EOF marker ensures any easily detectable file corruption
--   is discovered and reported before any value is decoded from the second
--   component and before the file handle is closed. OTOH, binary encoding
--   corruption is not discovered until a version check elswere ensures
--   that binary formats are compatible.
strictDecodeEOF :: Binary b => FilePath -> IO (Version, b)

-- | Try to create a directory, if it doesn't exist. We catch exceptions in
--   case many clients try to do the same thing at the same time.
tryCreateDir :: FilePath -> IO ()

-- | The operation <a>doesFileExist</a> returns <a>True</a> if the argument
--   file exists and is not a directory, and <a>False</a> otherwise.
doesFileExist :: FilePath -> IO Bool

-- | Try to write a file, given content, if the file not already there. We
--   catch exceptions in case many clients and/or the server try to do the
--   same thing at the same time. Using <a>IO</a> to avoid UTF conflicts
--   with OS or filesystem.
tryWriteFile :: FilePath -> Text -> IO ()

-- | The <a>readFile</a> function reads a file and returns the contents of
--   the file as a string. The file is read lazily, on demand, as with
--   <a>getContents</a>.
readFile :: FilePath -> IO String

-- | <tt><a>renameFile</a> old new</tt> changes the name of an existing
--   file system object from <i>old</i> to <i>new</i>. If the <i>new</i>
--   object already exists, it is replaced by the <i>old</i> object.
--   Neither path may refer to an existing directory.
--   
--   A conformant implementation need not support renaming files in all
--   situations (e.g. renaming across different physical devices), but the
--   constraints must be documented. On Windows, this does not support
--   renaming across different physical devices; if you are looking to do
--   so, consider using <a>copyFileWithMetadata</a> and <a>removeFile</a>.
--   
--   On Windows, this calls <tt>MoveFileEx</tt> with
--   <tt>MOVEFILE_REPLACE_EXISTING</tt> set, which is not guaranteed to be
--   atomic (<a>https://github.com/haskell/directory/issues/109</a>).
--   
--   On other platforms, this operation is atomic.
--   
--   The operation may fail with:
--   
--   <ul>
--   <li><tt>HardwareFault</tt> A physical I/O error has occurred.
--   <tt>[EIO]</tt></li>
--   <li><tt>InvalidArgument</tt> Either operand is not a valid file name.
--   <tt>[ENAMETOOLONG, ELOOP]</tt></li>
--   <li><a>isDoesNotExistError</a> The original file does not exist, or
--   there is no path to the target. <tt>[ENOENT, ENOTDIR]</tt></li>
--   <li><a>isPermissionError</a> The process has insufficient privileges
--   to perform the operation. <tt>[EROFS, EACCES, EPERM]</tt></li>
--   <li><a>isFullError</a> Insufficient resources are available to perform
--   the operation. <tt>[EDQUOT, ENOSPC, ENOMEM, EMLINK]</tt></li>
--   <li><tt>UnsatisfiedConstraints</tt> Implementation-dependent
--   constraints are not satisfied. <tt>[EBUSY]</tt></li>
--   <li><tt>UnsupportedOperation</tt> The implementation does not support
--   renaming in this situation. <tt>[EXDEV]</tt></li>
--   <li><tt>InappropriateType</tt> Either path refers to an existing
--   directory. <tt>[ENOTDIR, EISDIR, EINVAL, EEXIST, ENOTEMPTY]</tt></li>
--   </ul>
renameFile :: FilePath -> FilePath -> IO ()


-- | Options that affect the behaviour of the client.
module Game.LambdaHack.Common.ClientOptions

-- | Kinds of fullscreen or windowed mode. See
--   <a>https://hackage.haskell.org/package/sdl2-2.5.3.0/docs/SDL-Video.html#t:WindowMode</a>.
data FullscreenMode

-- | a normal window instead of fullscreen
NotFullscreen :: FullscreenMode

-- | fake fullscreen; window the size of the desktop; this is the preferred
--   one, if it works
BigBorderlessWindow :: FullscreenMode

-- | real fullscreen with a video mode change
ModeChange :: FullscreenMode

-- | Options that affect the behaviour of the client (but not game rules).
data ClientOptions
ClientOptions :: Maybe Text -> Maybe Double -> [(Text, FontDefinition)] -> [(Text, FontSet)] -> Maybe FullscreenMode -> Maybe Int -> Maybe Double -> Bool -> Maybe Bool -> Bool -> Bool -> Bool -> Maybe String -> String -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe Int -> Maybe Int -> Bool -> Bool -> Bool -> Bool -> ClientOptions

-- | Font set chosen by the player for the whole UI.
[schosenFontset] :: ClientOptions -> Maybe Text

-- | The scale applied to all fonts, resizing the whole UI.
[sallFontsScale] :: ClientOptions -> Maybe Double

-- | Available fonts as defined in config file.
[sfonts] :: ClientOptions -> [(Text, FontDefinition)]

-- | Available font sets as defined in config file.
[sfontsets] :: ClientOptions -> [(Text, FontSet)]

-- | Whether to start in fullscreen mode and in which one.
[sfullscreenMode] :: ClientOptions -> Maybe FullscreenMode

-- | How much to log (e.g., from SDL). 1 is all, 5 is errors, the default.
[slogPriority] :: ClientOptions -> Maybe Int

-- | Maximal frames per second. This is better low and fixed, to avoid
--   jerkiness and delays that tell the player there are many intelligent
--   enemies on the level. That's better than scaling AI sofistication down
--   based on the FPS setting and machine speed.
[smaxFps] :: ClientOptions -> Maybe Double

-- | Never auto-answer all prompts, even if under AI control.
[sdisableAutoYes] :: ClientOptions -> Bool

-- | Don't show any animations.
[snoAnim] :: ClientOptions -> Maybe Bool

-- | Start a new game, overwriting the save file.
[snewGameCli] :: ClientOptions -> Bool

-- | Don't create directories and files and show time stats.
[sbenchmark] :: ClientOptions -> Bool

-- | Display messages in realistic was under AI control (e.g., for
--   benchmarking).
[sbenchMessages] :: ClientOptions -> Bool
[stitle] :: ClientOptions -> Maybe String

-- | Prefix of the save game file name.
[ssavePrefixCli] :: ClientOptions -> String

-- | Whether to use the ANSI frontend.
[sfrontendANSI] :: ClientOptions -> Bool

-- | Whether to use the stdout/stdin frontend.
[sfrontendTeletype] :: ClientOptions -> Bool

-- | Whether to use null (no input/output) frontend.
[sfrontendNull] :: ClientOptions -> Bool

-- | Whether to use lazy (output not even calculated) frontend.
[sfrontendLazy] :: ClientOptions -> Bool

-- | Show clients' internal debug messages.
[sdbgMsgCli] :: ClientOptions -> Bool
[sstopAfterSeconds] :: ClientOptions -> Maybe Int
[sstopAfterFrames] :: ClientOptions -> Maybe Int
[sprintEachScreen] :: ClientOptions -> Bool
[sexposePlaces] :: ClientOptions -> Bool
[sexposeItems] :: ClientOptions -> Bool
[sexposeActors] :: ClientOptions -> Bool

-- | Default value of client options.
defClientOptions :: ClientOptions
instance GHC.Generics.Generic Game.LambdaHack.Common.ClientOptions.FullscreenMode
instance GHC.Classes.Eq Game.LambdaHack.Common.ClientOptions.FullscreenMode
instance GHC.Read.Read Game.LambdaHack.Common.ClientOptions.FullscreenMode
instance GHC.Show.Show Game.LambdaHack.Common.ClientOptions.FullscreenMode
instance GHC.Generics.Generic Game.LambdaHack.Common.ClientOptions.ClientOptions
instance GHC.Classes.Eq Game.LambdaHack.Common.ClientOptions.ClientOptions
instance GHC.Show.Show Game.LambdaHack.Common.ClientOptions.ClientOptions
instance Data.Binary.Class.Binary Game.LambdaHack.Common.ClientOptions.ClientOptions
instance Control.DeepSeq.NFData Game.LambdaHack.Common.ClientOptions.FullscreenMode
instance Data.Binary.Class.Binary Game.LambdaHack.Common.ClientOptions.FullscreenMode

module Game.LambdaHack.Client.UI.TutorialHints
data TutorialHints
DamageOfDifferentKind :: TutorialHints
NewFloorNewOpportunity :: TutorialHints
CannotHarmYouInMelee :: TutorialHints
CaughtProjectile :: TutorialHints
HitsWithNoDirectDamage :: TutorialHints
TemporaryConditions :: TutorialHints
WokenUpActors :: TutorialHints
AvoidWalkingEnemies :: TutorialHints
AlotOfDamageFromOneSource :: TutorialHints
TerrainNotFullyKnown :: TutorialHints
OutOfSightEvents :: TutorialHints
HearingRadius :: TutorialHints
SwitchTeammate :: TutorialHints
MeleeEnemies :: TutorialHints
UseTerrainEffect :: TutorialHints
SwitchPointmanAndAvoidMeleeAlone :: TutorialHints
SwitchPointmanAndSoftenFoes :: TutorialHints

-- | Generate the standard textual representation for the tutorial hints.
renderTutorialHints :: TutorialHints -> Text


-- | AI strategies to direct actors not controlled directly by human
--   players. No operation in this module involves the <tt>State</tt> type
--   or any of our client/server monads types.
module Game.LambdaHack.Client.AI.Strategy

-- | A strategy is a choice of (non-empty) frequency tables of possible
--   actions.
--   
--   Currently, the way we use it, the list could have at most one element
--   (we filter out void frequencies early and only ever access the first).
--   except for the argument of <tt>mapStrategyM</tt>, which may even be
--   process to the end of the list, if no earlier strategies can be
--   transformed into non-null ones.
data Strategy a
nullStrategy :: Strategy a -> Bool

-- | Strategy where only the actions from the given single frequency table
--   can be picked.
liftFrequency :: Frequency a -> Strategy a

-- | Strategy with the actions from both argument strategies, with original
--   frequencies.
(.|) :: Strategy a -> Strategy a -> Strategy a
infixr 2 .|

-- | Strategy with no actions at all.
reject :: Strategy a

-- | Conditionally accepted strategy.
(.=>) :: Bool -> Strategy a -> Strategy a
infix 3 .=>

-- | Strategy with all actions not satisfying the predicate removed. The
--   remaining actions keep their original relative frequency values.
only :: (a -> Bool) -> Strategy a -> Strategy a

-- | When better choices are towards the start of the list, this is the
--   best frequency of the strategy.
bestVariant :: Strategy a -> Frequency a

-- | Like <a>return</a>, but pick a name of the single frequency.
returN :: Text -> a -> Strategy a
mapStrategyM :: Monad m => (a -> m (Maybe b)) -> Strategy a -> m (Strategy b)
instance Data.Traversable.Traversable Game.LambdaHack.Client.AI.Strategy.Strategy
instance Data.Foldable.Foldable Game.LambdaHack.Client.AI.Strategy.Strategy
instance GHC.Show.Show a => GHC.Show.Show (Game.LambdaHack.Client.AI.Strategy.Strategy a)
instance GHC.Base.Monad Game.LambdaHack.Client.AI.Strategy.Strategy
instance GHC.Base.Functor Game.LambdaHack.Client.AI.Strategy.Strategy
instance GHC.Base.Applicative Game.LambdaHack.Client.AI.Strategy.Strategy
instance GHC.Base.MonadPlus Game.LambdaHack.Client.AI.Strategy.Strategy
instance GHC.Base.Alternative Game.LambdaHack.Client.AI.Strategy.Strategy


-- | Representation of probabilities and random computations.
module Game.LambdaHack.Core.Random

-- | The monad of computations with random generator state.
type Rnd a = State SMGen a

-- | Get a random object within a (inclusive) range with a uniform
--   distribution.
randomR :: Integral a => (a, a) -> Rnd a

-- | Generate random <a>Integral</a> in <tt>[0, x]</tt> range.
randomR0 :: Integral a => a -> Rnd a

-- | Generate a random integral value in <tt>[0, x]</tt> range, where
--   <tt>x</tt> is within <tt>Int32</tt>.
--   
--   The limitation to <tt>Int32</tt> values is needed to keep it working
--   on signed types. In package <tt>random</tt>, a much more complex
--   scheme is used to keep it working for arbitrary fixed number of bits.
nextRandom :: forall a. Integral a => a -> SMGen -> (a, SMGen)

-- | Get a random <a>Word32</a> using full range.
randomWord32 :: Rnd Word32

-- | Get any element of a list with equal probability.
oneOf :: [a] -> Rnd a

-- | Generates a random permutation. Naive, but good enough for small
--   inputs.
shuffle :: Eq a => [a] -> Rnd [a]

-- | Code that means the information (e.g., flavour or hidden kind index)
--   should be regenerated, because it could not be transferred from
--   previous playthrough (it's random in each playthrough or there was no
--   previous playthrough).
invalidInformationCode :: Word16

-- | Generates a random permutation, except for the existing mapping.
shuffleExcept :: Vector Word16 -> Int -> [Word16] -> Rnd [Word16]

-- | Gen an element according to a frequency distribution.
frequency :: Show a => Frequency a -> Rnd a

-- | Fractional chance.
type Chance = Rational

-- | Give <tt>True</tt>, with probability determined by the fraction.
chance :: Chance -> Rnd Bool

-- | Cast dice scaled with current level depth.
castDice :: AbsDepth -> AbsDepth -> Dice -> Rnd Int

-- | Cast dice scaled with current level depth and return <tt>True</tt> if
--   the results is greater than 50.
oddsDice :: AbsDepth -> AbsDepth -> Dice -> Rnd Bool

-- | Cast dice, scaled with current level depth, for coordinates.
castDiceXY :: AbsDepth -> AbsDepth -> DiceXY -> Rnd (Int, Int)
foldrM :: Foldable t => (a -> b -> Rnd b) -> b -> t a -> Rnd b
foldlM' :: Foldable t => (b -> a -> Rnd b) -> b -> t a -> Rnd b

-- | Randomly choose an item according to the distribution.
rollFreq :: Show a => Frequency a -> SMGen -> (a, SMGen)


-- | Abilities of items, actors and factions.
module Game.LambdaHack.Definition.Ability

-- | Actor and faction skills. They are a subset of actor aspects. See
--   <a>skillDesc</a> for documentation.
data Skill
SkMove :: Skill
SkMelee :: Skill
SkDisplace :: Skill
SkAlter :: Skill
SkWait :: Skill
SkMoveItem :: Skill
SkProject :: Skill
SkApply :: Skill
SkSwimming :: Skill
SkFlying :: Skill
SkHurtMelee :: Skill
SkArmorMelee :: Skill
SkArmorRanged :: Skill
SkMaxHP :: Skill
SkMaxCalm :: Skill
SkSpeed :: Skill

-- | FOV radius, where 1 means a single tile FOV area
SkSight :: Skill
SkSmell :: Skill
SkShine :: Skill
SkNocto :: Skill
SkHearing :: Skill
SkAggression :: Skill
SkOdor :: Skill

-- | intended to reflect how many items granting complete invulnerability
--   are among organs and equipment; this is not strength of deflection nor
--   duration, etc.
SkDeflectRanged :: Skill

-- | see above
SkDeflectMelee :: Skill

-- | Strength of particular skills. This is cumulative from actor organs
--   and equipment and so pertain to an actor as well as to items.
--   
--   This representation is sparse, so better than a record when there are
--   more item kinds (with few skills) than actors (with many skills),
--   especially if the number of skills grows as the engine is developed.
--   It's also easier to code and maintain.
--   
--   The tree is by construction sparse, so the derived equality is
--   semantical.
data Skills

-- | Item flag aspects.
data Flag

-- | as a projectile, break at target tile, even if no hit; also, at each
--   periodic activation a copy is destroyed and all other copies require
--   full cooldown (timeout)
Fragile :: Flag

-- | drop at target tile, even if no hit
Lobable :: Flag

-- | don't break even when hitting or applying
Durable :: Flag

-- | AI and UI flag: consider equipping (may or may not have
--   <a>EqpSlot</a>, e.g., if the benefit is periodic)
Equipable :: Flag

-- | AI and UI flag: the item is not meant to harm
Benign :: Flag

-- | AI and UI flag: don't risk identifying by use; also, can't throw or
--   apply if not calm enough; also may be used for UI flavour or AI hints
Precious :: Flag

-- | the item is an explosion blast particle
Blast :: Flag

-- | item is a condition (buff or de-buff) of an actor and is displayed as
--   such, not activated at death; this differs from belonging to the
--   <tt>CONDITION</tt> group, which doesn't guarantee any behaviour or
--   display, but governs removal by items that drop <tt>CONDITION</tt>
Condition :: Flag

-- | at most one copy can ever be generated
Unique :: Flag

-- | once identified, the item is known until savefile deleted
MetaGame :: Flag

-- | override: the effects on this item are considered minor and so
--   possibly not causing identification on use, and so this item will
--   identify on pick-up
MinorEffects :: Flag

-- | override: don't show question marks by weapons in HUD even when
--   unidentified item with this flag equipped
MinorAspects :: Flag

-- | meleeing with the item is permitted and so the item activates when
--   meleed with
Meleeable :: Flag

-- | at most one of any copies without cooldown (timeout) activates each
--   turn; the cooldown required after activation is specified in
--   <tt>Timeout</tt> (or is zero); the initial cooldown can also be
--   specified as <tt>TimerDice</tt> in <tt>CreateItem</tt> effect;
--   uniquely, this activation never destroys a copy, unless item is
--   fragile; all this happens only for items in equipment or organs;
--   kinetic damage is not applied
Periodic :: Flag

-- | activates when non-projectile actor with this item as equipment or
--   organ is under ranged attack; kinetic damage is not applied
UnderRanged :: Flag

-- | activates when non-projectile actor with this item as equipment or
--   organ is under melee attack; kinetic damage is not applied
UnderMelee :: Flag

-- | These flags correspond to the last cases of <tt>Flag</tt> and
--   addtionally to all the universal circumstances of item activation,
--   under which every item activates (even if vacuusly).
data ActivationFlag
ActivationMeleeable :: ActivationFlag
ActivationPeriodic :: ActivationFlag
ActivationUnderRanged :: ActivationFlag
ActivationUnderMelee :: ActivationFlag

-- | From here on, all items affected regardless of their <a>Flag</a>
--   content.
ActivationProjectile :: ActivationFlag
ActivationTrigger :: ActivationFlag
ActivationOnSmash :: ActivationFlag
ActivationOnCombine :: ActivationFlag
ActivationEmbed :: ActivationFlag
ActivationConsume :: ActivationFlag
newtype Flags
Flags :: EnumSet Flag -> Flags
[flags] :: Flags -> EnumSet Flag

-- | Doctrine of non-leader actors. Apart of determining AI operation, each
--   doctrine implies a skill modifier, that is added to the non-leader
--   skills defined in <tt>fskillsOther</tt> field of <tt>FactionKind</tt>.
data Doctrine

-- | if enemy nearby, attack, if no items, etc., explore unknown
TExplore :: Doctrine

-- | always follow leader's target or his position if no target
TFollow :: Doctrine

-- | follow but don't do any item management nor use
TFollowNoItems :: Doctrine

-- | only melee and do ranged combat
TMeleeAndRanged :: Doctrine

-- | only melee (or wait)
TMeleeAdjacent :: Doctrine

-- | always only wait, even if enemy in melee range
TBlock :: Doctrine

-- | if enemy nearby, attack, if no items, etc., roam randomly
TRoam :: Doctrine

-- | find an open and uncrowded area, patrol it according to sight radius
--   and fallback temporarily to <tt>TRoam</tt> when enemy is seen by the
--   faction and is within the actor's sight radius
TPatrol :: Doctrine

-- | AI and UI hints about the role of the item.
data EqpSlot
EqpSlotMove :: EqpSlot
EqpSlotMelee :: EqpSlot
EqpSlotDisplace :: EqpSlot
EqpSlotAlter :: EqpSlot
EqpSlotWait :: EqpSlot
EqpSlotMoveItem :: EqpSlot
EqpSlotProject :: EqpSlot
EqpSlotApply :: EqpSlot
EqpSlotSwimming :: EqpSlot
EqpSlotFlying :: EqpSlot
EqpSlotHurtMelee :: EqpSlot
EqpSlotArmorMelee :: EqpSlot
EqpSlotArmorRanged :: EqpSlot
EqpSlotMaxHP :: EqpSlot
EqpSlotSpeed :: EqpSlot
EqpSlotSight :: EqpSlot
EqpSlotShine :: EqpSlot
EqpSlotMiscBonus :: EqpSlot
EqpSlotWeaponFast :: EqpSlot
EqpSlotWeaponBig :: EqpSlot
getSk :: Skill -> Skills -> Int
addSk :: Skill -> Int -> Skills -> Skills
checkFl :: Flag -> Flags -> Bool
skillsToList :: Skills -> [(Skill, Int)]
zeroSkills :: Skills
addSkills :: Skills -> Skills -> Skills
sumScaledSkills :: [(Skills, Int)] -> Skills
nameDoctrine :: Doctrine -> Text
describeDoctrine :: Doctrine -> Text
doctrineSkills :: Doctrine -> Skills
blockOnly :: Skills
meleeAdjacent :: Skills
meleeAndRanged :: Skills
ignoreItems :: Skills
scaleSkills :: (Skills, Int) -> Skills
instance GHC.Generics.Generic Game.LambdaHack.Definition.Ability.Skill
instance GHC.Enum.Bounded Game.LambdaHack.Definition.Ability.Skill
instance GHC.Enum.Enum Game.LambdaHack.Definition.Ability.Skill
instance GHC.Classes.Eq Game.LambdaHack.Definition.Ability.Skill
instance GHC.Show.Show Game.LambdaHack.Definition.Ability.Skill
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Ability.Skills
instance Data.Hashable.Class.Hashable Game.LambdaHack.Definition.Ability.Skills
instance GHC.Classes.Ord Game.LambdaHack.Definition.Ability.Skills
instance GHC.Classes.Eq Game.LambdaHack.Definition.Ability.Skills
instance GHC.Show.Show Game.LambdaHack.Definition.Ability.Skills
instance GHC.Generics.Generic Game.LambdaHack.Definition.Ability.Flag
instance GHC.Enum.Bounded Game.LambdaHack.Definition.Ability.Flag
instance GHC.Enum.Enum Game.LambdaHack.Definition.Ability.Flag
instance GHC.Classes.Eq Game.LambdaHack.Definition.Ability.Flag
instance GHC.Show.Show Game.LambdaHack.Definition.Ability.Flag
instance GHC.Classes.Eq Game.LambdaHack.Definition.Ability.ActivationFlag
instance GHC.Show.Show Game.LambdaHack.Definition.Ability.ActivationFlag
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Ability.Flags
instance Data.Hashable.Class.Hashable Game.LambdaHack.Definition.Ability.Flags
instance GHC.Classes.Ord Game.LambdaHack.Definition.Ability.Flags
instance GHC.Classes.Eq Game.LambdaHack.Definition.Ability.Flags
instance GHC.Show.Show Game.LambdaHack.Definition.Ability.Flags
instance GHC.Generics.Generic Game.LambdaHack.Definition.Ability.Doctrine
instance GHC.Enum.Bounded Game.LambdaHack.Definition.Ability.Doctrine
instance GHC.Enum.Enum Game.LambdaHack.Definition.Ability.Doctrine
instance GHC.Classes.Eq Game.LambdaHack.Definition.Ability.Doctrine
instance GHC.Show.Show Game.LambdaHack.Definition.Ability.Doctrine
instance GHC.Generics.Generic Game.LambdaHack.Definition.Ability.EqpSlot
instance GHC.Enum.Bounded Game.LambdaHack.Definition.Ability.EqpSlot
instance GHC.Enum.Enum Game.LambdaHack.Definition.Ability.EqpSlot
instance GHC.Classes.Ord Game.LambdaHack.Definition.Ability.EqpSlot
instance GHC.Classes.Eq Game.LambdaHack.Definition.Ability.EqpSlot
instance GHC.Show.Show Game.LambdaHack.Definition.Ability.EqpSlot
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Ability.EqpSlot
instance Data.Hashable.Class.Hashable Game.LambdaHack.Definition.Ability.EqpSlot
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Ability.Doctrine
instance Data.Hashable.Class.Hashable Game.LambdaHack.Definition.Ability.Doctrine
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Ability.Flag
instance Data.Hashable.Class.Hashable Game.LambdaHack.Definition.Ability.Flag
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Ability.Skill
instance Data.Hashable.Class.Hashable Game.LambdaHack.Definition.Ability.Skill


-- | Colours and text attributes.
module Game.LambdaHack.Definition.Color

-- | Colours supported by the major frontends.
data Color
Black :: Color
Red :: Color
Green :: Color
Brown :: Color
Blue :: Color
Magenta :: Color
Cyan :: Color
White :: Color
AltWhite :: Color
BrBlack :: Color
BrRed :: Color
BrGreen :: Color
BrYellow :: Color
BrBlue :: Color
BrMagenta :: Color
BrCyan :: Color
BrWhite :: Color

-- | The default colours, to optimize attribute setting.
defFG :: Color

-- | A helper for the terminal frontends that display bright via bold.
isBright :: Color -> Bool

-- | Colour sets. Sorted.
darkCol :: [Color]

-- | Colour sets. Sorted.
brightCol :: [Color]

-- | Colour sets. Sorted.
stdCol :: [Color]

-- | Colour sets. Sorted.
legalFgCol :: [Color]
cVeryBadEvent :: Color
cBadEvent :: Color
cRisk :: Color
cGraveRisk :: Color
cVeryGoodEvent :: Color
cGoodEvent :: Color
cVista :: Color
cSleep :: Color
cWakeUp :: Color
cGreed :: Color
cNeutralEvent :: Color
cRareNeutralEvent :: Color
cIdentification :: Color
cMeta :: Color
cBoring :: Color
cGameOver :: Color
cTutorialHint :: Color

-- | Translationg to heavily modified Linux console color RGB values.
--   
--   Warning: SDL frontend sadly duplicates this code.
colorToRGB :: Color -> Text

-- | Additional map cell highlight, e.g., a colorful square around the cell
--   or a colorful background.
--   
--   Warning: the highlight underscored by the terminal cursor is the
--   maximal element of this type present on a screen, so don't add new
--   highlights to the end.
data Highlight
HighlightNone :: Highlight
HighlightBackground :: Highlight
HighlightGreen :: Highlight
HighlightBlue :: Highlight
HighlightBrown :: Highlight
HighlightCyan :: Highlight
HighlightGrey :: Highlight
HighlightWhite :: Highlight
HighlightMagenta :: Highlight
HighlightRed :: Highlight
HighlightYellow :: Highlight
HighlightYellowAim :: Highlight
HighlightRedAim :: Highlight
HighlightNoneCursor :: Highlight

-- | Text attributes: foreground color and highlight.
data Attr
Attr :: Color -> Highlight -> Attr

-- | foreground colour
[fg] :: Attr -> Color

-- | highlight
[bg] :: Attr -> Highlight
highlightToColor :: Highlight -> Color

-- | The default attribute, to optimize attribute setting.
defAttr :: Attr

-- | Character to display, with its attribute.
data AttrChar
AttrChar :: Attr -> Char -> AttrChar
[acAttr] :: AttrChar -> Attr
[acChar] :: AttrChar -> Char

-- | Optimized representation of <a>AttrChar</a>.
newtype AttrCharW32
AttrCharW32 :: Word32 -> AttrCharW32
[attrCharW32] :: AttrCharW32 -> Word32
attrCharToW32 :: AttrChar -> AttrCharW32
attrCharFromW32 :: AttrCharW32 -> AttrChar
fgFromW32 :: AttrCharW32 -> Color
bgFromW32 :: AttrCharW32 -> Highlight
charFromW32 :: AttrCharW32 -> Char
attrFromW32 :: AttrCharW32 -> Attr
spaceAttrW32 :: AttrCharW32
nbspAttrW32 :: AttrCharW32
trimmedLineAttrW32 :: AttrCharW32
attrChar2ToW32 :: Color -> Char -> AttrCharW32
attrChar1ToW32 :: Char -> AttrCharW32
instance GHC.Generics.Generic Game.LambdaHack.Definition.Color.Color
instance GHC.Enum.Enum Game.LambdaHack.Definition.Color.Color
instance GHC.Classes.Ord Game.LambdaHack.Definition.Color.Color
instance GHC.Classes.Eq Game.LambdaHack.Definition.Color.Color
instance GHC.Read.Read Game.LambdaHack.Definition.Color.Color
instance GHC.Show.Show Game.LambdaHack.Definition.Color.Color
instance GHC.Enum.Bounded Game.LambdaHack.Definition.Color.Highlight
instance GHC.Enum.Enum Game.LambdaHack.Definition.Color.Highlight
instance GHC.Classes.Ord Game.LambdaHack.Definition.Color.Highlight
instance GHC.Classes.Eq Game.LambdaHack.Definition.Color.Highlight
instance GHC.Show.Show Game.LambdaHack.Definition.Color.Highlight
instance GHC.Classes.Eq Game.LambdaHack.Definition.Color.Attr
instance GHC.Show.Show Game.LambdaHack.Definition.Color.Attr
instance GHC.Classes.Eq Game.LambdaHack.Definition.Color.AttrChar
instance GHC.Show.Show Game.LambdaHack.Definition.Color.AttrChar
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Color.AttrCharW32
instance GHC.Enum.Enum Game.LambdaHack.Definition.Color.AttrCharW32
instance GHC.Classes.Ord Game.LambdaHack.Definition.Color.AttrCharW32
instance GHC.Classes.Eq Game.LambdaHack.Definition.Color.AttrCharW32
instance GHC.Show.Show Game.LambdaHack.Definition.Color.AttrCharW32
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Color.Color
instance Control.DeepSeq.NFData Game.LambdaHack.Definition.Color.Color


-- | Very basic types for content definitions with their internals exposed.
module Game.LambdaHack.Definition.DefsInternal
newtype GroupName c
GroupName :: Text -> GroupName c
[fromGroupName] :: GroupName c -> Text

-- | This does not need to be 1-1, so should not be used in place of the
--   <a>Eq</a> instance, etc.
displayGroupName :: GroupName c -> Text

-- | Content identifiers for the content type <tt>c</tt>.
data ContentId c
toContentId :: Word16 -> ContentId c
fromContentId :: ContentId c -> Word16
contentIdIndex :: ContentId c -> Int
type ContentSymbol c = Char
toContentSymbol :: Char -> ContentSymbol c
displayContentSymbol :: ContentSymbol c -> Char
instance Control.DeepSeq.NFData (Game.LambdaHack.Definition.DefsInternal.GroupName c)
instance Data.Binary.Class.Binary (Game.LambdaHack.Definition.DefsInternal.GroupName c)
instance Data.Hashable.Class.Hashable (Game.LambdaHack.Definition.DefsInternal.GroupName c)
instance GHC.Classes.Ord (Game.LambdaHack.Definition.DefsInternal.GroupName c)
instance GHC.Classes.Eq (Game.LambdaHack.Definition.DefsInternal.GroupName c)
instance GHC.Show.Show (Game.LambdaHack.Definition.DefsInternal.GroupName c)
instance Data.Binary.Class.Binary (Game.LambdaHack.Definition.DefsInternal.ContentId c)
instance Data.Hashable.Class.Hashable (Game.LambdaHack.Definition.DefsInternal.ContentId c)
instance GHC.Enum.Enum (Game.LambdaHack.Definition.DefsInternal.ContentId c)
instance GHC.Classes.Ord (Game.LambdaHack.Definition.DefsInternal.ContentId c)
instance GHC.Classes.Eq (Game.LambdaHack.Definition.DefsInternal.ContentId c)
instance GHC.Show.Show (Game.LambdaHack.Definition.DefsInternal.ContentId c)


-- | Basic types for content definitions.
module Game.LambdaHack.Definition.Defs
data GroupName c

-- | This does not need to be 1-1, so should not be used in place of the
--   <a>Eq</a> instance, etc.
displayGroupName :: GroupName c -> Text

-- | Content identifiers for the content type <tt>c</tt>.
data ContentId c
contentIdIndex :: ContentId c -> Int
type ContentSymbol c = Char
displayContentSymbol :: ContentSymbol c -> Char

-- | X spacial dimension for points and vectors.
type X = Int

-- | Y xpacial dimension for points and vectors.
type Y = Int

-- | For each group that the kind belongs to, denoted by a
--   <tt>GroupName</tt> in the first component of a pair, the second
--   component of a pair shows how common the kind is within the group.
type Freqs c = [(GroupName c, Int)]
renameFreqs :: (Text -> Text) -> Freqs c -> Freqs c

-- | Rarity on given depths. The first element of the pair is normally in
--   (0, 10] interval and, e.g., if there are 20 levels, 0.5 represents the
--   first level and 10 the last. Exceptionally, it may be larger than 10,
--   meaning appearance in the dungeon is not possible under normal
--   circumstances and the value remains constant above the interval bound.
type Rarity = [(Double, Int)]
linearInterpolation :: Int -> Int -> Rarity -> Int

-- | Actor's item stores.
data CStore
CGround :: CStore
COrgan :: CStore
CEqp :: CStore
CStash :: CStore
ppCStore :: CStore -> (Text, Text)
ppCStoreIn :: CStore -> Text
verbCStore :: CStore -> Text

-- | Item slot and lore categories.
data SLore
SItem :: SLore
SOrgan :: SLore
STrunk :: SLore
SCondition :: SLore
SBlast :: SLore
SEmbed :: SLore
SBody :: SLore
data ItemDialogMode

-- | a leader's store
MStore :: CStore -> ItemDialogMode

-- | all party's items
MOwned :: ItemDialogMode

-- | not items, but determined by leader's items
MSkills :: ItemDialogMode

-- | not party's items, but all known generalized items
MLore :: SLore -> ItemDialogMode

-- | places; not items at all, but definitely a lore
MPlaces :: ItemDialogMode

-- | factions in this game, with some data from previous
MFactions :: ItemDialogMode

-- | scenarios; not items at all, but definitely a lore
MModes :: ItemDialogMode
ppSLore :: SLore -> Text
headingSLore :: SLore -> Text
ppItemDialogMode :: ItemDialogMode -> (Text, Text)
ppItemDialogModeIn :: ItemDialogMode -> Text
ppItemDialogModeFrom :: ItemDialogMode -> Text
loreFromMode :: ItemDialogMode -> SLore
data Direction
Forward :: Direction
Backward :: Direction
instance GHC.Generics.Generic Game.LambdaHack.Definition.Defs.CStore
instance GHC.Enum.Bounded Game.LambdaHack.Definition.Defs.CStore
instance GHC.Enum.Enum Game.LambdaHack.Definition.Defs.CStore
instance GHC.Classes.Ord Game.LambdaHack.Definition.Defs.CStore
instance GHC.Classes.Eq Game.LambdaHack.Definition.Defs.CStore
instance GHC.Read.Read Game.LambdaHack.Definition.Defs.CStore
instance GHC.Show.Show Game.LambdaHack.Definition.Defs.CStore
instance GHC.Generics.Generic Game.LambdaHack.Definition.Defs.SLore
instance GHC.Enum.Bounded Game.LambdaHack.Definition.Defs.SLore
instance GHC.Enum.Enum Game.LambdaHack.Definition.Defs.SLore
instance GHC.Classes.Ord Game.LambdaHack.Definition.Defs.SLore
instance GHC.Classes.Eq Game.LambdaHack.Definition.Defs.SLore
instance GHC.Read.Read Game.LambdaHack.Definition.Defs.SLore
instance GHC.Show.Show Game.LambdaHack.Definition.Defs.SLore
instance GHC.Generics.Generic Game.LambdaHack.Definition.Defs.ItemDialogMode
instance GHC.Classes.Ord Game.LambdaHack.Definition.Defs.ItemDialogMode
instance GHC.Classes.Eq Game.LambdaHack.Definition.Defs.ItemDialogMode
instance GHC.Read.Read Game.LambdaHack.Definition.Defs.ItemDialogMode
instance GHC.Show.Show Game.LambdaHack.Definition.Defs.ItemDialogMode
instance GHC.Generics.Generic Game.LambdaHack.Definition.Defs.Direction
instance GHC.Classes.Ord Game.LambdaHack.Definition.Defs.Direction
instance GHC.Classes.Eq Game.LambdaHack.Definition.Defs.Direction
instance GHC.Read.Read Game.LambdaHack.Definition.Defs.Direction
instance GHC.Show.Show Game.LambdaHack.Definition.Defs.Direction
instance Control.DeepSeq.NFData Game.LambdaHack.Definition.Defs.Direction
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Defs.Direction
instance Control.DeepSeq.NFData Game.LambdaHack.Definition.Defs.ItemDialogMode
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Defs.ItemDialogMode
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Defs.SLore
instance Control.DeepSeq.NFData Game.LambdaHack.Definition.Defs.SLore
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Defs.CStore
instance Control.DeepSeq.NFData Game.LambdaHack.Definition.Defs.CStore


-- | Basic operations on 2D points represented as linear offsets.
module Game.LambdaHack.Common.Point

-- | 2D points in cartesian representation. Coordinates grow to the right
--   and down, so that the (0, 0) point is in the top-left corner of the
--   screen. Coordinates are never negative (unlike for <a>Vector</a>) and
--   the <tt>X</tt> coordinate never reaches the screen width as read from
--   <a>speedupHackXSize</a>.
data Point
Point :: X -> Y -> Point
[px] :: Point -> X
[py] :: Point -> Y

-- | Enumeration representation of <tt>Point</tt>.
type PointI = Int

-- | The distance between two points in the chessboard metric.
--   
--   <pre>
--   &gt;&gt;&gt; chessDist (Point 0 0) (Point 0 0)
--   0
--   
--   &gt;&gt;&gt; chessDist (Point (-1) 0) (Point 0 0)
--   1
--   
--   &gt;&gt;&gt; chessDist (Point (-1) 0) (Point (-1) 1)
--   1
--   
--   &gt;&gt;&gt; chessDist (Point (-1) 0) (Point 0 1)
--   1
--   
--   &gt;&gt;&gt; chessDist (Point (-1) 0) (Point 1 1)
--   2
--   </pre>
--   
--   <pre>
--   chessDist p1 p2 &gt;= 0
--   </pre>
--   
--   <pre>
--   chessDist p1 p2 ^ (2 :: Int) &lt;= euclidDistSq p1 p2
--   </pre>
chessDist :: Point -> Point -> Int

-- | Squared euclidean distance between two points.
euclidDistSq :: Point -> Point -> Int

-- | Checks whether two points are adjacent on the map (horizontally,
--   vertically or diagonally).
adjacent :: Point -> Point -> Bool

-- | Bresenham's line algorithm generalized to arbitrary starting
--   <tt>eps</tt> (<tt>eps</tt> value of 0 gives the standard BLA). Skips
--   the source point and goes through the second point to infinity. Gives
--   <tt>Nothing</tt> if the points are equal. The target is given as
--   <tt>Point</tt>, not <tt>PointI</tt>, to permit aiming out of the
--   level, e.g., to get uniform distributions of directions for explosions
--   close to the edge of the level.
--   
--   <pre>
--   &gt;&gt;&gt; bresenhamsLineAlgorithm 0 (Point 0 0) (Point 0 0)
--   Nothing
--   
--   &gt;&gt;&gt; take 3 $ fromJust $ bresenhamsLineAlgorithm 0 (Point 0 0) (Point 1 0)
--   [(1,0),(2,0),(3,0)]
--   
--   &gt;&gt;&gt; take 3 $ fromJust $ bresenhamsLineAlgorithm 0 (Point 0 0) (Point 0 1)
--   [(0,1),(0,2),(0,3)]
--   
--   &gt;&gt;&gt; take 3 $ fromJust $ bresenhamsLineAlgorithm 0 (Point 0 0) (Point 1 1)
--   [(1,1),(2,2),(3,3)]
--   </pre>
bresenhamsLineAlgorithm :: Int -> Point -> Point -> Maybe [Point]

-- | A list of all points on a straight vertical or straight horizontal
--   line between two points. Fails if no such line exists.
--   
--   <pre>
--   &gt;&gt;&gt; fromTo (Point 0 0) (Point 2 0)
--   [(0,0),(1,0),(2,0)]
--   </pre>
fromTo :: Point -> Point -> [Point]
originPoint :: Point

-- | Checks that a point belongs to an area.
insideP :: (X, Y, X, Y) -> Point -> Bool

-- | This is a hack to pass the X size of the dungeon, defined in game
--   content, to the <tt>Enum</tt> instances of <tt>Point</tt> and
--   <tt>Vector</tt>. This is already slower and has higher allocation than
--   hardcoding the value, so passing the value explicitly to a
--   generalization of the <tt>Enum</tt> conversions is out of the
--   question. Perhaps this can be done cleanly and efficiently at
--   link-time via Backpack, but it's probably not supported yet by GHCJS
--   (not verified). For now, we need to be careful never to modify this
--   array, except for setting it at program start before it's used for the
--   first time. Which is easy, because <tt>Point</tt> is never mentioned
--   in content definitions. The <tt>PrimArray</tt> has much smaller
--   overhead than <tt>IORef</tt> and reading from it looks cleaner, hence
--   its use.
speedupHackXSize :: PrimArray X

-- | Bresenham's line algorithm generalized to arbitrary starting
--   <tt>eps</tt> (<tt>eps</tt> value of 0 gives the standard BLA).
--   Includes the source point and goes through the target point to
--   infinity.
--   
--   <pre>
--   &gt;&gt;&gt; take 4 $ bresenhamsLineAlgorithmBegin 0 (Point 0 0) (Point 2 0)
--   [(0,0),(1,0),(2,0),(3,0)]
--   </pre>
bresenhamsLineAlgorithmBegin :: Int -> Point -> Point -> [Point]

-- | See
--   <a>http://roguebasin.roguelikedevelopment.org/index.php/index.php?title=Digital_lines</a>.
balancedWord :: Int -> Int -> Int -> [Int]
instance GHC.Generics.Generic Game.LambdaHack.Common.Point.Point
instance GHC.Classes.Ord Game.LambdaHack.Common.Point.Point
instance GHC.Classes.Eq Game.LambdaHack.Common.Point.Point
instance GHC.Show.Show Game.LambdaHack.Common.Point.Point
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Point.Point
instance GHC.Enum.Enum Game.LambdaHack.Common.Point.Point
instance Test.QuickCheck.Arbitrary.Arbitrary Game.LambdaHack.Common.Point.Point


-- | Basic operations on bounded 2D vectors, with an efficient, but not 1-1
--   and not monotonic <tt>Enum</tt> instance.
module Game.LambdaHack.Common.Vector

-- | 2D vectors in cartesian representation. Coordinates grow to the right
--   and down, so that the (1, 1) vector points to the bottom-right corner
--   of the screen.
data Vector
Vector :: X -> Y -> Vector
[vx] :: Vector -> X
[vy] :: Vector -> Y

-- | Enumeration representation of <tt>Vector</tt>.
type VectorI = Int

-- | Tells if a vector has length 1 in the chessboard metric.
isUnit :: Vector -> Bool

-- | Reverse an arbirary vector.
neg :: Vector -> Vector

-- | The lenght of a vector in the chessboard metric, where diagonal moves
--   cost 1.
chessDistVector :: Vector -> Int

-- | Squared euclidean distance between two vectors.
euclidDistSqVector :: Vector -> Vector -> Int

-- | Vectors of all unit moves in the chessboard metric, clockwise,
--   starting north-west.
moves :: [Vector]

-- | Vectors of all cardinal direction unit moves, clockwise, starting
--   north.
movesCardinal :: [Vector]
movesCardinalI :: [VectorI]

-- | Vectors of all diagonal direction unit moves, clockwise, starting
--   north.
movesDiagonal :: [Vector]
movesDiagonalI :: [VectorI]
compassText :: Vector -> Text

-- | All (8 at most) closest neighbours of a point within an area.
vicinityBounded :: X -> Y -> Point -> [Point]
vicinityUnsafe :: Point -> [Point]

-- | All (4 at most) cardinal direction neighbours of a point within an
--   area.
vicinityCardinal :: X -> Y -> Point -> [Point]
vicinityCardinalUnsafe :: Point -> [Point]
squareUnsafeSet :: Point -> EnumSet Point

-- | Translate a point by a vector.
shift :: Point -> Vector -> Point

-- | Translate a point by a vector, but only if the result fits in an area.
shiftBounded :: X -> Y -> Point -> Vector -> Point

-- | A list of points that a list of vectors leads to.
trajectoryToPath :: Point -> [Vector] -> [Point]

-- | A list of points that a list of vectors leads to, bounded by level
--   size.
trajectoryToPathBounded :: X -> Y -> Point -> [Vector] -> [Point]

-- | The vector between the second point and the first. We have
--   
--   <pre>
--   shift pos1 (pos2 `vectorToFrom` pos1) == pos2
--   </pre>
--   
--   The arguments are in the same order as in the underlying scalar
--   subtraction.
vectorToFrom :: Point -> Point -> Vector
computeTrajectory :: Int -> Int -> Int -> [Point] -> ([Vector], (Speed, Int))
type RadianAngle = Double

-- | Rotate a vector by the given angle (expressed in radians)
--   counterclockwise and return a unit vector approximately in the
--   resulting direction.
rotate :: RadianAngle -> Vector -> Vector

-- | Given two distinct positions, determine the direction (a unit vector)
--   in which one should move from the first in order to get closer to the
--   second. Ignores obstacles. Of several equally good directions (in the
--   chessboard metric) it picks one of those that visually (in the
--   euclidean metric) maximally align with the vector between the two
--   points.
towards :: Point -> Point -> Vector
longMoveTexts :: [Text]
movesSquare :: [VectorI]

-- | A list of vectors between a list of points.
pathToTrajectory :: [Point] -> [Vector]

-- | Given a vector of arbitrary non-zero length, produce a unit vector
--   that points in the same direction (in the chessboard metric). Of
--   several equally good directions it picks one of those that visually
--   (in the euclidean metric) maximally align with the original vector.
normalize :: Double -> Double -> Vector
normalizeVector :: Vector -> Vector
instance GHC.Generics.Generic Game.LambdaHack.Common.Vector.Vector
instance GHC.Classes.Ord Game.LambdaHack.Common.Vector.Vector
instance GHC.Classes.Eq Game.LambdaHack.Common.Vector.Vector
instance GHC.Read.Read Game.LambdaHack.Common.Vector.Vector
instance GHC.Show.Show Game.LambdaHack.Common.Vector.Vector
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Vector.Vector
instance GHC.Enum.Enum Game.LambdaHack.Common.Vector.Vector
instance Control.DeepSeq.NFData Game.LambdaHack.Common.Vector.Vector


-- | Abstract identifiers for the main types in the engine. This is
--   imported by modules that don't need to know the internal structure of
--   the types. As a side effect, this prevents mutual dependencies among
--   modules.
module Game.LambdaHack.Common.Types

-- | A unique identifier of an item in the dungeon.
data ItemId

-- | A unique identifier of a faction in a game. It's assigned in the order
--   from game mode roster, starting from one. We keep the
--   <tt>FactionId</tt> and <tt>TeamContinuity</tt> types separate mostly
--   to let <tt>FactionId</tt> reflect the order, which influences starting
--   faction positions, etc. We use <tt>TeamContinuity</tt> for
--   dictionaries containing teams that may or may not be active factions
--   in the current game, while <tt>FactionId</tt> are used only for
--   factions in the game (in particular, because they vary depending on
--   order in game mode roster, while <tt>TeamContinuity</tt> are stable).
data FactionId

-- | Abstract level identifiers.
data LevelId

-- | A unique identifier of an actor in the dungeon.
data ActorId

-- | Item container type.
data Container
CFloor :: LevelId -> Point -> Container
CEmbed :: LevelId -> Point -> Container
CActor :: ActorId -> CStore -> Container

-- | for bootstrapping actor bodies
CTrunk :: FactionId -> LevelId -> Point -> Container
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Types.ItemId
instance GHC.Enum.Enum Game.LambdaHack.Common.Types.ItemId
instance GHC.Classes.Ord Game.LambdaHack.Common.Types.ItemId
instance GHC.Classes.Eq Game.LambdaHack.Common.Types.ItemId
instance GHC.Show.Show Game.LambdaHack.Common.Types.ItemId
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Types.FactionId
instance Data.Hashable.Class.Hashable Game.LambdaHack.Common.Types.FactionId
instance GHC.Enum.Enum Game.LambdaHack.Common.Types.FactionId
instance GHC.Classes.Ord Game.LambdaHack.Common.Types.FactionId
instance GHC.Classes.Eq Game.LambdaHack.Common.Types.FactionId
instance GHC.Show.Show Game.LambdaHack.Common.Types.FactionId
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Types.LevelId
instance Data.Hashable.Class.Hashable Game.LambdaHack.Common.Types.LevelId
instance GHC.Classes.Ord Game.LambdaHack.Common.Types.LevelId
instance GHC.Classes.Eq Game.LambdaHack.Common.Types.LevelId
instance GHC.Show.Show Game.LambdaHack.Common.Types.LevelId
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Types.ActorId
instance GHC.Enum.Enum Game.LambdaHack.Common.Types.ActorId
instance GHC.Classes.Ord Game.LambdaHack.Common.Types.ActorId
instance GHC.Classes.Eq Game.LambdaHack.Common.Types.ActorId
instance GHC.Show.Show Game.LambdaHack.Common.Types.ActorId
instance GHC.Generics.Generic Game.LambdaHack.Common.Types.Container
instance GHC.Classes.Ord Game.LambdaHack.Common.Types.Container
instance GHC.Classes.Eq Game.LambdaHack.Common.Types.Container
instance GHC.Show.Show Game.LambdaHack.Common.Types.Container
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Types.Container
instance GHC.Enum.Enum Game.LambdaHack.Common.Types.LevelId


-- | Actors perceiving other actors and the dungeon level.
--   
--   Visibility works according to KISS. Everything that player sees is
--   real. There are no unmarked hidden tiles and only solid tiles can be
--   marked, so there are no invisible walls and to pass through an
--   illusory wall, you have to use a turn bumping into it first. Only
--   tiles marked with Suspect can turn out to be another tile. (So, if all
--   tiles are marked with Suspect, the player knows nothing for sure, but
--   this should be avoided, because searching becomes too time-consuming.)
--   Each actor sees adjacent tiles, even when blind, so adjacent tiles are
--   known, so the actor can decide accurately whether to pass thorugh or
--   alter, etc.
--   
--   Items are always real and visible. Actors are real, but can be
--   invisible. Invisible actors in walls can't be hit, but are hinted at
--   when altering the tile, so the player can flee or block. Invisible
--   actors in open space can be hit.
module Game.LambdaHack.Common.Perception

-- | Visible positions.
newtype PerVisible
PerVisible :: EnumSet Point -> PerVisible
[pvisible] :: PerVisible -> EnumSet Point

-- | Smelled positions.
newtype PerSmelled
PerSmelled :: EnumSet Point -> PerSmelled
[psmelled] :: PerSmelled -> EnumSet Point

-- | The type representing the perception of a faction on a level.
data Perception
Perception :: PerVisible -> PerSmelled -> Perception
[psight] :: Perception -> PerVisible
[psmell] :: Perception -> PerSmelled

-- | Perception of a single faction, indexed by level identifier.
type PerLid = EnumMap LevelId Perception

-- | Perception indexed by faction identifier. This can't be added to
--   <tt>FactionDict</tt>, because clients can't see it for other factions.
type PerFid = EnumMap FactionId PerLid

-- | The set of tiles visible by at least one hero.
totalVisible :: Perception -> EnumSet Point

-- | The set of tiles smelt by at least one hero.
totalSmelled :: Perception -> EnumSet Point
emptyPer :: Perception
nullPer :: Perception -> Bool
addPer :: Perception -> Perception -> Perception
diffPer :: Perception -> Perception -> Perception
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Perception.PerVisible
instance GHC.Classes.Eq Game.LambdaHack.Common.Perception.PerVisible
instance GHC.Show.Show Game.LambdaHack.Common.Perception.PerVisible
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Perception.PerSmelled
instance GHC.Classes.Eq Game.LambdaHack.Common.Perception.PerSmelled
instance GHC.Show.Show Game.LambdaHack.Common.Perception.PerSmelled
instance GHC.Generics.Generic Game.LambdaHack.Common.Perception.Perception
instance GHC.Classes.Eq Game.LambdaHack.Common.Perception.Perception
instance GHC.Show.Show Game.LambdaHack.Common.Perception.Perception
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Perception.Perception


-- | UI screen coordinates.
module Game.LambdaHack.Client.UI.PointUI

-- | UI screen coordinates, independent of whether square or monospace
--   fonts are being placed on the screen (though square fonts are never
--   placed on odd coordinates). These are not game map coordinates, becuse
--   UI is larger and more fine-grained than just the game map.
data PointUI
PointUI :: Int -> Int -> PointUI

-- | Coordinates of the big square fonts. These are not game map
--   coordinates, because the latter are offset by <tt>mapStartY</tt> and
--   represented by <tt>Point</tt>.
--   
--   However, confusingly, <tt>Point</tt> is also used for square font
--   glyph coordinates, though exclusively in context of rendered frames to
--   be sent to a frontend, namely <tt>PointArray.Array</tt>, which is
--   indexed by <tt>Point</tt> and is a vector, and so traditionally
--   indexed starting from zero and not from minus one, as would be needed
--   for consistency.
data PointSquare
PointSquare :: Int -> Int -> PointSquare
squareToUI :: PointSquare -> PointUI
uiToSquare :: PointUI -> PointSquare
squareToMap :: PointSquare -> Point
mapToSquare :: Point -> PointSquare

-- | The row where the dungeon map starts, both in <tt>PointUI</tt> and
--   <tt>PointSquare</tt> coordinates.
mapStartY :: Int
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.PointUI.PointUI
instance GHC.Show.Show Game.LambdaHack.Client.UI.PointUI.PointUI
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.PointUI.PointSquare
instance GHC.Show.Show Game.LambdaHack.Client.UI.PointUI.PointSquare


-- | Screen overlays.
module Game.LambdaHack.Client.UI.Overlay

-- | Three types of fonts used in the UI. Overlays (layers, more or less)
--   in proportional font are overwritten by layers in square font, which
--   are overwritten by layers in mono font. All overlays overwrite the
--   rendering of the game map, which is the underlying basic UI frame,
--   comprised of square font glyps.
--   
--   This type needs to be kept abstract to ensure that frontend-enforced
--   or user config-enforced font assignments in <a>FontSetup</a> (e.g.,
--   stating that the supposedly proportional font is overriden to be the
--   square font) can't be ignored. Otherwise a programmer could use
--   arbirary <tt>DisplayFont</tt>, instead of the one taken from
--   <a>FontSetup</a>, and so, e.g., calculating the width of an overlay so
--   constructed in order to decide where another overlay can start would
--   be inconsistent what what font is really eventually used when
--   rendering.
--   
--   Note that the order of constructors has limited effect, but it
--   illustrates how overwriting is explicitly implemented in frontends
--   that support all fonts.
data DisplayFont
isPropFont :: DisplayFont -> Bool
isSquareFont :: DisplayFont -> Bool
isMonoFont :: DisplayFont -> Bool
textSize :: DisplayFont -> [a] -> Int
data FontSetup
FontSetup :: DisplayFont -> DisplayFont -> DisplayFont -> FontSetup
[squareFont] :: FontSetup -> DisplayFont
[monoFont] :: FontSetup -> DisplayFont
[propFont] :: FontSetup -> DisplayFont
multiFontSetup :: FontSetup
singleFontSetup :: FontSetup

-- | String of colourful text. End of line characters permitted.
type AttrString = [AttrCharW32]
blankAttrString :: Int -> AttrString
textToAS :: Text -> AttrString
textFgToAS :: Color -> Text -> AttrString
stringToAS :: String -> AttrString

-- | Transform <a>AttrString</a> type to <a>String</a>.
attrStringToString :: AttrString -> String
(<+:>) :: AttrString -> AttrString -> AttrString
infixr 6 <+:>
(<\:>) :: AttrString -> AttrString -> AttrString
infixr 6 <\:>

-- | Line of colourful text. End of line characters forbidden. Trailing
--   <tt>White</tt> space forbidden.
data AttrLine
attrLine :: AttrLine -> AttrString
emptyAttrLine :: AttrLine
attrStringToAL :: AttrString -> AttrLine
firstParagraph :: AttrString -> AttrLine
textToAL :: Text -> AttrLine
textFgToAL :: Color -> Text -> AttrLine
stringToAL :: String -> AttrLine
linesAttr :: AttrString -> [AttrLine]

-- | Split a string into lines. Avoid breaking the line at a character
--   other than space. Remove the spaces on which lines are broken, keep
--   other spaces. In expensive assertions mode (dev debug mode) fail at
--   trailing spaces, but keep leading spaces, e.g., to make distance from
--   a text in another font. Newlines are respected.
--   
--   Note that we only split wrt <tt>White</tt> space, nothing else, and
--   the width, in the first argument, is calculated in characters, not in
--   UI (mono font) coordinates, so that taking and dropping characters is
--   performed correctly.
splitAttrString :: Int -> Int -> AttrString -> [AttrLine]
indentSplitAttrString :: DisplayFont -> Int -> AttrString -> [AttrLine]

-- | A series of screen lines with start positions at which they should be
--   overlayed over the base frame or a blank screen, depending on context.
--   The position point is represented as in integer that is an index into
--   the frame character array. The lines either fit the width of the
--   screen or are intended for truncation when displayed. The start
--   positions of lines may fall outside the length of the screen, too,
--   unlike in <tt>SingleFrame</tt>. Then they are simply not shown.
type Overlay = [(PointUI, AttrLine)]
xytranslateOverlay :: Int -> Int -> Overlay -> Overlay
xtranslateOverlay :: Int -> Overlay -> Overlay
ytranslateOverlay :: Int -> Overlay -> Overlay
offsetOverlay :: [AttrLine] -> Overlay
offsetOverlayX :: [(Int, AttrLine)] -> Overlay
typesetXY :: (Int, Int) -> [AttrLine] -> Overlay
updateLine :: Int -> (Int -> AttrString -> AttrString) -> Overlay -> Overlay
rectangleOfSpaces :: Int -> Int -> Overlay
maxYofOverlay :: Overlay -> Int
labDescOverlay :: DisplayFont -> Int -> AttrString -> (Overlay, Overlay)
nonbreakableRev :: [String]
isPrefixOfNonbreakable :: AttrString -> Bool
breakAtSpace :: AttrString -> (AttrString, AttrString)
splitAttrPhrase :: Int -> Int -> AttrLine -> [AttrLine]
instance GHC.Enum.Enum Game.LambdaHack.Client.UI.Overlay.DisplayFont
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Overlay.DisplayFont
instance GHC.Show.Show Game.LambdaHack.Client.UI.Overlay.DisplayFont
instance GHC.Show.Show Game.LambdaHack.Client.UI.Overlay.FontSetup
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Overlay.FontSetup
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Overlay.AttrLine
instance GHC.Show.Show Game.LambdaHack.Client.UI.Overlay.AttrLine


-- | Game messages displayed on top of the screen for the player to read
--   and then saved to player history.
module Game.LambdaHack.Client.UI.Msg

-- | The type of a single game message.
data Msg
class MsgShared a
toMsgShared :: MsgShared a => [(String, Color)] -> a -> Text -> Msg
toMsgDistinct :: [(String, Color)] -> MsgClassDistinct -> Text -> Text -> Msg
data MsgClassShowAndSave
MsgBookKeeping :: MsgClassShowAndSave
MsgStatusWakeup :: MsgClassShowAndSave
MsgStatusStopUs :: MsgClassShowAndSave
MsgStatusStopThem :: MsgClassShowAndSave
MsgItemCreation :: MsgClassShowAndSave
MsgItemRuination :: MsgClassShowAndSave
MsgDeathVictory :: MsgClassShowAndSave
MsgDeathDeafeat :: MsgClassShowAndSave
MsgDeathBoring :: MsgClassShowAndSave
MsgRiskOfDeath :: MsgClassShowAndSave
MsgPointmanSwap :: MsgClassShowAndSave
MsgFactionIntel :: MsgClassShowAndSave
MsgFinalOutcome :: MsgClassShowAndSave
MsgBackdropInfo :: MsgClassShowAndSave
MsgTerrainReveal :: MsgClassShowAndSave
MsgItemDiscovery :: MsgClassShowAndSave
MsgSpottedActor :: MsgClassShowAndSave
MsgItemMovement :: MsgClassShowAndSave
MsgActionMajor :: MsgClassShowAndSave
MsgActionMinor :: MsgClassShowAndSave
MsgEffectMajor :: MsgClassShowAndSave
MsgEffectMedium :: MsgClassShowAndSave
MsgEffectMinor :: MsgClassShowAndSave
MsgMiscellanous :: MsgClassShowAndSave
MsgHeardOutside :: MsgClassShowAndSave
MsgHeardNearby :: MsgClassShowAndSave
MsgHeardFaraway :: MsgClassShowAndSave
MsgBackdropFocus :: MsgClassShowAndSave
MsgActionWarning :: MsgClassShowAndSave
MsgRangedMightyWe :: MsgClassShowAndSave
MsgRangedMightyUs :: MsgClassShowAndSave
MsgRangedOthers :: MsgClassShowAndSave
MsgRangedNormalUs :: MsgClassShowAndSave
MsgGoodMiscEvent :: MsgClassShowAndSave
MsgBadMiscEvent :: MsgClassShowAndSave
MsgNeutralEvent :: MsgClassShowAndSave
MsgSpecialEvent :: MsgClassShowAndSave
MsgMeleeMightyWe :: MsgClassShowAndSave
MsgMeleeMightyUs :: MsgClassShowAndSave
MsgMeleeComplexWe :: MsgClassShowAndSave
MsgMeleeComplexUs :: MsgClassShowAndSave
MsgMeleeOthers :: MsgClassShowAndSave
MsgMeleeNormalUs :: MsgClassShowAndSave
MsgActionComplete :: MsgClassShowAndSave
MsgAtFeetMajor :: MsgClassShowAndSave
MsgAtFeetMinor :: MsgClassShowAndSave
MsgTutorialHint :: MsgClassShowAndSave
data MsgClassShow
MsgPromptGeneric :: MsgClassShow
MsgPromptFocus :: MsgClassShow
MsgPromptMention :: MsgClassShow
MsgPromptModify :: MsgClassShow
MsgPromptActors :: MsgClassShow
MsgPromptItems :: MsgClassShow
MsgPromptAction :: MsgClassShow
MsgActionAlert :: MsgClassShow
MsgSpottedThreat :: MsgClassShow
data MsgClassSave
MsgInnerWorkSpam :: MsgClassSave
MsgNumericReport :: MsgClassSave
data MsgClassIgnore
MsgMacroOperation :: MsgClassIgnore
MsgRunStopReason :: MsgClassIgnore
MsgStopPlayback :: MsgClassIgnore
data MsgClassDistinct
MsgSpottedItem :: MsgClassDistinct
MsgStatusSleep :: MsgClassDistinct
MsgStatusGoodUs :: MsgClassDistinct
MsgStatusBadUs :: MsgClassDistinct
MsgStatusOthers :: MsgClassDistinct
MsgStatusBenign :: MsgClassDistinct
MsgStatusWarning :: MsgClassDistinct
MsgStatusLongerUs :: MsgClassDistinct
MsgStatusLongThem :: MsgClassDistinct
data MsgClass
interruptsRunning :: MsgClass -> Bool
disturbsResting :: MsgClass -> Bool

-- | The set of messages, with repetitions, to show at the screen at once.
data Report

-- | Test if the list of non-whitespace messages is empty.
nullVisibleReport :: Report -> Bool

-- | Add a message to the start of report.
consReport :: Msg -> Report -> Report

-- | Render a report as a (possibly very long) list of <a>AttrString</a>.
renderReport :: Bool -> Report -> [AttrString]
anyInReport :: (MsgClass -> Bool) -> Report -> Bool

-- | The history of reports. This is a ring buffer of the given length
--   containing old archived history and two most recent reports stored
--   separately.
data History
newReport :: History -> Report

-- | Empty history of the given maximal length.
emptyHistory :: Int -> History

-- | Add a message to the new report of history, eliminating a possible
--   duplicate and noting its existence in the result.
addToReport :: Set Msg -> Bool -> Bool -> History -> Msg -> Time -> (Set Msg, History, Bool)

-- | Add a newline to end of the new report of history, unless empty.
addEolToNewReport :: History -> History

-- | Archive old report to history, filtering out messages with 0
--   duplicates and prompts. Set up new report with a new timestamp.
archiveReport :: History -> History
lengthHistory :: History -> Int

-- | Render history as many lines of text. New report is not rendered. It's
--   expected to be empty when history is shown.
renderHistory :: History -> [AttrString]
type UAttrString = Vector Word32
uToAttrString :: UAttrString -> AttrString
attrStringToU :: AttrString -> UAttrString
toMsg :: [(String, Color)] -> MsgPrototype -> Msg
data MsgPrototype
tripleFromProto :: MsgPrototype -> (Text, Text, MsgClass)
scrapsRepeats :: MsgClass -> Bool
isTutorialHint :: MsgClass -> Bool
msgColor :: MsgClass -> Color
data RepMsgNK

-- | If only one of the message components is non-empty and non-whitespace,
--   but its count is zero, the message is considered empty.
nullRepMsgNK :: RepMsgNK -> Bool

-- | Empty set of messages.
emptyReport :: Report
renderRepetition :: (AttrString, Int) -> AttrString
scrapRepetitionSingle :: (AttrString, Int) -> [(AttrString, Int)] -> [(AttrString, Int)] -> (Bool, [(AttrString, Int)], [(AttrString, Int)])
scrapRepetition :: History -> Maybe History
renderTimeReport :: Time -> Report -> [AttrString]
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Msg.MsgClassShowAndSave
instance GHC.Enum.Bounded Game.LambdaHack.Client.UI.Msg.MsgClassShowAndSave
instance GHC.Enum.Enum Game.LambdaHack.Client.UI.Msg.MsgClassShowAndSave
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Msg.MsgClassShowAndSave
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Msg.MsgClassShowAndSave
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.MsgClassShowAndSave
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Msg.MsgClassShow
instance GHC.Enum.Bounded Game.LambdaHack.Client.UI.Msg.MsgClassShow
instance GHC.Enum.Enum Game.LambdaHack.Client.UI.Msg.MsgClassShow
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Msg.MsgClassShow
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Msg.MsgClassShow
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.MsgClassShow
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Msg.MsgClassSave
instance GHC.Enum.Bounded Game.LambdaHack.Client.UI.Msg.MsgClassSave
instance GHC.Enum.Enum Game.LambdaHack.Client.UI.Msg.MsgClassSave
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Msg.MsgClassSave
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Msg.MsgClassSave
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.MsgClassSave
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Msg.MsgClassIgnore
instance GHC.Enum.Bounded Game.LambdaHack.Client.UI.Msg.MsgClassIgnore
instance GHC.Enum.Enum Game.LambdaHack.Client.UI.Msg.MsgClassIgnore
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Msg.MsgClassIgnore
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Msg.MsgClassIgnore
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.MsgClassIgnore
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Msg.MsgClassDistinct
instance GHC.Enum.Bounded Game.LambdaHack.Client.UI.Msg.MsgClassDistinct
instance GHC.Enum.Enum Game.LambdaHack.Client.UI.Msg.MsgClassDistinct
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Msg.MsgClassDistinct
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Msg.MsgClassDistinct
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.MsgClassDistinct
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Msg.MsgClass
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Msg.MsgClass
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Msg.MsgClass
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.MsgClass
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Msg.Msg
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Msg.Msg
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Msg.Msg
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.Msg
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Msg.RepMsgNK
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.RepMsgNK
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.Report
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.Report
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Msg.History
instance GHC.Show.Show Game.LambdaHack.Client.UI.Msg.History
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.History
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.RepMsgNK
instance Game.LambdaHack.Client.UI.Msg.MsgShared Game.LambdaHack.Client.UI.Msg.MsgClassShowAndSave
instance Game.LambdaHack.Client.UI.Msg.MsgShared Game.LambdaHack.Client.UI.Msg.MsgClassShow
instance Game.LambdaHack.Client.UI.Msg.MsgShared Game.LambdaHack.Client.UI.Msg.MsgClassSave
instance Game.LambdaHack.Client.UI.Msg.MsgShared Game.LambdaHack.Client.UI.Msg.MsgClassIgnore
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.Msg
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.MsgClass
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.MsgClassDistinct
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.MsgClassIgnore
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.MsgClassSave
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.MsgClassShow
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Msg.MsgClassShowAndSave


-- | Frontend-independent keyboard input operations.
module Game.LambdaHack.Client.UI.Key

-- | Frontend-independent datatype to represent keys.
data Key
Esc :: Key
Return :: Key
Space :: Key
Tab :: Key
BackTab :: Key
BackSpace :: Key
PgUp :: Key
PgDn :: Key
Left :: Key
Right :: Key
Up :: Key
Down :: Key
End :: Key
Begin :: Key
Insert :: Key
Delete :: Key
PrintScreen :: Key
Home :: Key

-- | a keypad key for a character (digits and operators)
KP :: Char -> Key

-- | a single printable character
Char :: Char -> Key

-- | function key
Fun :: Int -> Key

-- | left mouse button pressed
LeftButtonPress :: Key

-- | middle mouse button pressed
MiddleButtonPress :: Key

-- | right mouse button pressed
RightButtonPress :: Key

-- | left mouse button released
LeftButtonRelease :: Key

-- | middle mouse button released
MiddleButtonRelease :: Key

-- | right mouse button released
RightButtonRelease :: Key

-- | mouse wheel rotated north
WheelNorth :: Key

-- | mouse wheel rotated south
WheelSouth :: Key

-- | an unknown key, registered to warn the user
Unknown :: String -> Key
DeadKey :: Key

-- | Our own encoding of modifiers.
data Modifier
NoModifier :: Modifier
ControlShift :: Modifier
AltShift :: Modifier
Shift :: Modifier
Control :: Modifier
Alt :: Modifier

-- | Key and modifier.
data KM
KM :: Modifier -> Key -> KM
[modifier] :: KM -> Modifier
[key] :: KM -> Key

-- | Key, modifier and position of mouse pointer.
data KMP
KMP :: KM -> PointUI -> KMP
[kmpKeyMod] :: KMP -> KM
[kmpPointer] :: KMP -> PointUI

-- | Common and terse names for keys.
showKey :: Key -> String

-- | Show a key with a modifier, if any.
showKM :: KM -> String
escKM :: KM
controlEscKM :: KM
spaceKM :: KM
safeSpaceKM :: KM
undefinedKM :: KM
returnKM :: KM
pgupKM :: KM
pgdnKM :: KM
wheelNorthKM :: KM
wheelSouthKM :: KM
upKM :: KM
downKM :: KM
leftKM :: KM
rightKM :: KM
homeKM :: KM
endKM :: KM
backspaceKM :: KM
controlP :: KM
leftButtonReleaseKM :: KM
middleButtonReleaseKM :: KM
rightButtonReleaseKM :: KM
cardinalAllKM :: Bool -> Bool -> [KM]
dirAllKey :: Bool -> Bool -> [Key]
handleCardinal :: [KM] -> KM -> Maybe Vector

-- | Configurable event handler for the direction keys. Used for directed
--   commands such as close door.
handleDir :: [Key] -> KM -> Maybe Vector

-- | Binding of both sets of movement keys, vi and laptop.
moveBinding :: Bool -> Bool -> (Vector -> a) -> (Vector -> a) -> [(KM, a)]
mkKM :: String -> KM
mkChar :: Char -> KM

-- | Translate key from a GTK string description to our internal key type.
--   To be used, in particular, for the command bindings and macros in the
--   config file.
--   
--   See <a>https://github.com/twobob/gtk-/blob/master/gdk/keynames.txt</a>
keyTranslate :: String -> Key

-- | Translate key from a Web API string description
--   (<a>https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key#Key_values</a>)
--   to our internal key type. To be used in web frontends. The argument
--   says whether Shift is pressed.
keyTranslateWeb :: String -> Bool -> Key
dirMoveNoModifier :: Bool -> Bool -> [Key]
dirRunNoModifier :: Bool -> Bool -> [Key]
dirRunControl :: [Key]
dirRunShift :: [Key]
dirKeypadKey :: [Key]
dirKeypadShiftChar :: [Char]
dirKeypadShiftKey :: [Key]
dirLeftHandKey :: [Key]
dirLeftHandShiftKey :: [Key]
dirViChar :: [Char]
dirViKey :: [Key]
dirViShiftKey :: [Key]
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Key.Key
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Key.Key
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Key.Key
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Key.Modifier
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Key.Modifier
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Key.Modifier
instance GHC.Show.Show Game.LambdaHack.Client.UI.Key.Modifier
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.Key.KM
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Key.KM
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Key.KM
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Key.KM
instance Control.DeepSeq.NFData Game.LambdaHack.Client.UI.Key.KM
instance GHC.Show.Show Game.LambdaHack.Client.UI.Key.KM
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Key.Modifier
instance Control.DeepSeq.NFData Game.LambdaHack.Client.UI.Key.Modifier
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Key.Key
instance Control.DeepSeq.NFData Game.LambdaHack.Client.UI.Key.Key


-- | Rectangular areas of levels and their basic operations.
module Game.LambdaHack.Common.Area

-- | The type of areas. The bottom left and the top right points.
data Area

-- | Checks if it's an area with at least one field.
toArea :: (X, Y, X, Y) -> Maybe Area
fromArea :: Area -> (X, Y, X, Y)
spanArea :: Area -> (Point, X, Y)
trivialArea :: Point -> Area
isTrivialArea :: Area -> Bool

-- | Checks that a point belongs to an area.
inside :: Area -> Point -> Bool

-- | Shrink the given area on all fours sides by the amount.
shrink :: Area -> Maybe Area
expand :: Area -> Area
middlePoint :: Area -> Point
areaInnerBorder :: Area -> [Point]
sumAreas :: Area -> Area -> Area
punindex :: X -> Int -> Point
instance GHC.Classes.Eq Game.LambdaHack.Common.Area.Area
instance GHC.Show.Show Game.LambdaHack.Common.Area.Area
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Area.Area


-- | Per-actor analytics of personal feats.
module Game.LambdaHack.Common.Analytics

-- | Summary analytics data for each faction.
type FactionAnalytics = EnumMap FactionId Analytics

-- | Analytics data for each live actor.
type ActorAnalytics = EnumMap ActorId Analytics

-- | Statistics of possible and actual generation of items for each lore
--   kind.
type GenerationAnalytics = EnumMap SLore (EnumMap ItemId Int)
type KillMap = EnumMap FactionId (EnumMap ItemId Int)

-- | Statistics of past events concerning an actor.
newtype Analytics
Analytics :: EnumMap KillHow KillMap -> Analytics
[akillCounts] :: Analytics -> EnumMap KillHow KillMap

-- | Labels of individual kill count analytics.
data KillHow
KillKineticMelee :: KillHow
KillKineticRanged :: KillHow
KillKineticBlast :: KillHow
KillKineticPush :: KillHow
KillOtherMelee :: KillHow
KillOtherRanged :: KillHow
KillOtherBlast :: KillHow
KillOtherPush :: KillHow
KillActorLaunch :: KillHow
KillTileLaunch :: KillHow
KillDropLaunch :: KillHow
KillCatch :: KillHow
emptyAnalytics :: Analytics
addFactionKill :: FactionId -> KillHow -> FactionId -> ItemId -> FactionAnalytics -> FactionAnalytics
addActorKill :: ActorId -> KillHow -> FactionId -> ItemId -> ActorAnalytics -> ActorAnalytics
addKill :: KillHow -> FactionId -> ItemId -> Maybe Analytics -> Analytics
instance GHC.Generics.Generic Game.LambdaHack.Common.Analytics.KillHow
instance GHC.Enum.Enum Game.LambdaHack.Common.Analytics.KillHow
instance GHC.Classes.Eq Game.LambdaHack.Common.Analytics.KillHow
instance GHC.Show.Show Game.LambdaHack.Common.Analytics.KillHow
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Analytics.Analytics
instance GHC.Classes.Eq Game.LambdaHack.Common.Analytics.Analytics
instance GHC.Show.Show Game.LambdaHack.Common.Analytics.Analytics
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Analytics.KillHow


-- | A game requires the engine provided by the library, perhaps
--   customized, and game content, defined completely afresh for the
--   particular game. The possible kinds of content are fixed in the
--   library and all defined within the library source code directory. On
--   the other hand, game content, is defined in the directory hosting the
--   particular game definition.
--   
--   Content of a given kind is just a list of content items. After the
--   list is verified and the data preprocessed, it's held in the
--   <tt>ContentData</tt> datatype.
module Game.LambdaHack.Definition.ContentData

-- | Verified and preprocessed content data of a particular kind.
data ContentData c
validateRarity :: Rarity -> [Text]
validFreqs :: Freqs a -> Bool
emptyContentData :: ContentData a
makeContentData :: Show c => String -> (c -> Text) -> (c -> Freqs c) -> (c -> [Text]) -> ([c] -> ContentData c -> [Text]) -> [c] -> [GroupName c] -> [GroupName c] -> ContentData c

-- | Content element at given id.
okind :: ContentData a -> ContentId a -> a
omemberGroup :: ContentData a -> GroupName a -> Bool
oexistsGroup :: ContentData a -> GroupName a -> Bool
oisSingletonGroup :: ContentData a -> GroupName a -> Bool

-- | The id of the unique member of a singleton content group.
ouniqGroup :: Show a => ContentData a -> GroupName a -> ContentId a

-- | Pick a random id belonging to a group and satisfying a predicate.
opick :: Show a => ContentData a -> GroupName a -> (a -> Bool) -> Rnd (Maybe (ContentId a))

-- | Fold strictly over all content <tt>a</tt>.
ofoldlWithKey' :: ContentData a -> (b -> ContentId a -> a -> b) -> b -> b

-- | Fold over the given group only.
ofoldlGroup' :: ContentData a -> GroupName a -> (b -> Int -> ContentId a -> a -> b) -> b -> b
omapVector :: ContentData a -> (a -> b) -> Vector b
oimapVector :: ContentData a -> (ContentId a -> a -> b) -> Vector b

-- | Size of content <tt>a</tt>.
olength :: ContentData a -> Int


-- | Arrays, based on Data.Vector.Unboxed, indexed by <tt>Point</tt>.
module Game.LambdaHack.Common.PointArray
class (Ord c, Eq (UnboxRep c), Ord (UnboxRep c), Bounded (UnboxRep c), Binary (UnboxRep c), Unbox (UnboxRep c)) => UnboxRepClass c where {
    type UnboxRep c;
    type UnboxRep c = c;
}
toUnboxRepUnsafe :: UnboxRepClass c => c -> UnboxRep c
fromUnboxRep :: UnboxRepClass c => UnboxRep c -> c

-- | Arrays indexed by <tt>Point</tt>.
data Array c
Array :: X -> Y -> Vector (UnboxRep c) -> Array c
[axsize] :: Array c -> X
[aysize] :: Array c -> Y
[avector] :: Array c -> Vector (UnboxRep c)
empty :: UnboxRepClass c => Array c

-- | Array lookup.
(!) :: UnboxRepClass c => Array c -> Point -> c
accessI :: UnboxRepClass c => Array c -> Int -> UnboxRep c

-- | Construct an array updated with the association list.
(//) :: UnboxRepClass c => Array c -> [(Point, c)] -> Array c

-- | Create an array from a replicated element.
replicateA :: UnboxRepClass c => X -> Y -> c -> Array c
unfoldrNA :: UnboxRepClass c => X -> Y -> (b -> (c, b)) -> b -> Array c

-- | Fold right over an array.
foldrA :: UnboxRepClass c => (c -> a -> a) -> a -> Array c -> a

-- | Fold right strictly over an array.
foldrA' :: UnboxRepClass c => (c -> a -> a) -> a -> Array c -> a

-- | Fold left strictly over an array.
foldlA' :: UnboxRepClass c => (a -> c -> a) -> a -> Array c -> a

-- | Fold left strictly over an array (function applied to each element and
--   its index).
ifoldlA' :: UnboxRepClass c => (a -> Point -> c -> a) -> a -> Array c -> a

-- | Fold right strictly over an array (function applied to each element
--   and its index).
ifoldrA' :: UnboxRepClass c => (Point -> c -> a -> a) -> a -> Array c -> a

-- | Fold monadically strictly over an array.
foldMA' :: (Monad m, UnboxRepClass c) => (a -> c -> m a) -> a -> Array c -> m a

-- | Map over an array.
mapA :: (UnboxRepClass c, UnboxRepClass d) => (c -> d) -> Array c -> Array d

-- | Map over an array (function applied to each element and its index).
imapA :: (UnboxRepClass c, UnboxRepClass d) => (Point -> c -> d) -> Array c -> Array d

-- | Map monadically over an array (function applied to each element and
--   its index) and ignore the results.
imapMA_ :: (Monad m, UnboxRepClass c) => (Point -> c -> m ()) -> Array c -> m ()

-- | Yield the point coordinates of all the minimum elements of the array.
--   The array may not be empty.
minIndexesA :: UnboxRepClass c => Array c -> [Point]

-- | Yield the point coordinates of the first maximum element of the array.
--   The array may not be empty.
maxIndexA :: UnboxRepClass c => Array c -> Point

-- | Yield the point coordinates of the first maximum element of the array.
--   The array may not be empty.
maxIndexByA :: UnboxRepClass c => (c -> c -> Ordering) -> Array c -> Point

-- | Yield the point coordinates of the last maximum element of the array.
--   The array may not be empty.
maxLastIndexA :: UnboxRepClass c => Array c -> Point
toListA :: UnboxRepClass c => Array c -> [c]
toUnboxRep :: UnboxRepClass c => c -> UnboxRep c
instance Game.LambdaHack.Common.PointArray.UnboxRepClass c => GHC.Classes.Eq (Game.LambdaHack.Common.PointArray.Array c)
instance GHC.Show.Show (Game.LambdaHack.Common.PointArray.Array c)
instance Game.LambdaHack.Common.PointArray.UnboxRepClass c => Data.Binary.Class.Binary (Game.LambdaHack.Common.PointArray.Array c)
instance Game.LambdaHack.Common.PointArray.UnboxRepClass GHC.Types.Bool
instance Game.LambdaHack.Common.PointArray.UnboxRepClass GHC.Word.Word8
instance Game.LambdaHack.Common.PointArray.UnboxRepClass (Game.LambdaHack.Definition.DefsInternal.ContentId k)
instance Game.LambdaHack.Common.PointArray.UnboxRepClass Game.LambdaHack.Definition.Color.AttrCharW32


-- | Breadth first search algorithm.
module Game.LambdaHack.Client.Bfs

-- | Weighted distance between points along shortest paths.
data BfsDistance

-- | State of legality of moves between adjacent points.
data MoveLegal
MoveBlocked :: MoveLegal
MoveToOpen :: MoveLegal
MoveToClosed :: MoveLegal
MoveToUnknown :: MoveLegal
subtractBfsDistance :: BfsDistance -> BfsDistance -> Int

-- | The minimal distance value assigned to paths that don't enter any
--   unknown tiles.
minKnownBfs :: BfsDistance

-- | The distance value that denotes no legal path between points, either
--   due to blocked tiles or pathfinding aborted at earlier tiles, e.g.,
--   due to unknown tiles.
apartBfs :: BfsDistance

-- | Maximum value of the type.
maxBfsDistance :: BfsDistance

-- | Create and fill a BFS array for the given level. Unsafe array
--   operations are OK here, because the intermediate values of the vector
--   don't leak anywhere outside nor are kept unevaluated and so they can't
--   be overwritten by the unsafe side-effect.
--   
--   When computing move cost, we assume doors openable at no cost, because
--   other actors use them, too, so the cost is shared and the extra
--   visiblity is valuable, too. We treat unknown tiles specially. Whether
--   suspect tiles are considered openable depends on
--   <tt>smarkSuspect</tt>.
--   
--   Instead of a BFS queue (list) we use the two tabs (arrays), for (JS)
--   speed.
fillBfs :: Array Word8 -> Word8 -> Point -> (PrimArray PointI, PrimArray PointI) -> Array BfsDistance
data AndPath
AndPath :: Point -> [Point] -> Point -> Int -> AndPath
[pathSource] :: AndPath -> Point
[pathList] :: AndPath -> [Point]
[pathGoal] :: AndPath -> Point
[pathLen] :: AndPath -> Int

-- | Find a path, without the source position, with the smallest length.
--   The <tt>eps</tt> coefficient determines which direction (of the
--   closest directions available) that path should prefer, where 0 means
--   north-west and 1 means north. The path tries hard to avoid actors and
--   tries to avoid tiles that need altering and ambient light. Actors are
--   avoided only close to the start of the path, because elsewhere they
--   are likely to move before they are reached. Even projectiles are
--   avoided, which sometimes has the effect of choosing a safer route
--   (regardless if the projectiles are friendly fire or not).
--   
--   An unwelcome side effect of avoiding actors is that friends will
--   sometimes avoid displacing and instead perform two separate moves,
--   wasting 1 turn in total (only if they had opposed direction of their
--   goals; unlikely). But in corridors they will still displace and
--   elsewhere this scenario was quite rare already.
findPathBfs :: EnumSet Point -> Array Word8 -> (PointI -> Bool) -> Point -> Point -> Int -> Array BfsDistance -> Maybe AndPath

-- | Access a BFS array and interpret the looked up distance value.
accessBfs :: Array BfsDistance -> Point -> Maybe Int
succBfsDistance :: BfsDistance -> BfsDistance
predBfsDistance :: BfsDistance -> BfsDistance

-- | The distance value that denotes that path search was aborted at this
--   tile due to too large actual distance and that the tile was unknown.
--   It is also a true distance value for this tile.
abortedUnknownBfs :: BfsDistance
maskBfs :: BfsDistance -> BfsDistance
distanceBfs :: BfsDistance -> Maybe Int
instance GHC.Bits.Bits Game.LambdaHack.Client.Bfs.BfsDistance
instance GHC.Classes.Ord Game.LambdaHack.Client.Bfs.BfsDistance
instance GHC.Classes.Eq Game.LambdaHack.Client.Bfs.BfsDistance
instance GHC.Show.Show Game.LambdaHack.Client.Bfs.BfsDistance
instance GHC.Classes.Eq Game.LambdaHack.Client.Bfs.MoveLegal
instance GHC.Generics.Generic Game.LambdaHack.Client.Bfs.AndPath
instance GHC.Show.Show Game.LambdaHack.Client.Bfs.AndPath
instance Data.Binary.Class.Binary Game.LambdaHack.Client.Bfs.AndPath
instance Game.LambdaHack.Common.PointArray.UnboxRepClass Game.LambdaHack.Client.Bfs.BfsDistance


-- | The appearance of in-game items, as communicated to the player.
module Game.LambdaHack.Definition.Flavour

-- | The type of item flavours.
data Flavour

-- | Turn a colour set into a flavour set.
zipPlain :: [Color] -> [Flavour]

-- | Turn a colour set into a flavour set.
zipFancy :: [Color] -> [Flavour]

-- | Turn a colour set into a flavour set.
zipLiquid :: [Color] -> [Flavour]

-- | Turn a colour set into a flavour set.
zipGlassPlain :: [Color] -> [Flavour]

-- | Turn a colour set into a flavour set.
zipGlassFancy :: [Color] -> [Flavour]

-- | Turn a colour set into a flavour set.
zipStory :: [Color] -> [Flavour]
dummyFlavour :: Flavour
stdFlavList :: [Flavour]

-- | Get the underlying base colour of a flavour.
flavourToColor :: Flavour -> Color

-- | Construct the full name of a flavour.
flavourToName :: Flavour -> Text

-- | Human-readable names for item colors. The plain set.
colorToPlainName :: Color -> Text

-- | Human-readable names for item colors. The fancy set.
colorToFancyName :: Color -> Text

-- | Simple names for team colors (bright colours preferred).
colorToTeamName :: Color -> Text
data FancyName

-- | Human-readable names for item colors. The liquid set.
colorToLiquidName :: Color -> Text

-- | Human-readable names for item colors. The plain glass set.
colorToGlassPlainName :: Color -> Text

-- | Human-readable names for item colors. The fancy glass set.
colorToGlassFancyName :: Color -> Text
instance GHC.Generics.Generic Game.LambdaHack.Definition.Flavour.FancyName
instance GHC.Enum.Bounded Game.LambdaHack.Definition.Flavour.FancyName
instance GHC.Enum.Enum Game.LambdaHack.Definition.Flavour.FancyName
instance GHC.Classes.Ord Game.LambdaHack.Definition.Flavour.FancyName
instance GHC.Classes.Eq Game.LambdaHack.Definition.Flavour.FancyName
instance GHC.Show.Show Game.LambdaHack.Definition.Flavour.FancyName
instance GHC.Generics.Generic Game.LambdaHack.Definition.Flavour.Flavour
instance GHC.Classes.Ord Game.LambdaHack.Definition.Flavour.Flavour
instance GHC.Classes.Eq Game.LambdaHack.Definition.Flavour.Flavour
instance GHC.Show.Show Game.LambdaHack.Definition.Flavour.Flavour
instance GHC.Enum.Enum Game.LambdaHack.Definition.Flavour.Flavour
instance Data.Binary.Class.Binary Game.LambdaHack.Definition.Flavour.Flavour


-- | The type of kinds of weapons, treasure, organs, blasts, etc.
module Game.LambdaHack.Content.ItemKind
pattern CONDITION :: GroupName ItemKind
pattern COMMON_ITEM :: GroupName ItemKind
pattern S_BONUS_HP :: GroupName ItemKind
pattern S_BRACED :: GroupName ItemKind
pattern S_ASLEEP :: GroupName ItemKind
pattern S_IMPRESSED :: GroupName ItemKind
pattern S_CURRENCY :: GroupName ItemKind
pattern MOBILE :: GroupName ItemKind
pattern CRAWL_ITEM :: GroupName ItemKind
pattern TREASURE :: GroupName ItemKind
pattern ANY_SCROLL :: GroupName ItemKind
pattern ANY_GLASS :: GroupName ItemKind
pattern ANY_POTION :: GroupName ItemKind
pattern ANY_FLASK :: GroupName ItemKind
pattern EXPLOSIVE :: GroupName ItemKind
pattern ANY_JEWELRY :: GroupName ItemKind
pattern S_SINGLE_SPARK :: GroupName ItemKind
pattern S_SPARK :: GroupName ItemKind
pattern S_FRAGRANCE :: GroupName ItemKind
pattern HORROR :: GroupName ItemKind
pattern VALUABLE :: GroupName ItemKind
pattern UNREPORTED_INVENTORY :: GroupName ItemKind
pattern AQUATIC :: GroupName ItemKind

-- | Item properties that are fixed for a given kind of items. Of these,
--   aspects and effects are jointly called item powers. Note that this
--   type is mutually recursive with <a>Effect</a> and <a>Aspect</a>.
data ItemKind
ItemKind :: ContentSymbol ItemKind -> Text -> Freqs ItemKind -> [Flavour] -> Dice -> Rarity -> Text -> Int -> Dice -> [Aspect] -> [Effect] -> [(GroupName ItemKind, CStore)] -> Text -> ItemKind

-- | map symbol
[isymbol] :: ItemKind -> ContentSymbol ItemKind

-- | generic name; is pluralized if needed
[iname] :: ItemKind -> Text

-- | frequency within groups
[ifreq] :: ItemKind -> Freqs ItemKind

-- | possible flavours
[iflavour] :: ItemKind -> [Flavour]

-- | created in that quantity
[icount] :: ItemKind -> Dice

-- | rarity on given depths
[irarity] :: ItemKind -> Rarity

-- | the verb for hitting
[iverbHit] :: ItemKind -> Text

-- | weight in grams
[iweight] :: ItemKind -> Int

-- | basic kinetic damage
[idamage] :: ItemKind -> Dice

-- | affect the actor continuously
[iaspects] :: ItemKind -> [Aspect]

-- | cause the effects when triggered
[ieffects] :: ItemKind -> [Effect]

-- | accompanying organs and equipment
[ikit] :: ItemKind -> [(GroupName ItemKind, CStore)]

-- | description
[idesc] :: ItemKind -> Text
makeData :: ItemSymbolsUsedInEngine -> [ItemKind] -> [GroupName ItemKind] -> [GroupName ItemKind] -> ContentData ItemKind

-- | Aspects of items. Aspect <tt>AddSkill</tt> is additive (starting at 0)
--   for all items wielded by an actor and it affects the actor. The others
--   affect only the item in question, not the actor carrying it, and so
--   are not additive in any sense.
data Aspect

-- | specifies the cooldown before an item may be applied again; if a copy
--   of an item is applied manually (not via periodic activation), all
--   effects on a single copy of the item are disabled until the copy
--   recharges for the given time expressed in game turns; all copies
--   recharge concurrently
Timeout :: Dice -> Aspect

-- | bonus to a skill; in content, avoid boosting skills such as SkApply
--   via permanent equipment, to avoid micromanagement through swapping
--   items among party members before each skill use
AddSkill :: Skill -> Dice -> Aspect

-- | item feature
SetFlag :: Flag -> Aspect

-- | extra label of the item; it's not pluralized
ELabel :: Text -> Aspect

-- | parameters modifying a throw
ToThrow :: ThrowMod -> Aspect

-- | until identified, presents as this unique kind
PresentAs :: GroupName ItemKind -> Aspect

-- | AI and UI flag that leaks item intended use
EqpSlot :: EqpSlot -> Aspect

-- | if level-scaled dice roll &gt; 50, pick the former aspects, otherwise
--   the latter
Odds :: Dice -> [Aspect] -> [Aspect] -> Aspect

-- | Effects of items. Can be invoked by the item wielder to affect another
--   actor or the wielder himself.
--   
--   Various effects of an item kind are all groupped in one list, at the
--   cost of conditionals, sequences, etc., to ensure brevity and
--   simplicity of content definitions. Most effects fire regardless of
--   activation kind (the only exceptions are <tt>OnSmash</tt> and
--   <tt>OnCombine</tt> effects) so the deviations, handled via the
--   conditionals, are rare and the definitions remain simple. Whether an
--   item can be activated in any particular way, OTOH, is specified via
--   simple flags elsewhere, again, by default, assuming that most
--   activations are possible for all.
data Effect

-- | burn with this damage
Burn :: Dice -> Effect

-- | explode producing this group of blasts
Explode :: GroupName ItemKind -> Effect

-- | modify HP of the actor by this amount
RefillHP :: Int -> Effect

-- | modify Calm of the actor by this amount
RefillCalm :: Int -> Effect

-- | change actor's allegiance
Dominate :: Effect

-- | make actor susceptible to domination
Impress :: Effect

-- | put actor to sleep, also calming him
PutToSleep :: Effect

-- | make the actor yell/yawn, waking him and others up
Yell :: Effect

-- | summon the given number of actors of this group
Summon :: GroupName ItemKind -> Dice -> Effect

-- | ascend to another level of the dungeon
Ascend :: Bool -> Effect

-- | escape from the dungeon
Escape :: Effect

-- | paralyze for this many game clips
Paralyze :: Dice -> Effect

-- | paralyze for this many game clips due to water
ParalyzeInWater :: Dice -> Effect

-- | give actor this many extra tenths of actor move
InsertMove :: Dice -> Effect

-- | teleport actor across rougly this distance
Teleport :: Dice -> Effect

-- | create an item of the group and insert into the store with the given
--   random timer; it cardinality not specified, roll it
CreateItem :: Maybe Int -> CStore -> GroupName ItemKind -> TimerDice -> Effect

-- | destroy some items of the group from the store; see below about Ints
DestroyItem :: Int -> Int -> CStore -> GroupName ItemKind -> Effect

-- | <tt>ConsumeItems toUse toDestroy</tt> uses items matching
--   <tt>toUse</tt> (destroys non-durable, without invoking OnSmash
--   effects; applies normal effects of durable, without destroying them;
--   the same behaviour as when transforming terrain using items) and
--   destroys items matching <tt>toDestroy</tt>, invoking no effects,
--   regardless of durability; the items are taken from <tt>CGround</tt>
--   (but not from <tt>CEqp</tt>), preferring non-durable (since durable
--   can harm when used and may be more vauable when destroyed); if not all
--   required items are present, no item are destroyed; if an item belongs
--   to many groups in the sum of <tt>toUse</tt> and <tt>toDestroy</tt>, it
--   counts for all (otherwise, some orders of destroying would succeed,
--   while others would not); even if item durable, as many copies are
--   needed as specified, not just one applied many times; items are first
--   destroyed and then, if any copies left, applied
ConsumeItems :: [(Int, GroupName ItemKind)] -> [(Int, GroupName ItemKind)] -> Effect

-- | make the actor drop items of the given group from the given store; the
--   first integer says how many item kinds to drop, the second, how many
--   copies of each kind to drop; for non-organs, beware of not dropping
--   all kinds, or cluttering store with rubbish becomes beneficial
DropItem :: Int -> Int -> CStore -> GroupName ItemKind -> Effect

-- | reduce the cooldown period of this number of discharged items in the
--   victim's equipment and organs by this dice of game clips; if the
--   result is negative, set to 0, instantly recharging the item; starts
--   with weapons with highest raw damage in equipment, then among organs,
--   then non-weapons in equipment and among organs; beware of exploiting
--   for healing periodic items
Recharge :: Int -> Dice -> Effect

-- | increase the cooldown period of this number of fully recharged items
--   in the victim's equipment and organs by this dice of game clips;
--   starts with weapons with highest raw damage in equipment, then among
--   organs, then non-weapons in equipment and among organs; beware of
--   exploiting for hunger inducing and similar organs
Discharge :: Int -> Dice -> Effect

-- | get a suitable (i.e., numerous enough) non-unique common item stack on
--   the floor and polymorph it to a stack of random common items, with
--   current depth coefficient
PolyItem :: Effect

-- | get a suitable (i.e., with any random aspects) single item (even
--   unique) on the floor and change the random bonuses of the items
--   randomly, with maximal depth coefficient
RerollItem :: Effect

-- | exactly duplicate a single non-unique, non-valuable item on the floor
DupItem :: Effect

-- | find a suitable (i.e., not identified) item, starting from the floor,
--   and identify it
Identify :: Effect

-- | detect something on the map in the given radius
Detect :: DetectKind -> Int -> Effect

-- | send an actor flying (push or pull, depending)
SendFlying :: ThrowMod -> Effect

-- | push an actor
PushActor :: ThrowMod -> Effect

-- | pull an actor
PullActor :: ThrowMod -> Effect

-- | remove all smell on the level
ApplyPerfume :: Effect

-- | try to trigger a single random effect of the list
AtMostOneOf :: [Effect] -> Effect

-- | trigger, with equal probability, one of the effects that don't end
--   with <tt>UseDud</tt>
OneOf :: [Effect] -> Effect

-- | trigger the effect when item smashed (not when applied nor meleed)
OnSmash :: Effect -> Effect

-- | trigger the effect only when the actor explicitly desires to combine
--   items or otherwise subtly tinker with an item or a tile, e.g., craft
--   items from other items in a workshop; in particular, don't trigger the
--   effects when entering a tile; trigger exclusively the effects when
--   activating walkable terrain
OnCombine :: Effect -> Effect

-- | apply the effect to the user, not the victim
OnUser :: Effect -> Effect

-- | nothing happens, <tt>UseDud</tt>, no description
NopEffect :: Effect

-- | only fire second effect if first activated
AndEffect :: Effect -> Effect -> Effect

-- | only fire second effect if first not activated
OrEffect :: Effect -> Effect -> Effect

-- | fire all effects in order; always suceed
SeqEffect :: [Effect] -> Effect

-- | if condition not met, fail without a message; better avoided, since AI
--   can't value it well
When :: Condition -> Effect -> Effect

-- | if condition met, fail without a message; better avoided, since AI
--   can't value it well
Unless :: Condition -> Effect -> Effect

-- | conditional effect; better avoided, since AI can't value it well
IfThenElse :: Condition -> Effect -> Effect -> Effect

-- | a sentence with the actor causing the effect as subject, the given
--   texts as the verb and the ending of the sentence (that may be ignored
--   when the message is cited, e.g., as heard by someone) that is emitted
--   when an activation causes an item to expire; no spam is emitted if a
--   projectile; the ending is appended without a space in-between
VerbNoLonger :: Text -> Text -> Effect

-- | as <tt>VerbNoLonger</tt> but that is emitted whenever the item is
--   activated;
VerbMsg :: Text -> Text -> Effect

-- | as <tt>VerbMsg</tt>, but a failed effect (returns <tt>UseId</tt>)
VerbMsgFail :: Text -> Text -> Effect
data Condition
HpLeq :: Int -> Condition
HpGeq :: Int -> Condition
CalmLeq :: Int -> Condition
CalmGeq :: Int -> Condition
TriggeredBy :: ActivationFlag -> Condition
data DetectKind
DetectAll :: DetectKind
DetectActor :: DetectKind
DetectLoot :: DetectKind
DetectExit :: DetectKind
DetectHidden :: DetectKind
DetectEmbed :: DetectKind
DetectStash :: DetectKind

-- | Specification of how to randomly roll a timer at item creation to
--   obtain a fixed timer for the item's lifetime.
data TimerDice

-- | Parameters modifying a throw of a projectile or flight of pushed
--   actor. Not additive and don't start at 0.
data ThrowMod
ThrowMod :: Int -> Int -> Int -> ThrowMod

-- | fly with this percentage of base throw speed
[throwVelocity] :: ThrowMod -> Int

-- | fly for this percentage of 2 turns
[throwLinger] :: ThrowMod -> Int

-- | start flight with this many HP
[throwHP] :: ThrowMod -> Int
data ItemSymbolsUsedInEngine
ItemSymbolsUsedInEngine :: ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ContentSymbol ItemKind -> ItemSymbolsUsedInEngine
[rsymbolProjectile] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolLight] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolTool] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolSpecial] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolGold] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolNecklace] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolRing] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolPotion] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolFlask] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolScroll] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolTorsoArmor] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolMiscArmor] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolClothes] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolShield] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolPolearm] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolEdged] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolHafted] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolWand] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
[rsymbolFood] :: ItemSymbolsUsedInEngine -> ContentSymbol ItemKind
emptyItemSymbolsUsedInEngine :: ItemSymbolsUsedInEngine
boostItemKindList :: SMGen -> [ItemKind] -> [ItemKind]

-- | Whether the effect has a chance of exhibiting any potentially
--   noticeable behaviour, except when the item is destroyed or combined.
--   We assume at least one of <tt>OneOf</tt> effects must be noticeable.
forApplyEffect :: Effect -> Bool

-- | Whether a non-nested effect always applies raw damage.
forDamageEffect :: Effect -> Bool

-- | Whether an item is damaging. Such items may trigger embedded items and
--   may collide with bursting items mid-air.
isDamagingKind :: ItemKind -> Bool
strengthOnCombine :: ItemKind -> [Effect]
strengthOnSmash :: ItemKind -> [Effect]
getDropOrgans :: ItemKind -> [GroupName ItemKind]
getMandatoryPresentAsFromKind :: ItemKind -> Maybe (GroupName ItemKind)
isEffEscape :: Effect -> Bool
isEffEscapeOrAscend :: Effect -> Bool
timeoutAspect :: Aspect -> Bool
orEffect :: Effect -> Bool
onSmashEffect :: Effect -> Bool
onCombineEffect :: Effect -> Bool
alwaysDudEffect :: Effect -> Bool
damageUsefulness :: ItemKind -> Double
verbMsgNoLonger :: Text -> Effect
verbMsgLess :: Text -> Effect
toVelocity :: Int -> Aspect
toLinger :: Int -> Aspect
timerNone :: TimerDice
isTimerNone :: TimerDice -> Bool
foldTimer :: a -> (Dice -> a) -> (Dice -> a) -> TimerDice -> a
toOrganBad :: GroupName ItemKind -> Dice -> Effect
toOrganGood :: GroupName ItemKind -> Dice -> Effect
toOrganNoTimer :: GroupName ItemKind -> Effect

-- | Catch invalid item kind definitions.
validateSingle :: ItemSymbolsUsedInEngine -> ItemKind -> [Text]
mandatoryGroups :: [GroupName ItemKind]
mandatoryGroupsSingleton :: [GroupName ItemKind]
boostItemKind :: ItemKind -> ItemKind
onSmashOrCombineEffect :: Effect -> Bool

-- | Validate all item kinds.
validateAll :: [ItemKind] -> ContentData ItemKind -> [Text]
validateDups :: ItemKind -> Aspect -> [Text]
validateDamage :: Dice -> [Text]
instance GHC.Classes.Eq Game.LambdaHack.Content.ItemKind.Condition
instance GHC.Show.Show Game.LambdaHack.Content.ItemKind.Condition
instance GHC.Classes.Eq Game.LambdaHack.Content.ItemKind.DetectKind
instance GHC.Show.Show Game.LambdaHack.Content.ItemKind.DetectKind
instance GHC.Classes.Eq Game.LambdaHack.Content.ItemKind.TimerDice
instance GHC.Generics.Generic Game.LambdaHack.Content.ItemKind.ThrowMod
instance GHC.Classes.Ord Game.LambdaHack.Content.ItemKind.ThrowMod
instance GHC.Classes.Eq Game.LambdaHack.Content.ItemKind.ThrowMod
instance GHC.Show.Show Game.LambdaHack.Content.ItemKind.ThrowMod
instance GHC.Classes.Eq Game.LambdaHack.Content.ItemKind.Effect
instance GHC.Show.Show Game.LambdaHack.Content.ItemKind.Effect
instance GHC.Show.Show Game.LambdaHack.Content.ItemKind.ItemKind
instance GHC.Classes.Eq Game.LambdaHack.Content.ItemKind.Aspect
instance GHC.Show.Show Game.LambdaHack.Content.ItemKind.Aspect
instance Data.Binary.Class.Binary Game.LambdaHack.Content.ItemKind.ThrowMod
instance Data.Hashable.Class.Hashable Game.LambdaHack.Content.ItemKind.ThrowMod
instance GHC.Show.Show Game.LambdaHack.Content.ItemKind.TimerDice


-- | The type of tile kinds. Every terrain tile in the game is an
--   instantiated tile kind.
module Game.LambdaHack.Content.TileKind
pattern S_UNKNOWN_SPACE :: GroupName TileKind
pattern S_UNKNOWN_OUTER_FENCE :: GroupName TileKind
pattern S_BASIC_OUTER_FENCE :: GroupName TileKind
pattern AQUATIC :: GroupName TileKind

-- | The type of kinds of terrain tiles. See <tt>Tile.hs</tt> for
--   explanation of the absence of a corresponding type <tt>Tile</tt> that
--   would hold particular concrete tiles in the dungeon. Note that tile
--   names (and any other content names) should not be plural (that would
--   lead to "a stairs"), so "road with cobblestones" is fine, but "granite
--   cobblestones" is wrong.
--   
--   Tile kind for unknown space has the minimal <tt>ContentId</tt> index.
--   The <tt>talter</tt> for unknown space is <tt>1</tt> and no other tile
--   kind has that value.
data TileKind
TileKind :: Char -> Text -> Freqs TileKind -> Color -> Color -> Word8 -> [Feature] -> TileKind

-- | map symbol
[tsymbol] :: TileKind -> Char

-- | short description
[tname] :: TileKind -> Text

-- | frequency within groups
[tfreq] :: TileKind -> Freqs TileKind

-- | map color
[tcolor] :: TileKind -> Color

-- | map color when not in FOV
[tcolor2] :: TileKind -> Color

-- | minimal skill needed to activate embeds and, in case of big actors not
--   standing on the tile, to alter the tile in any way
[talter] :: TileKind -> Word8

-- | properties; order matters
[tfeature] :: TileKind -> [Feature]

-- | Marks whether projectiles are permitted to trigger the tile
--   transformation action.
data ProjectileTriggers
ProjYes :: ProjectileTriggers
ProjNo :: ProjectileTriggers

-- | All possible terrain tile features.
data Feature

-- | initially an item of this group is embedded; we assume the item has
--   effects and is supposed to be triggered
Embed :: GroupName ItemKind -> Feature

-- | goes from a closed to closed or open tile when altered
OpenTo :: GroupName TileKind -> Feature

-- | goes from an open to open or closed tile when altered
CloseTo :: GroupName TileKind -> Feature

-- | alters tile, but does not change walkability
ChangeTo :: GroupName TileKind -> Feature

-- | alters tile, as before, using up all listed items from the ground and
--   equipment; the list never empty; for simplicity, such tiles are never
--   taken into account when pathfinding
OpenWith :: ProjectileTriggers -> [(Int, GroupName ItemKind)] -> GroupName TileKind -> Feature
CloseWith :: ProjectileTriggers -> [(Int, GroupName ItemKind)] -> GroupName TileKind -> Feature
ChangeWith :: ProjectileTriggers -> [(Int, GroupName ItemKind)] -> GroupName TileKind -> Feature

-- | when hidden, looks as the unique tile of the group
HideAs :: GroupName TileKind -> Feature

-- | when generating, may be transformed to the unique tile of the group
BuildAs :: GroupName TileKind -> Feature

-- | when generating in opening, can be revealed to belong to the group
RevealAs :: GroupName TileKind -> Feature

-- | when generating in solid wall, can be revealed to belong to the group
ObscureAs :: GroupName TileKind -> Feature

-- | actors can walk through
Walkable :: Feature

-- | actors can see through
Clear :: Feature

-- | is not lit with an ambient light
Dark :: Feature

-- | initial items often generated there
OftenItem :: Feature

-- | initial items very often generated there
VeryOftenItem :: Feature

-- | initial actors often generated there; counterpart of
--   <tt>VeryOftenItem</tt> for dark places
OftenActor :: Feature

-- | no items ever generated there
NoItem :: Feature

-- | no actors ever generated there
NoActor :: Feature

-- | even if otherwise uninteresting, taken into account for triggering by
--   AI
ConsideredByAI :: Feature

-- | used for visible trails throughout the level
Trail :: Feature

-- | in place normal legend and in override, don't roll a tile kind only
--   once per place, but roll for each position; one non-spicy (according
--   to frequencies of non-spicy) and at most one spicy (according to their
--   frequencies) is rolled per place and then, once for each position, one
--   of the two is semi-randomly chosen (according to their individual
--   frequencies only)
Spice :: Feature
makeData :: [TileKind] -> [GroupName TileKind] -> [GroupName TileKind] -> ContentData TileKind
isUknownSpace :: ContentId TileKind -> Bool
unknownId :: ContentId TileKind
isSuspectKind :: TileKind -> Bool
isOpenableKind :: TileKind -> Bool
isClosableKind :: TileKind -> Bool
talterForStairs :: Word8
floorSymbol :: Char
mandatoryGroups :: [GroupName TileKind]
mandatoryGroupsSingleton :: [GroupName TileKind]

-- | Validate a single tile kind.
validateSingle :: TileKind -> [Text]

-- | Validate all tile kinds.
--   
--   We don't check it any more, but if tiles look the same on the map
--   (symbol and color), their substantial features should be the same,
--   too, unless there is a good reason they shouldn't. Otherwise the
--   player has to inspect manually all the tiles with this look to see if
--   any is special. This tends to be tedious. Note that tiles may freely
--   differ wrt text blurb, dungeon generation rules, AI preferences, etc.,
--   whithout causing the tedium.
validateAll :: [TileKind] -> ContentData TileKind -> [Text]
validateDups :: TileKind -> Feature -> [Text]
instance GHC.Classes.Eq Game.LambdaHack.Content.TileKind.ProjectileTriggers
instance GHC.Show.Show Game.LambdaHack.Content.TileKind.ProjectileTriggers
instance GHC.Show.Show Game.LambdaHack.Content.TileKind.TileKind
instance GHC.Classes.Eq Game.LambdaHack.Content.TileKind.Feature
instance GHC.Show.Show Game.LambdaHack.Content.TileKind.Feature


-- | The type of place kinds. Every room in the game is an instantiated
--   place kind.
module Game.LambdaHack.Content.PlaceKind

-- | Parameters for the generation of small areas within a dungeon level.
data PlaceKind
PlaceKind :: Text -> Freqs PlaceKind -> Rarity -> Cover -> Fence -> [Text] -> EnumMap Char (GroupName TileKind) -> EnumMap Char (GroupName TileKind) -> PlaceKind

-- | short description, singular or plural
[pname] :: PlaceKind -> Text

-- | frequency within groups
[pfreq] :: PlaceKind -> Freqs PlaceKind

-- | rarity on given depths
[prarity] :: PlaceKind -> Rarity

-- | how to fill whole place using the corner
[pcover] :: PlaceKind -> Cover

-- | whether to fence place with solid border
[pfence] :: PlaceKind -> Fence

-- | plan of the top-left corner of the place
[ptopLeft] :: PlaceKind -> [Text]

-- | dark legend
[plegendDark] :: PlaceKind -> EnumMap Char (GroupName TileKind)

-- | lit legend
[plegendLit] :: PlaceKind -> EnumMap Char (GroupName TileKind)
makeData :: ContentData TileKind -> [PlaceKind] -> [GroupName PlaceKind] -> [GroupName PlaceKind] -> ContentData PlaceKind

-- | A method of filling the whole area (except for CVerbatim and CMirror,
--   which are just placed in the middle of the area) by transforming a
--   given corner.
data Cover

-- | reflect every other corner, overlapping 1 row and column
CAlternate :: Cover

-- | fill symmetrically 4 corners and stretch their borders
CStretch :: Cover

-- | tile separately and symmetrically quarters of the place
CReflect :: Cover

-- | just build the given interior, without filling the area
CVerbatim :: Cover

-- | build the given interior in one of 4 mirrored variants
CMirror :: Cover

-- | The choice of a fence type for the place.
data Fence

-- | put a solid wall fence around the place
FWall :: Fence

-- | leave an empty space, like the room's floor
FFloor :: Fence

-- | leave an empty space, like the cave's ground
FGround :: Fence

-- | skip the fence and fill all with the place proper
FNone :: Fence

-- | Places are rooms and other dungeon features, their names can be seen
--   on a level map by aiming at a position that is an entry to the place
--   (an individual entrance point, an approach area around the place or a
--   phantom entry not on the map, but only used for statistics to witness
--   the place exists). Entries are proxies for initial places created on
--   the level (which may be otherwise eradicated by burrowing the walls,
--   etc.) and so used for dungeon statistics. The statistics are presented
--   in the <tt>Dashboard/displace place lore</tt> menu.
data PlaceEntry
PEntry :: ContentId PlaceKind -> PlaceEntry
PAround :: ContentId PlaceKind -> PlaceEntry
PExists :: ContentId PlaceKind -> PlaceEntry
deadEndId :: ContentId PlaceKind
overridePlaceKind :: [(Char, GroupName TileKind)] -> PlaceKind -> PlaceKind
override2PlaceKind :: [(Char, GroupName TileKind)] -> [(Char, GroupName TileKind)] -> PlaceKind -> PlaceKind

-- | Catch invalid place kind definitions. In particular, verify that the
--   top-left corner map is rectangular and not empty.
validateSingle :: ContentData TileKind -> PlaceKind -> [Text]

-- | Validate all place kinds.
validateAll :: [PlaceKind] -> ContentData PlaceKind -> [Text]
instance GHC.Classes.Eq Game.LambdaHack.Content.PlaceKind.Cover
instance GHC.Show.Show Game.LambdaHack.Content.PlaceKind.Cover
instance GHC.Classes.Eq Game.LambdaHack.Content.PlaceKind.Fence
instance GHC.Show.Show Game.LambdaHack.Content.PlaceKind.Fence
instance GHC.Show.Show Game.LambdaHack.Content.PlaceKind.PlaceKind
instance GHC.Generics.Generic Game.LambdaHack.Content.PlaceKind.PlaceEntry
instance GHC.Classes.Eq Game.LambdaHack.Content.PlaceKind.PlaceEntry
instance GHC.Show.Show Game.LambdaHack.Content.PlaceKind.PlaceEntry
instance Data.Binary.Class.Binary Game.LambdaHack.Content.PlaceKind.PlaceEntry


-- | The type of game rules and assorted game data.
module Game.LambdaHack.Content.RuleKind

-- | The type of game rules and assorted game data.
data RuleContent
RuleContent :: String -> X -> Y -> Version -> FilePath -> (Text, Config) -> Int -> Int -> FilePath -> Int -> [Text] -> ItemSymbolsUsedInEngine -> RuleContent

-- | title of the game (not lib)
[rtitle] :: RuleContent -> String

-- | maximum level width
[rWidthMax] :: RuleContent -> X

-- | maximum level height
[rHeightMax] :: RuleContent -> Y

-- | version of the game
[rexeVersion] :: RuleContent -> Version

-- | name of the UI config file
[rcfgUIName] :: RuleContent -> FilePath

-- | the default UI settings config file
[rcfgUIDefault] :: RuleContent -> (Text, Config)

-- | game saved that often (not on browser)
[rwriteSaveClips] :: RuleContent -> Int

-- | server switches leader level that often
[rleadLevelClips] :: RuleContent -> Int

-- | name of the scores file
[rscoresFileName] :: RuleContent -> FilePath

-- | what is a close distance between actors
[rnearby] :: RuleContent -> Int

-- | words that can't be dropped from stair name as it goes through levels
[rstairWordCarried] :: RuleContent -> [Text]

-- | item symbols treated specially in engine
[ritemSymbols] :: RuleContent -> ItemSymbolsUsedInEngine
emptyRuleContent :: RuleContent
makeData :: RuleContent -> RuleContent
emptyRuleContentRaw :: RuleContent

-- | Catch invalid rule kind definitions.
validateSingle :: RuleContent -> [Text]


-- | The type of kinds of factions present in a game, both human and
--   computer-controlled.
module Game.LambdaHack.Content.FactionKind

-- | Properties of a particular faction.
data FactionKind
FactionKind :: Text -> Freqs FactionKind -> TeamContinuity -> Freqs ItemKind -> Skills -> Bool -> Bool -> HiCondPoly -> Bool -> Doctrine -> Bool -> Bool -> Bool -> Bool -> [TeamContinuity] -> [TeamContinuity] -> FactionKind

-- | name of the faction
[fname] :: FactionKind -> Text

-- | frequency within groups
[ffreq] :: FactionKind -> Freqs FactionKind

-- | the team the faction identifies with across games and modes
[fteam] :: FactionKind -> TeamContinuity

-- | names of actor groups that may naturally fall under faction's control,
--   e.g., upon spawning; make sure all groups that may ever continuousely
--   generate actors, e.g., through spawning or summoning, are mentioned in
--   at least one faction kind; groups of initial faction actors don't need
--   to be included
[fgroups] :: FactionKind -> Freqs ItemKind

-- | fixed skill modifiers to the non-leader actors; also summed with
--   skills implied by <tt>fdoctrine</tt> (which is not fixed)
[fskillsOther] :: FactionKind -> Skills

-- | the faction can escape the dungeon
[fcanEscape] :: FactionKind -> Bool

-- | the faction declared killed if no actors
[fneverEmpty] :: FactionKind -> Bool

-- | score formula (conditional polynomial)
[fhiCondPoly] :: FactionKind -> HiCondPoly

-- | whether actors have gender
[fhasGender] :: FactionKind -> Bool

-- | initial faction's non-leaders doctrine
[finitDoctrine] :: FactionKind -> Doctrine

-- | spawns fast enough that switching pointman to another level to
--   optimize spawning is a winning tactics, which would spoil the fun, so
--   switching is disabled in UI and AI clients
[fspawnsFast] :: FactionKind -> Bool

-- | whether the faction can have a pointman
[fhasPointman] :: FactionKind -> Bool

-- | does the faction have a UI client (for control or passive observation)
[fhasUI] :: FactionKind -> Bool

-- | is the faction initially under AI control
[finitUnderAI] :: FactionKind -> Bool

-- | teams starting at war with the faction
[fenemyTeams] :: FactionKind -> [TeamContinuity]

-- | teams starting allied with the faction
[falliedTeams] :: FactionKind -> [TeamContinuity]
makeData :: [FactionKind] -> [GroupName FactionKind] -> [GroupName FactionKind] -> ContentData FactionKind

-- | Conditional polynomial representing score calculation for this
--   faction.
type HiCondPoly = [HiSummand]
type HiSummand = (HiPolynomial, [Outcome])
type HiPolynomial = [(HiIndeterminant, Double)]
data HiIndeterminant
HiConst :: HiIndeterminant
HiLoot :: HiIndeterminant
HiSprint :: HiIndeterminant
HiBlitz :: HiIndeterminant
HiSurvival :: HiIndeterminant
HiKill :: HiIndeterminant
HiLoss :: HiIndeterminant

-- | Team continuity index. Starting with 1. See the comment for
--   <tt>FactionId</tt>.
newtype TeamContinuity
TeamContinuity :: Int -> TeamContinuity

-- | Outcome of a game.
data Outcome

-- | the faction escaped the dungeon alive
Escape :: Outcome

-- | the faction won by eliminating all rivals
Conquer :: Outcome

-- | the faction lost the game in another way
Defeated :: Outcome

-- | the faction was eliminated
Killed :: Outcome

-- | game is restarted; the quitter quit
Restart :: Outcome

-- | game is supended
Camping :: Outcome
teamExplorer :: TeamContinuity
hiHeroLong :: HiCondPoly
hiHeroMedium :: HiCondPoly
hiHeroShort :: HiCondPoly
hiDweller :: HiCondPoly
victoryOutcomes :: [Outcome]
deafeatOutcomes :: [Outcome]
nameOutcomePast :: Outcome -> Text
nameOutcomeVerb :: Outcome -> Text
endMessageOutcome :: Outcome -> Text
validateSingle :: FactionKind -> [Text]

-- | Validate game faction kinds together.
validateAll :: [FactionKind] -> ContentData FactionKind -> [Text]
instance GHC.Generics.Generic Game.LambdaHack.Content.FactionKind.TeamContinuity
instance GHC.Enum.Enum Game.LambdaHack.Content.FactionKind.TeamContinuity
instance GHC.Classes.Ord Game.LambdaHack.Content.FactionKind.TeamContinuity
instance GHC.Classes.Eq Game.LambdaHack.Content.FactionKind.TeamContinuity
instance GHC.Show.Show Game.LambdaHack.Content.FactionKind.TeamContinuity
instance GHC.Generics.Generic Game.LambdaHack.Content.FactionKind.HiIndeterminant
instance GHC.Classes.Eq Game.LambdaHack.Content.FactionKind.HiIndeterminant
instance GHC.Show.Show Game.LambdaHack.Content.FactionKind.HiIndeterminant
instance GHC.Generics.Generic Game.LambdaHack.Content.FactionKind.Outcome
instance GHC.Enum.Bounded Game.LambdaHack.Content.FactionKind.Outcome
instance GHC.Enum.Enum Game.LambdaHack.Content.FactionKind.Outcome
instance GHC.Classes.Ord Game.LambdaHack.Content.FactionKind.Outcome
instance GHC.Classes.Eq Game.LambdaHack.Content.FactionKind.Outcome
instance GHC.Show.Show Game.LambdaHack.Content.FactionKind.Outcome
instance GHC.Generics.Generic Game.LambdaHack.Content.FactionKind.FactionKind
instance GHC.Classes.Eq Game.LambdaHack.Content.FactionKind.FactionKind
instance GHC.Show.Show Game.LambdaHack.Content.FactionKind.FactionKind
instance Data.Binary.Class.Binary Game.LambdaHack.Content.FactionKind.FactionKind
instance Data.Binary.Class.Binary Game.LambdaHack.Content.FactionKind.Outcome
instance Data.Binary.Class.Binary Game.LambdaHack.Content.FactionKind.HiIndeterminant
instance Data.Binary.Class.Binary Game.LambdaHack.Content.FactionKind.TeamContinuity


-- | The type of cave kinds. Every level in the game is an instantiated
--   cave kind.
module Game.LambdaHack.Content.CaveKind
pattern DEFAULT_RANDOM :: GroupName CaveKind

-- | Parameters for the generation of dungeon levels. Warning: for
--   efficiency, avoid embedded items in any of the common tiles.
data CaveKind
CaveKind :: Text -> Freqs CaveKind -> X -> Y -> DiceXY -> DiceXY -> DiceXY -> Dice -> Dice -> Rational -> Rational -> Chance -> Chance -> Int -> Int -> Freqs ItemKind -> Dice -> Freqs ItemKind -> Freqs PlaceKind -> Bool -> Bool -> GroupName TileKind -> GroupName TileKind -> GroupName TileKind -> GroupName TileKind -> GroupName TileKind -> GroupName TileKind -> GroupName TileKind -> GroupName TileKind -> GroupName TileKind -> Bool -> Int -> Dice -> Freqs PlaceKind -> Freqs PlaceKind -> Freqs PlaceKind -> [Int] -> InitSleep -> Text -> CaveKind

-- | short description
[cname] :: CaveKind -> Text

-- | frequency within groups
[cfreq] :: CaveKind -> Freqs CaveKind

-- | minimal X size of the whole cave
[cXminSize] :: CaveKind -> X

-- | minimal Y size of the whole cave
[cYminSize] :: CaveKind -> Y

-- | size of a map cell holding a place
[ccellSize] :: CaveKind -> DiceXY

-- | minimal size of places; for merging
[cminPlaceSize] :: CaveKind -> DiceXY

-- | maximal size of places; for growing
[cmaxPlaceSize] :: CaveKind -> DiceXY

-- | the odds a place is dark (level-scaled dice roll &gt; 50)
[cdarkOdds] :: CaveKind -> Dice

-- | the odds the cave is dark (level-scaled dice roll &gt; 50)
[cnightOdds] :: CaveKind -> Dice

-- | a proportion of extra connections
[cauxConnects] :: CaveKind -> Rational

-- | at most this proportion of rooms may be void
[cmaxVoid] :: CaveKind -> Rational

-- | the chance of a door in an opening
[cdoorChance] :: CaveKind -> Chance

-- | if there's a door, is it open?
[copenChance] :: CaveKind -> Chance

-- | if not open, hidden one in n times
[chidden] :: CaveKind -> Int

-- | the lower, the more monsters spawn
[cactorCoeff] :: CaveKind -> Int

-- | actor groups to consider
[cactorFreq] :: CaveKind -> Freqs ItemKind

-- | number of initial items in the cave
[citemNum] :: CaveKind -> Dice

-- | item groups to consider; note that the groups are flattened; e.g., if
--   an item is moved to another included group with the same weight, the
--   outcome doesn't change
[citemFreq] :: CaveKind -> Freqs ItemKind

-- | place groups to consider
[cplaceFreq] :: CaveKind -> Freqs PlaceKind

-- | are passable default tiles permitted
[cpassable] :: CaveKind -> Bool

-- | waste of time for AI to explore
[clabyrinth] :: CaveKind -> Bool

-- | the default cave tile
[cdefTile] :: CaveKind -> GroupName TileKind

-- | the dark cave corridor tile
[cdarkCorTile] :: CaveKind -> GroupName TileKind

-- | the lit cave corridor tile
[clitCorTile] :: CaveKind -> GroupName TileKind

-- | the tile used for <tt>FWall</tt> fence
[cwallTile] :: CaveKind -> GroupName TileKind

-- | tile used for the fence corners
[ccornerTile] :: CaveKind -> GroupName TileKind

-- | the outer fence N wall
[cfenceTileN] :: CaveKind -> GroupName TileKind

-- | the outer fence E wall
[cfenceTileE] :: CaveKind -> GroupName TileKind

-- | the outer fence S wall
[cfenceTileS] :: CaveKind -> GroupName TileKind

-- | the outer fence W wall
[cfenceTileW] :: CaveKind -> GroupName TileKind

-- | are places touching fence banned
[cfenceApart] :: CaveKind -> Bool

-- | minimal distance between stairs
[cminStairDist] :: CaveKind -> Int

-- | maximum number of stairs
[cmaxStairsNum] :: CaveKind -> Dice

-- | escape groups, if any
[cescapeFreq] :: CaveKind -> Freqs PlaceKind

-- | place groups for created stairs
[cstairFreq] :: CaveKind -> Freqs PlaceKind

-- | extra groups for inherited
[cstairAllowed] :: CaveKind -> Freqs PlaceKind

-- | which faction starting positions to skip
[cskip] :: CaveKind -> [Int]

-- | whether actors spawn sleeping
[cinitSleep] :: CaveKind -> InitSleep

-- | full cave description
[cdesc] :: CaveKind -> Text
data InitSleep
InitSleepAlways :: InitSleep
InitSleepPermitted :: InitSleep
InitSleepBanned :: InitSleep
makeData :: RuleContent -> [CaveKind] -> [GroupName CaveKind] -> [GroupName CaveKind] -> ContentData CaveKind

-- | Catch caves with not enough space for all the places. Check the size
--   of the cave descriptions to make sure they fit on screen. Etc.
validateSingle :: RuleContent -> CaveKind -> [Text]

-- | Validate all cave kinds. Note that names don't have to be unique: we
--   can have several variants of a cave with a given name.
validateAll :: [CaveKind] -> ContentData CaveKind -> [Text]
mandatoryGroups :: [GroupName CaveKind]
instance GHC.Classes.Eq Game.LambdaHack.Content.CaveKind.InitSleep
instance GHC.Show.Show Game.LambdaHack.Content.CaveKind.InitSleep
instance GHC.Show.Show Game.LambdaHack.Content.CaveKind.CaveKind


-- | The type of game modes.
module Game.LambdaHack.Content.ModeKind
pattern CAMPAIGN_SCENARIO :: GroupName ModeKind
pattern INSERT_COIN :: GroupName ModeKind

-- | Game mode specification.
data ModeKind
ModeKind :: Text -> Freqs ModeKind -> Bool -> Bool -> Roster -> Caves -> [(Outcome, Text)] -> Text -> Text -> Text -> Text -> ModeKind

-- | short description
[mname] :: ModeKind -> Text

-- | frequency within groups
[mfreq] :: ModeKind -> Freqs ModeKind

-- | whether to show tutorial messages, etc.
[mtutorial] :: ModeKind -> Bool

-- | whether this is an attract mode
[mattract] :: ModeKind -> Bool

-- | factions taking part in the game
[mroster] :: ModeKind -> Roster

-- | arena of the game
[mcaves] :: ModeKind -> Caves

-- | messages displayed at each particular game ends; if message empty, the
--   screen is skipped
[mendMsg] :: ModeKind -> [(Outcome, Text)]

-- | rules note
[mrules] :: ModeKind -> Text

-- | description
[mdesc] :: ModeKind -> Text

-- | why/when the mode should be played
[mreason] :: ModeKind -> Text

-- | hints in case player faces difficulties
[mhint] :: ModeKind -> Text
makeData :: ContentData FactionKind -> [ModeKind] -> [GroupName ModeKind] -> [GroupName ModeKind] -> ContentData ModeKind

-- | Requested cave groups for particular level intervals.
type Caves = [([Int], [GroupName CaveKind])]

-- | The specification of factions and of levels, numbers and groups of
--   their initial members.
type Roster = [(GroupName FactionKind, [(Int, Dice, GroupName ItemKind)])]
mandatoryGroups :: [GroupName ModeKind]

-- | Catch invalid game mode kind definitions.
validateSingle :: ContentData FactionKind -> ModeKind -> [Text]

-- | Validate game mode kinds together.
validateAll :: [ModeKind] -> ContentData ModeKind -> [Text]

-- | Checks, in particular, that there is at least one faction with
--   fneverEmpty or the game would get stuck as soon as the dungeon is
--   devoid of actors.
validateSingleRoster :: ContentData FactionKind -> Caves -> Roster -> [Text]
instance GHC.Show.Show Game.LambdaHack.Content.ModeKind.ModeKind


-- | Operations concerning dungeon level tiles.
--   
--   Unlike for many other content types, there is no type <tt>Tile</tt>,
--   of particular concrete tiles in the dungeon, corresponding to
--   <a>TileKind</a> (the type of kinds of terrain tiles). This is because
--   the tiles are too numerous and there's not enough storage space for a
--   well-rounded <tt>Tile</tt> type, on one hand, and on the other hand,
--   tiles are accessed too often in performance critical code to try to
--   compress their representation and/or recompute them. Instead, of
--   defining a <tt>Tile</tt> type, we express various properties of
--   concrete tiles by arrays or sparse EnumMaps, as appropriate.
--   
--   Actors at normal speed (2 m/s) take one turn to move one tile (1 m by
--   1 m).
module Game.LambdaHack.Common.Tile

-- | A lot of tabulated maps from tile kind identifier to a property of the
--   tile kind.
data TileSpeedup
TileSpeedup :: Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Bool -> Tab Word8 -> Tab Word8 -> TileSpeedup
[isClearTab] :: TileSpeedup -> Tab Bool
[isLitTab] :: TileSpeedup -> Tab Bool
[isHideoutTab] :: TileSpeedup -> Tab Bool
[isWalkableTab] :: TileSpeedup -> Tab Bool
[isDoorTab] :: TileSpeedup -> Tab Bool
[isOpenableTab] :: TileSpeedup -> Tab Bool
[isClosableTab] :: TileSpeedup -> Tab Bool
[isChangableTab] :: TileSpeedup -> Tab Bool
[isModifiableWithTab] :: TileSpeedup -> Tab Bool
[isSuspectTab] :: TileSpeedup -> Tab Bool
[isHideAsTab] :: TileSpeedup -> Tab Bool
[consideredByAITab] :: TileSpeedup -> Tab Bool
[isVeryOftenItemTab] :: TileSpeedup -> Tab Bool
[isCommonItemTab] :: TileSpeedup -> Tab Bool
[isOftenActorTab] :: TileSpeedup -> Tab Bool
[isNoItemTab] :: TileSpeedup -> Tab Bool
[isNoActorTab] :: TileSpeedup -> Tab Bool
[isEasyOpenTab] :: TileSpeedup -> Tab Bool
[isEmbedTab] :: TileSpeedup -> Tab Bool
[isAquaticTab] :: TileSpeedup -> Tab Bool
[alterMinSkillTab] :: TileSpeedup -> Tab Word8
[alterMinWalkTab] :: TileSpeedup -> Tab Word8

-- | A map morally indexed by <tt>ContentId TileKind</tt>.
newtype Tab a
Tab :: Vector a -> Tab a
speedupTile :: Bool -> ContentData TileKind -> TileSpeedup

-- | Whether a tile does not block vision. Essential for efficiency of
--   <a>FOV</a>, hence tabulated.
isClear :: TileSpeedup -> ContentId TileKind -> Bool

-- | Whether a tile has ambient light --- is lit on its own. Essential for
--   efficiency of <a>Perception</a>, hence tabulated.
isLit :: TileSpeedup -> ContentId TileKind -> Bool

-- | Whether a tile is a good hideout: walkable and dark.
isHideout :: TileSpeedup -> ContentId TileKind -> Bool

-- | Whether actors can walk into a tile. Essential for efficiency of
--   pathfinding, hence tabulated.
isWalkable :: TileSpeedup -> ContentId TileKind -> Bool

-- | Whether a tile is a door, open or closed. Essential for efficiency of
--   pathfinding, hence tabulated.
isDoor :: TileSpeedup -> ContentId TileKind -> Bool

-- | Whether a tile is changable.
isChangable :: TileSpeedup -> ContentId TileKind -> Bool

-- | Whether a tile is suspect. Essential for efficiency of pathfinding,
--   hence tabulated.
isSuspect :: TileSpeedup -> ContentId TileKind -> Bool
isHideAs :: TileSpeedup -> ContentId TileKind -> Bool
consideredByAI :: TileSpeedup -> ContentId TileKind -> Bool

-- | Whether one can easily explore a tile, possibly finding a treasure,
--   either spawned there or dropped there by a (dying from poison) foe.
--   Doors can't be explorable since revealing a secret tile should not
--   change it's explorable status. Also, door explorable status should not
--   depend on whether they are open or not, so that a foe opening a door
--   doesn't force us to backtrack to explore it. Still, a foe that digs
--   through a wall will affect our exploration counter and if content lets
--   walls contain threasure, such backtraking makes sense.
isExplorable :: TileSpeedup -> ContentId TileKind -> Bool
isVeryOftenItem :: TileSpeedup -> ContentId TileKind -> Bool
isCommonItem :: TileSpeedup -> ContentId TileKind -> Bool
isOftenActor :: TileSpeedup -> ContentId TileKind -> Bool
isNoItem :: TileSpeedup -> ContentId TileKind -> Bool
isNoActor :: TileSpeedup -> ContentId TileKind -> Bool

-- | Whether a tile kind (specified by its id) has an <tt>OpenTo</tt>
--   feature or is walkable even without opening.
isEasyOpen :: TileSpeedup -> ContentId TileKind -> Bool
isEmbed :: TileSpeedup -> ContentId TileKind -> Bool
isAquatic :: TileSpeedup -> ContentId TileKind -> Bool
alterMinSkill :: TileSpeedup -> ContentId TileKind -> Int
alterMinWalk :: TileSpeedup -> ContentId TileKind -> Int

-- | Whether a tile kind has the given feature.
kindHasFeature :: Feature -> TileKind -> Bool
openTo :: ContentData TileKind -> ContentId TileKind -> Rnd (ContentId TileKind)
closeTo :: ContentData TileKind -> ContentId TileKind -> Rnd (ContentId TileKind)
embeddedItems :: ContentData TileKind -> ContentId TileKind -> [GroupName ItemKind]
revealAs :: ContentData TileKind -> ContentId TileKind -> Rnd (ContentId TileKind)
obscureAs :: ContentData TileKind -> ContentId TileKind -> Rnd (ContentId TileKind)
hideAs :: ContentData TileKind -> ContentId TileKind -> Maybe (ContentId TileKind)
buildAs :: ContentData TileKind -> ContentId TileKind -> ContentId TileKind
isEasyOpenKind :: TileKind -> Bool

-- | Whether a tile kind (specified by its id) has an <tt>OpenTo</tt>
--   feature.
isOpenable :: TileSpeedup -> ContentId TileKind -> Bool

-- | Whether a tile kind (specified by its id) has a <tt>CloseTo</tt>
--   feature.
isClosable :: TileSpeedup -> ContentId TileKind -> Bool
isModifiable :: TileSpeedup -> ContentId TileKind -> Bool
createTab :: Unbox a => ContentData TileKind -> (TileKind -> a) -> Tab a
createTabWithKey :: Unbox a => ContentData TileKind -> (ContentId TileKind -> TileKind -> a) -> Tab a
accessTab :: Unbox a => Tab a -> ContentId TileKind -> a
alterMinSkillKind :: ContentId TileKind -> TileKind -> Word8
alterMinWalkKind :: ContentId TileKind -> TileKind -> Word8


-- | The type of item aspects and its operations.
module Game.LambdaHack.Common.ItemAspect

-- | Record of skills conferred by an item as well as of item flags and
--   other item aspects.
data AspectRecord
AspectRecord :: Int -> Skills -> Flags -> Text -> ThrowMod -> Maybe (GroupName ItemKind) -> Maybe EqpSlot -> AspectRecord
[aTimeout] :: AspectRecord -> Int
[aSkills] :: AspectRecord -> Skills
[aFlags] :: AspectRecord -> Flags
[aELabel] :: AspectRecord -> Text
[aToThrow] :: AspectRecord -> ThrowMod
[aPresentAs] :: AspectRecord -> Maybe (GroupName ItemKind)
[aEqpSlot] :: AspectRecord -> Maybe EqpSlot

-- | Partial information about an item, deduced from its item kind. These
--   are assigned to each <a>ItemKind</a>. The <tt>kmConst</tt> flag says
--   whether the item's aspect record is constant rather than random or
--   dependent on item creation dungeon level.
data KindMean
KindMean :: Bool -> AspectRecord -> KindMean

-- | whether the item doesn't need second identification
[kmConst] :: KindMean -> Bool

-- | mean value of item's possible aspect records
[kmMean] :: KindMean -> AspectRecord
emptyAspectRecord :: AspectRecord
addMeanAspect :: AspectRecord -> Aspect -> AspectRecord
castAspect :: AbsDepth -> AbsDepth -> AspectRecord -> Aspect -> Rnd AspectRecord
aspectsRandom :: [Aspect] -> Bool
aspectRecordToList :: AspectRecord -> [Aspect]
rollAspectRecord :: [Aspect] -> AbsDepth -> AbsDepth -> Rnd AspectRecord
getSkill :: Skill -> AspectRecord -> Int
checkFlag :: Flag -> AspectRecord -> Bool
meanAspect :: ItemKind -> AspectRecord
onlyMinorEffects :: AspectRecord -> ItemKind -> Bool
itemTrajectory :: AspectRecord -> ItemKind -> [Point] -> ([Vector], (Speed, Int))
totalRange :: AspectRecord -> ItemKind -> Int
isHumanTrinket :: ItemKind -> Bool
goesIntoEqp :: AspectRecord -> Bool
loreFromContainer :: AspectRecord -> Container -> SLore
ceilingMeanDice :: Dice -> Int
instance GHC.Generics.Generic Game.LambdaHack.Common.ItemAspect.AspectRecord
instance GHC.Classes.Ord Game.LambdaHack.Common.ItemAspect.AspectRecord
instance GHC.Classes.Eq Game.LambdaHack.Common.ItemAspect.AspectRecord
instance GHC.Show.Show Game.LambdaHack.Common.ItemAspect.AspectRecord
instance GHC.Classes.Ord Game.LambdaHack.Common.ItemAspect.KindMean
instance GHC.Classes.Eq Game.LambdaHack.Common.ItemAspect.KindMean
instance GHC.Show.Show Game.LambdaHack.Common.ItemAspect.KindMean
instance Data.Hashable.Class.Hashable Game.LambdaHack.Common.ItemAspect.AspectRecord
instance Data.Binary.Class.Binary Game.LambdaHack.Common.ItemAspect.AspectRecord


-- | Factions taking part in the game, e.g., a hero faction, a monster
--   faction and an animal faction.
module Game.LambdaHack.Common.Faction

-- | All factions in the game, indexed by faction identifier.
type FactionDict = EnumMap FactionId Faction

-- | The faction datatype.
data Faction
Faction :: FactionKind -> Text -> Color -> Doctrine -> Bool -> [(Int, Int, GroupName ItemKind)] -> Dipl -> Maybe Status -> Maybe ActorId -> Maybe (LevelId, Point) -> EnumMap (ContentId ItemKind) Int -> Faction

-- | the player spec for this faction, do not update! it is morally
--   read-only, but not represented as <tt>ContentId FactionKind</tt>,
--   because it's very small and it's looked up often enough in the code
--   and during runtime; a side-effect is that if content changes mid-game,
--   this stays; if we ever have thousands of factions in a single game,
--   e.g., one for each separately spawned herd of animals, change this
[gkind] :: Faction -> FactionKind

-- | individual name
[gname] :: Faction -> Text

-- | color of numbered actors
[gcolor] :: Faction -> Color

-- | non-pointmen behave according to this
[gdoctrine] :: Faction -> Doctrine

-- | whether the faction is under AI control
[gunderAI] :: Faction -> Bool

-- | initial actors
[ginitial] :: Faction -> [(Int, Int, GroupName ItemKind)]

-- | diplomatic standing
[gdipl] :: Faction -> Dipl

-- | cause of game end/exit
[gquit] :: Faction -> Maybe Status

-- | the leader of the faction; don't use in place of sleader on clients
[_gleader] :: Faction -> Maybe ActorId

-- | level and position of faction's shared inventory stash
[gstash] :: Faction -> Maybe (LevelId, Point)

-- | members killed
[gvictims] :: Faction -> EnumMap (ContentId ItemKind) Int

-- | Diplomacy states. Higher overwrite lower in case of asymmetric
--   content.
data Diplomacy
Unknown :: Diplomacy
Neutral :: Diplomacy
Alliance :: Diplomacy
War :: Diplomacy

-- | Current game status.
data Status
Status :: Outcome -> Int -> Maybe (GroupName ModeKind) -> Status

-- | current game outcome
[stOutcome] :: Status -> Outcome

-- | depth of the final encounter
[stDepth] :: Status -> Int

-- | new game group to start, if any
[stNewGame] :: Status -> Maybe (GroupName ModeKind)

-- | The difficulty level influencess HP of either the human player or the
--   AI. The challenges restrict some abilities of the human player only.
data Challenge
Challenge :: Int -> Bool -> Bool -> Bool -> Bool -> Challenge

-- | game difficulty level (HP bonus or malus)
[cdiff] :: Challenge -> Int

-- | cold fish challenge (no healing from enemies)
[cfish] :: Challenge -> Bool

-- | ready goods challenge (crafting disabled)
[cgoods] :: Challenge -> Bool

-- | lone wolf challenge (only one starting character)
[cwolf] :: Challenge -> Bool

-- | finder keeper challenge (ranged attacks disabled)
[ckeeper] :: Challenge -> Bool
tshowDiplomacy :: Diplomacy -> Text
tshowChallenge :: Challenge -> Text
gleader :: Faction -> Maybe ActorId

-- | Tell whether the faction consists of summoned horrors only.
--   
--   Horror player is special, for summoned actors that don't belong to any
--   of the main players of a given game. E.g., animals summoned during a
--   skirmish game between two hero factions land in the horror faction. In
--   every game, either all factions for which summoning items exist should
--   be present or a horror player should be added to host them.
isHorrorFact :: Faction -> Bool
noRunWithMulti :: Faction -> Bool
bannedPointmanSwitchBetweenLevels :: Faction -> Bool

-- | Check if factions are at war. Assumes symmetry.
isFoe :: FactionId -> Faction -> FactionId -> Bool

-- | Check if factions are allied or are the same faction. Assumes
--   symmetry.
isFriend :: FactionId -> Faction -> FactionId -> Bool
difficultyBound :: Int
difficultyDefault :: Int
difficultyCoeff :: Int -> Int
defaultChallenge :: Challenge
possibleActorFactions :: [GroupName ItemKind] -> ItemKind -> FactionDict -> Frequency (FactionId, Faction)
ppContainer :: FactionDict -> Container -> Text
type Dipl = EnumMap FactionId Diplomacy
instance GHC.Generics.Generic Game.LambdaHack.Common.Faction.Diplomacy
instance GHC.Enum.Enum Game.LambdaHack.Common.Faction.Diplomacy
instance GHC.Classes.Ord Game.LambdaHack.Common.Faction.Diplomacy
instance GHC.Classes.Eq Game.LambdaHack.Common.Faction.Diplomacy
instance GHC.Show.Show Game.LambdaHack.Common.Faction.Diplomacy
instance GHC.Generics.Generic Game.LambdaHack.Common.Faction.Status
instance GHC.Classes.Ord Game.LambdaHack.Common.Faction.Status
instance GHC.Classes.Eq Game.LambdaHack.Common.Faction.Status
instance GHC.Show.Show Game.LambdaHack.Common.Faction.Status
instance GHC.Generics.Generic Game.LambdaHack.Common.Faction.Faction
instance GHC.Classes.Eq Game.LambdaHack.Common.Faction.Faction
instance GHC.Show.Show Game.LambdaHack.Common.Faction.Faction
instance GHC.Generics.Generic Game.LambdaHack.Common.Faction.Challenge
instance GHC.Classes.Ord Game.LambdaHack.Common.Faction.Challenge
instance GHC.Classes.Eq Game.LambdaHack.Common.Faction.Challenge
instance GHC.Show.Show Game.LambdaHack.Common.Faction.Challenge
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Faction.Challenge
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Faction.Faction
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Faction.Status
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Faction.Diplomacy


-- | High score table operations.
module Game.LambdaHack.Common.HighScore

-- | The list of scores, in decreasing order.
data ScoreTable

-- | A dictionary from game mode IDs to scores tables.
type ScoreDict = EnumMap (ContentId ModeKind) ScoreTable

-- | Empty score table
empty :: ScoreDict

-- | Register a new score in a score table.
register :: ScoreTable -> Int -> Int -> Time -> Status -> POSIXTime -> Challenge -> Text -> EnumMap (ContentId ItemKind) Int -> EnumMap (ContentId ItemKind) Int -> HiCondPoly -> (Bool, (ScoreTable, Int))

-- | Show a single high score, from the given ranking in the high score
--   table.
showScore :: TimeZone -> Int -> ScoreRecord -> [Text]
showAward :: Int -> ScoreTable -> Int -> Text -> Text
getTable :: ContentId ModeKind -> ScoreDict -> ScoreTable
unTable :: ScoreTable -> [ScoreRecord]
getRecord :: Int -> ScoreTable -> ScoreRecord
getStatus :: ScoreRecord -> Status
getDate :: ScoreRecord -> POSIXTime

-- | A single score record. Records are ordered in the highscore table,
--   from the best to the worst, in lexicographic ordering wrt the fields
--   below.
data ScoreRecord

-- | Insert a new score into the table, Return new table and the ranking.
--   Make sure the table doesn't grow too large.
insertPos :: ScoreRecord -> ScoreTable -> (ScoreTable, Int)
instance GHC.Generics.Generic Game.LambdaHack.Common.HighScore.ScoreRecord
instance GHC.Classes.Ord Game.LambdaHack.Common.HighScore.ScoreRecord
instance GHC.Classes.Eq Game.LambdaHack.Common.HighScore.ScoreRecord
instance Data.Binary.Class.Binary Game.LambdaHack.Common.HighScore.ScoreTable
instance GHC.Classes.Eq Game.LambdaHack.Common.HighScore.ScoreTable
instance GHC.Show.Show Game.LambdaHack.Common.HighScore.ScoreTable
instance Data.Binary.Class.Binary Game.LambdaHack.Common.HighScore.ScoreRecord


-- | Slideshows.
module Game.LambdaHack.Client.UI.Slideshow
type FontOverlayMap = EnumMap DisplayFont Overlay
maxYofFontOverlayMap :: FontOverlayMap -> Int
type KeyOrSlot = Either KM MenuSlot
data MenuSlot
natSlots :: [MenuSlot]

-- | Width of on-screen button text, expressed in characters, and so UI
--   (mono font) width is deduced from the used font.
data ButtonWidth
ButtonWidth :: DisplayFont -> Int -> ButtonWidth
[buttonFont] :: ButtonWidth -> DisplayFont
[buttonWidth] :: ButtonWidth -> Int

-- | A key or a menu slot at a given position on the screen.
type KYX = (KeyOrSlot, (PointUI, ButtonWidth))
xytranslateKXY :: Int -> Int -> KYX -> KYX
xtranslateKXY :: Int -> KYX -> KYX
ytranslateKXY :: Int -> KYX -> KYX
yrenumberKXY :: Int -> KYX -> KYX

-- | An Overlay of text with an associated list of keys or slots that
--   activate when the specified screen position is pointed at. The list
--   should be sorted wrt rows and then columns.
type OKX = (FontOverlayMap, [KYX])
emptyOKX :: OKX
xytranslateOKX :: Int -> Int -> OKX -> OKX
sideBySideOKX :: Int -> Int -> OKX -> OKX -> OKX
labDescOKX :: DisplayFont -> DisplayFont -> [(AttrString, AttrString, KeyOrSlot)] -> OKX

-- | A list of active screenfulls to be shown one after another. Each
--   screenful has an independent numbering of rows and columns.
data Slideshow
emptySlideshow :: Slideshow
unsnocSlideshow :: Slideshow -> Maybe (Slideshow, OKX)
toSlideshow :: FontSetup -> Bool -> [OKX] -> Slideshow

-- | This appends vertically a list of blurbs into a single font overlay
--   map. Not to be used if some blurbs need to be places overlapping
--   vertically, e.g., when the square font symbol needs to be in the same
--   line as the start of the descritpion of the denoted item or when mono
--   font buttons need to be after a prompt.
attrLinesToFontMap :: [(DisplayFont, [AttrLine])] -> FontOverlayMap
menuToSlideshow :: OKX -> Slideshow
wrapOKX :: DisplayFont -> Int -> Int -> Int -> [(KM, String)] -> (Overlay, [KYX])
splitOverlay :: FontSetup -> Bool -> Int -> Int -> Int -> Report -> [KM] -> OKX -> Slideshow
splitOKX :: FontSetup -> Bool -> Int -> Int -> Int -> AttrString -> [KM] -> OKX -> [OKX]

-- | Generate a slideshow with the current and previous scores.
highSlideshow :: FontSetup -> Bool -> Int -> Int -> ScoreTable -> Int -> Text -> TimeZone -> Slideshow
keysOKX :: DisplayFont -> Int -> Int -> Int -> [KM] -> (Overlay, [KYX])

-- | Show a screenful of the high scores table. Parameter <tt>entries</tt>
--   is the number of (3-line) scores to be shown.
showTable :: TimeZone -> Int -> ScoreTable -> Int -> Int -> [AttrLine]

-- | Produce a couple of renderings of the high scores table.
showNearbyScores :: TimeZone -> Int -> ScoreTable -> Int -> [[AttrLine]]
instance GHC.Enum.Enum Game.LambdaHack.Client.UI.Slideshow.MenuSlot
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.Slideshow.MenuSlot
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.Slideshow.MenuSlot
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Slideshow.MenuSlot
instance GHC.Show.Show Game.LambdaHack.Client.UI.Slideshow.MenuSlot
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Slideshow.ButtonWidth
instance GHC.Show.Show Game.LambdaHack.Client.UI.Slideshow.ButtonWidth
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Slideshow.Slideshow
instance GHC.Show.Show Game.LambdaHack.Client.UI.Slideshow.Slideshow


-- | Abstract syntax of requests.
--   
--   See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Client-server-architecture</a>.
module Game.LambdaHack.Client.Request

-- | Requests sent by AI clients to the server. If faction leader is to be
--   changed, it's included as the second component.
type RequestAI = (ReqAI, Maybe ActorId)

-- | Possible forms of requests sent by AI clients.
data ReqAI
ReqAINop :: ReqAI
ReqAITimed :: RequestTimed -> ReqAI

-- | Requests sent by UI clients to the server. If faction leader is to be
--   changed, it's included as the second component.
type RequestUI = (ReqUI, Maybe ActorId)

-- | Possible forms of requests sent by UI clients.
data ReqUI
ReqUINop :: ReqUI
ReqUITimed :: RequestTimed -> ReqUI
ReqUIGameRestart :: GroupName ModeKind -> Challenge -> ReqUI
ReqUIGameDropAndExit :: ReqUI
ReqUIGameSaveAndExit :: ReqUI
ReqUIGameSave :: ReqUI
ReqUIDoctrine :: Doctrine -> ReqUI
ReqUIAutomate :: ReqUI

-- | Requests that take game time.
data RequestTimed
ReqMove :: Vector -> RequestTimed
ReqMelee :: ActorId -> ItemId -> CStore -> RequestTimed
ReqDisplace :: ActorId -> RequestTimed
ReqAlter :: Point -> RequestTimed
ReqWait :: RequestTimed
ReqWait10 :: RequestTimed
ReqYell :: RequestTimed
ReqMoveItems :: [(ItemId, Int, CStore, CStore)] -> RequestTimed
ReqProject :: Point -> Int -> ItemId -> CStore -> RequestTimed
ReqApply :: ItemId -> CStore -> RequestTimed
instance GHC.Show.Show Game.LambdaHack.Client.Request.RequestTimed
instance GHC.Show.Show Game.LambdaHack.Client.Request.ReqUI
instance GHC.Show.Show Game.LambdaHack.Client.Request.ReqAI


-- | Abstract syntax of human player commands.
module Game.LambdaHack.Client.UI.HumanCmd
data CmdCategory
CmdDashboard :: CmdCategory
CmdItemMenu :: CmdCategory
CmdMove :: CmdCategory
CmdItem :: CmdCategory
CmdAim :: CmdCategory
CmdMeta :: CmdCategory
CmdMouse :: CmdCategory
CmdInternal :: CmdCategory
CmdDebug :: CmdCategory
CmdMinimal :: CmdCategory
categoryDescription :: CmdCategory -> Text

-- | Symbolic representation of areas of the screen used to define the
--   meaning of mouse button presses relative to where the mouse points to.
data CmdArea
CaMessage :: CmdArea
CaMapLeader :: CmdArea
CaMapParty :: CmdArea
CaMap :: CmdArea
CaLevelNumber :: CmdArea
CaArenaName :: CmdArea
CaPercentSeen :: CmdArea
CaXhairDesc :: CmdArea
CaSelected :: CmdArea
CaCalmGauge :: CmdArea
CaCalmValue :: CmdArea
CaHPGauge :: CmdArea
CaHPValue :: CmdArea
CaLeaderDesc :: CmdArea
areaDescription :: CmdArea -> Text

-- | This triple of command categories, description and the command term
--   itself defines the meaning of a human command as entered via a
--   keypress, mouse click or chosen from a menu.
type CmdTriple = ([CmdCategory], Text, HumanCmd)
data AimModeCmd
AimModeCmd :: HumanCmd -> HumanCmd -> AimModeCmd
[exploration] :: AimModeCmd -> HumanCmd
[aiming] :: AimModeCmd -> HumanCmd

-- | Abstract syntax of human player commands.
data HumanCmd
Macro :: [String] -> HumanCmd
ByArea :: [(CmdArea, HumanCmd)] -> HumanCmd
ByAimMode :: AimModeCmd -> HumanCmd
ComposeIfLocal :: HumanCmd -> HumanCmd -> HumanCmd
ComposeUnlessError :: HumanCmd -> HumanCmd -> HumanCmd
Compose2ndLocal :: HumanCmd -> HumanCmd -> HumanCmd
LoopOnNothing :: HumanCmd -> HumanCmd
ExecuteIfClear :: HumanCmd -> HumanCmd
Wait :: HumanCmd
Wait10 :: HumanCmd
Yell :: HumanCmd
MoveDir :: Vector -> HumanCmd
RunDir :: Vector -> HumanCmd
RunOnceAhead :: HumanCmd
MoveOnceToXhair :: HumanCmd
RunOnceToXhair :: HumanCmd
ContinueToXhair :: HumanCmd
MoveItem :: [CStore] -> CStore -> Maybe Text -> Bool -> HumanCmd
Project :: HumanCmd
Apply :: HumanCmd
AlterDir :: HumanCmd
AlterWithPointer :: HumanCmd
CloseDir :: HumanCmd
Help :: HumanCmd
Hint :: HumanCmd
ItemMenu :: HumanCmd
MainMenu :: HumanCmd
MainMenuAutoOn :: HumanCmd
MainMenuAutoOff :: HumanCmd
Dashboard :: HumanCmd
GameDifficultyIncr :: Int -> HumanCmd
GameFishToggle :: HumanCmd
GameGoodsToggle :: HumanCmd
GameWolfToggle :: HumanCmd
GameKeeperToggle :: HumanCmd
GameScenarioIncr :: Int -> HumanCmd
GameRestart :: HumanCmd
GameQuit :: HumanCmd
GameDrop :: HumanCmd
GameExit :: HumanCmd
GameSave :: HumanCmd
Doctrine :: HumanCmd
Automate :: HumanCmd
AutomateToggle :: HumanCmd
AutomateBack :: HumanCmd
ChooseItem :: ItemDialogMode -> HumanCmd
ChooseItemMenu :: ItemDialogMode -> HumanCmd
ChooseItemProject :: [TriggerItem] -> HumanCmd
ChooseItemApply :: [TriggerItem] -> HumanCmd
PickLeader :: Int -> HumanCmd
PickLeaderWithPointer :: HumanCmd
PointmanCycle :: Direction -> HumanCmd
PointmanCycleLevel :: Direction -> HumanCmd
SelectActor :: HumanCmd
SelectNone :: HumanCmd
SelectWithPointer :: HumanCmd
Repeat :: Int -> HumanCmd
RepeatLast :: Int -> HumanCmd
Record :: HumanCmd
AllHistory :: HumanCmd
MarkVision :: Int -> HumanCmd
MarkSmell :: HumanCmd
MarkSuspect :: Int -> HumanCmd
MarkAnim :: HumanCmd
OverrideTut :: Int -> HumanCmd
SettingsMenu :: HumanCmd
ChallengeMenu :: HumanCmd
PrintScreen :: HumanCmd
Cancel :: HumanCmd
Accept :: HumanCmd
DetailCycle :: HumanCmd
ClearTargetIfItemClear :: HumanCmd
ItemClear :: HumanCmd
MoveXhair :: Vector -> Int -> HumanCmd
AimTgt :: HumanCmd
AimFloor :: HumanCmd
AimEnemy :: HumanCmd
AimItem :: HumanCmd
AimAscend :: Int -> HumanCmd
EpsIncr :: Direction -> HumanCmd
XhairUnknown :: HumanCmd
XhairItem :: HumanCmd
XhairStair :: Bool -> HumanCmd
XhairPointerFloor :: HumanCmd
XhairPointerMute :: HumanCmd
XhairPointerEnemy :: HumanCmd
AimPointerFloor :: HumanCmd
AimPointerEnemy :: HumanCmd

-- | Description of how item manipulation is triggered and communicated to
--   the player.
data TriggerItem
TriggerItem :: Part -> Part -> [ContentSymbol ItemKind] -> TriggerItem
[tiverb] :: TriggerItem -> Part
[tiobject] :: TriggerItem -> Part
[tisymbols] :: TriggerItem -> [ContentSymbol ItemKind]
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.HumanCmd.CmdCategory
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.HumanCmd.CmdCategory
instance GHC.Read.Read Game.LambdaHack.Client.UI.HumanCmd.CmdCategory
instance GHC.Show.Show Game.LambdaHack.Client.UI.HumanCmd.CmdCategory
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.HumanCmd.CmdArea
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.HumanCmd.CmdArea
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.HumanCmd.CmdArea
instance GHC.Read.Read Game.LambdaHack.Client.UI.HumanCmd.CmdArea
instance GHC.Show.Show Game.LambdaHack.Client.UI.HumanCmd.CmdArea
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.HumanCmd.TriggerItem
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.HumanCmd.TriggerItem
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.HumanCmd.TriggerItem
instance GHC.Show.Show Game.LambdaHack.Client.UI.HumanCmd.TriggerItem
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.HumanCmd.AimModeCmd
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.HumanCmd.AimModeCmd
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.HumanCmd.AimModeCmd
instance GHC.Read.Read Game.LambdaHack.Client.UI.HumanCmd.AimModeCmd
instance GHC.Show.Show Game.LambdaHack.Client.UI.HumanCmd.AimModeCmd
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.HumanCmd.HumanCmd
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.HumanCmd.HumanCmd
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.HumanCmd.HumanCmd
instance GHC.Read.Read Game.LambdaHack.Client.UI.HumanCmd.HumanCmd
instance GHC.Show.Show Game.LambdaHack.Client.UI.HumanCmd.HumanCmd
instance Control.DeepSeq.NFData Game.LambdaHack.Client.UI.HumanCmd.AimModeCmd
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.HumanCmd.AimModeCmd
instance Control.DeepSeq.NFData Game.LambdaHack.Client.UI.HumanCmd.HumanCmd
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.HumanCmd.HumanCmd
instance GHC.Read.Read Game.LambdaHack.Client.UI.HumanCmd.TriggerItem
instance Control.DeepSeq.NFData Game.LambdaHack.Client.UI.HumanCmd.TriggerItem
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.HumanCmd.TriggerItem
instance Control.DeepSeq.NFData Game.LambdaHack.Client.UI.HumanCmd.CmdArea
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.HumanCmd.CmdArea
instance Control.DeepSeq.NFData Game.LambdaHack.Client.UI.HumanCmd.CmdCategory
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.HumanCmd.CmdCategory


-- | UI client options specified in the config file.
module Game.LambdaHack.Client.UI.UIOptions

-- | Options that affect the UI of the client, specified in the config
--   file. More documentation is in the default config file.
data UIOptions
UIOptions :: [(KM, CmdTriple)] -> [(Int, (Text, Text))] -> Bool -> Bool -> Text -> Double -> FullscreenMode -> Int -> X -> Int -> Double -> Bool -> [String] -> [(Text, FontDefinition)] -> [(Text, FontSet)] -> [(String, Color)] -> UIOptions
[uCommands] :: UIOptions -> [(KM, CmdTriple)]
[uHeroNames] :: UIOptions -> [(Int, (Text, Text))]
[uVi] :: UIOptions -> Bool
[uLeftHand] :: UIOptions -> Bool
[uChosenFontset] :: UIOptions -> Text
[uAllFontsScale] :: UIOptions -> Double
[uFullscreenMode] :: UIOptions -> FullscreenMode
[uhpWarningPercent] :: UIOptions -> Int
[uMsgWrapColumn] :: UIOptions -> X
[uHistoryMax] :: UIOptions -> Int
[uMaxFps] :: UIOptions -> Double
[uNoAnim] :: UIOptions -> Bool
[uOverrideCmdline] :: UIOptions -> [String]
[uFonts] :: UIOptions -> [(Text, FontDefinition)]
[uFontsets] :: UIOptions -> [(Text, FontSet)]
[uMessageColors] :: UIOptions -> [(String, Color)]
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.UIOptions.UIOptions
instance GHC.Show.Show Game.LambdaHack.Client.UI.UIOptions.UIOptions
instance Control.DeepSeq.NFData Game.LambdaHack.Client.UI.UIOptions.UIOptions
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.UIOptions.UIOptions


-- | The type of definitions of key-command mappings to be used for the UI
--   and shorthands for specifying command triples in the content files.
module Game.LambdaHack.Client.UI.Content.Input

-- | Key-command mappings to be specified in content and used for the UI.
newtype InputContentRaw
InputContentRaw :: [(KM, CmdTriple)] -> InputContentRaw

-- | Bindings and other information about human player commands.
data InputContent
InputContent :: Map KM CmdTriple -> [(KM, CmdTriple)] -> Map HumanCmd [KM] -> InputContent

-- | binding of keys to commands
[bcmdMap] :: InputContent -> Map KM CmdTriple

-- | the properly ordered list of commands for the help menu
[bcmdList] :: InputContent -> [(KM, CmdTriple)]

-- | and from commands to their keys
[brevMap] :: InputContent -> Map HumanCmd [KM]

-- | Create binding of keys to movement and other standard commands, as
--   well as commands defined in the config file.
makeData :: Maybe UIOptions -> InputContentRaw -> InputContent
evalKeyDef :: (String, CmdTriple) -> (KM, CmdTriple)
addCmdCategory :: CmdCategory -> CmdTriple -> CmdTriple
replaceDesc :: Text -> CmdTriple -> CmdTriple
moveItemTriple :: [CStore] -> CStore -> Part -> Bool -> CmdTriple
repeatTriple :: Int -> [CmdCategory] -> CmdTriple
repeatLastTriple :: Int -> [CmdCategory] -> CmdTriple
mouseLMB :: HumanCmd -> Text -> CmdTriple
mouseMMB :: CmdTriple
mouseMMBMute :: CmdTriple
mouseRMB :: CmdTriple
goToCmd :: HumanCmd
runToAllCmd :: HumanCmd
autoexploreCmd :: HumanCmd
autoexplore25Cmd :: HumanCmd
aimFlingCmd :: HumanCmd
projectI :: [TriggerItem] -> CmdTriple
projectA :: [TriggerItem] -> CmdTriple

-- | flingTs - list containing one flingable projectile &gt;&gt;&gt;
--   flingTs [TriggerItem {tiverb = Text "fling", tiobject = Text "in-range
--   projectile", tisymbols = ""}]
--   
--   I question the value of that test. But would Bob Martin like it on the
--   grounds it's like double-bookkeeping?
flingTs :: [TriggerItem]
applyIK :: [TriggerItem] -> CmdTriple
applyI :: [TriggerItem] -> CmdTriple
grabItems :: Text -> CmdTriple
dropItems :: Text -> CmdTriple
descIs :: [TriggerItem] -> Text
defaultHeroSelect :: Int -> (String, CmdTriple)
macroRun25 :: [String]
memberCycle :: Direction -> [CmdCategory] -> CmdTriple
memberCycleLevel :: Direction -> [CmdCategory] -> CmdTriple
replaceCmd :: HumanCmd -> CmdTriple -> CmdTriple
projectICmd :: [TriggerItem] -> HumanCmd
grabCmd :: HumanCmd
dropCmd :: HumanCmd


-- | The default game key-command mapping to be used for UI. Can be
--   overridden via macros in the config file.
module Client.UI.Content.Input

-- | Description of default key-command bindings.
--   
--   In addition to these commands, mouse and keys have a standard meaning
--   when navigating various menus.
standardKeysAndMouse :: InputContentRaw
applyTs :: [TriggerItem]


-- | The type of definitions of screen layout and features.
module Game.LambdaHack.Client.UI.Content.Screen

-- | Screen layout and features definition.
--   
--   Warning: this type is not abstract, but its values should not be
--   created ad hoc, even for unit tests, but should be constructed with
--   <tt>makeData</tt>, which includes validation,
--   
--   The <tt>emptyScreenContent</tt> is one such valid by construction
--   value of this type. It's suitable for bootstrapping and for testing.
data ScreenContent
ScreenContent :: X -> Y -> String -> ([String], [[String]]) -> EnumMap (ContentSymbol ItemKind) Text -> [(FilePath, ByteString)] -> ScreenContent

-- | screen width
[rwidth] :: ScreenContent -> X

-- | screen height
[rheight] :: ScreenContent -> Y

-- | an extra blurb line for the main menu
[rwebAddress] :: ScreenContent -> String

-- | the intro screen (first help screen) text and the rest of the manual
[rintroScreen] :: ScreenContent -> ([String], [[String]])

-- | verbs to use for apply actions
[rapplyVerbMap] :: ScreenContent -> EnumMap (ContentSymbol ItemKind) Text

-- | embedded game-supplied font files
[rFontFiles] :: ScreenContent -> [(FilePath, ByteString)]
emptyScreenContent :: ScreenContent
makeData :: RuleContent -> ScreenContent -> ScreenContent
emptyScreenContentRaw :: ScreenContent

-- | Catch invalid rule kind definitions.
validateSingle :: RuleContent -> ScreenContent -> [Text]


-- | Screen frames.
--   
--   Note that <tt>PointArray.Array</tt> here represents a screen frame and
--   so screen positions are denoted by <tt>Point</tt>, contrary to the
--   convention that <tt>Point</tt> refers to game map coordinates, as
--   outlined in description of <a>PointSquare</a> that should normally be
--   used in that role.
module Game.LambdaHack.Client.UI.Frame

-- | Color mode for the display.
data ColorMode

-- | normal, with full colours
ColorFull :: ColorMode

-- | black and white only
ColorBW :: ColorMode
type FrameST s = Mutable Vector s Word32 -> ST s ()

-- | Efficiently composable representation of an operation on a frame, that
--   is, on a mutable vector. When the composite operation is eventually
--   performed, the vector is frozen to become a <a>SingleFrame</a>.
newtype FrameForall
FrameForall :: (forall s. FrameST s) -> FrameForall
[unFrameForall] :: FrameForall -> forall s. FrameST s

-- | Action that results in a base frame, to be modified further.
newtype FrameBase
FrameBase :: (forall s. ST s (Mutable Vector s Word32)) -> FrameBase
[unFrameBase] :: FrameBase -> forall s. ST s (Mutable Vector s Word32)

-- | A frame, that is, a base frame and all its modifications.
type Frame = ((FrameBase, FrameForall), (OverlaySpace, OverlaySpace, OverlaySpace))

-- | Components of a frame, before it's decided if the first can be
--   overwritten in-place or needs to be copied.
type PreFrame3 = (PreFrame, (OverlaySpace, OverlaySpace, OverlaySpace))

-- | Sequence of screen frames, including delays. Potentially based on a
--   single base frame.
type PreFrames3 = [Maybe PreFrame3]

-- | A simpler variant of <tt>PreFrame3</tt>.
type PreFrame = (Vector Word32, FrameForall)

-- | A simpler variant of <tt>PreFrames3</tt>.
type PreFrames = [Maybe PreFrame]

-- | A frame that is padded to fill the whole screen with optional overlays
--   to display in proportional, square and monospace fonts.
--   
--   Note that we don't provide a list of color-highlighed box positions to
--   be drawn separately, because overlays need to obscure not only map,
--   but the highlights as well, so highlights need to be included earlier.
--   
--   See the description of <a>PointSquare</a> for explanation of why
--   screen coordinates in <tt>singleArray</tt> are <tt>Point</tt> even
--   though they should be <a>PointSquare</a>.
data SingleFrame
SingleFrame :: Array AttrCharW32 -> OverlaySpace -> OverlaySpace -> OverlaySpace -> SingleFrame
[singleArray] :: SingleFrame -> Array AttrCharW32
[singlePropOverlay] :: SingleFrame -> OverlaySpace
[singleSquareOverlay] :: SingleFrame -> OverlaySpace
[singleMonoOverlay] :: SingleFrame -> OverlaySpace
type OverlaySpace = [(PointUI, AttrString)]
blankSingleFrame :: ScreenContent -> SingleFrame

-- | Truncate the overlay: for each line, if it's too long, it's truncated
--   and if there are too many lines, excess is dropped and warning is
--   appended. The width, in the second argument, is calculated in
--   characters, not in UI (mono font) coordinates, so that taking and
--   dropping characters is performed correctly.
truncateOverlay :: Bool -> Int -> Int -> Bool -> Int -> Bool -> Overlay -> OverlaySpace

-- | Overlays either the game map only or the whole empty screen frame. We
--   assume the lines of the overlay are not too long nor too many.
overlayFrame :: Int -> OverlaySpace -> PreFrame -> PreFrame

-- | Add a space at the message end, for display overlayed over the level
--   map. Also trim (do not wrap!) too long lines. Also add many spaces
--   when under longer lines.
truncateAttrLine :: Bool -> Int -> Int -> AttrLine -> AttrString
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Frame.ColorMode
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Frame.SingleFrame
instance GHC.Show.Show Game.LambdaHack.Client.UI.Frame.SingleFrame


-- | Screen frames and animations.
module Game.LambdaHack.Client.UI.Frontend.Common

-- | Raw frontend definition. The minimal closed set of values that need to
--   depend on the specifics of the chosen frontend.
data RawFrontend
RawFrontend :: (SingleFrame -> IO ()) -> IO () -> MVar () -> TQueue KMP -> IO () -> ScreenContent -> RawFrontend
[fdisplay] :: RawFrontend -> SingleFrame -> IO ()
[fshutdown] :: RawFrontend -> IO ()
[fshowNow] :: RawFrontend -> MVar ()
[fchanKey] :: RawFrontend -> TQueue KMP
[fprintScreen] :: RawFrontend -> IO ()
[fcoscreen] :: RawFrontend -> ScreenContent

-- | Start up a frontend on a bound thread.
--   
--   In fact, it is started on the very main thread, via a hack, because
--   apparently some SDL backends are not thread-safe
--   (<a>https://wiki.libsdl.org/FAQDevelopment</a>; "this should only be
--   run in the thread that initialized the video subsystem, and for extra
--   safety, you should consider only doing those things on the main thread
--   in any case") and at least the newer OS X obtusely requires the main
--   thread, see
--   <a>https://github.com/AllureOfTheStars/Allure/issues/79</a> In case
--   any other exotic architecture requires the main thread, we make the
--   hack the default for all (on frontends that require a bound thread,
--   e.g., SLD2).
startupBound :: (MVar RawFrontend -> IO ()) -> IO RawFrontend
createRawFrontend :: ScreenContent -> (SingleFrame -> IO ()) -> IO () -> IO RawFrontend

-- | Empty the keyboard channel.
resetChanKey :: TQueue KMP -> IO ()
saveKMP :: RawFrontend -> Modifier -> Key -> PointUI -> IO ()

-- | Translates modifiers to our own encoding.
modifierTranslate :: Bool -> Bool -> Bool -> Bool -> Modifier


-- | Line terminal text frontend based on stdin/stdout, intended for
--   logging tests, but may be used on a teletype terminal, or with
--   keyboard and printer.
module Game.LambdaHack.Client.UI.Frontend.Teletype

-- | Set up the frontend input and output.
startup :: ScreenContent -> IO RawFrontend

-- | The name of the frontend.
frontendName :: String


-- | Text frontend based on SDL2.
module Game.LambdaHack.Client.UI.Frontend.Sdl

-- | Set up and start the main loop providing input and output.
--   
--   Because of Windows and OS X, SDL2 needs to be on a bound thread, so we
--   can't avoid the communication overhead of bound threads.
startup :: ScreenContent -> ClientOptions -> IO RawFrontend

-- | The name of the frontend.
frontendName :: String
type FontAtlas = EnumMap AttrCharW32 Texture

-- | Session data maintained by the frontend.
data FrontendSession
FrontendSession :: Window -> Renderer -> Font -> Int -> Bool -> Maybe Font -> Maybe Font -> Maybe Font -> IORef FontAtlas -> IORef FontAtlas -> IORef Texture -> IORef Texture -> IORef SingleFrame -> IORef Bool -> IORef Bool -> MVar SingleFrame -> MVar () -> FrontendSession
[swindow] :: FrontendSession -> Window
[srenderer] :: FrontendSession -> Renderer
[squareFont] :: FrontendSession -> Font
[squareFontSize] :: FrontendSession -> Int
[mapFontIsBitmap] :: FrontendSession -> Bool
[spropFont] :: FrontendSession -> Maybe Font
[sboldFont] :: FrontendSession -> Maybe Font
[smonoFont] :: FrontendSession -> Maybe Font
[squareAtlas] :: FrontendSession -> IORef FontAtlas
[smonoAtlas] :: FrontendSession -> IORef FontAtlas
[sbasicTexture] :: FrontendSession -> IORef Texture
[stexture] :: FrontendSession -> IORef Texture
[spreviousFrame] :: FrontendSession -> IORef SingleFrame
[sforcedShutdown] :: FrontendSession -> IORef Bool
[scontinueSdlLoop] :: FrontendSession -> IORef Bool
[sframeQueue] :: FrontendSession -> MVar SingleFrame
[sframeDrawn] :: FrontendSession -> MVar ()
startupFun :: ScreenContent -> ClientOptions -> MVar RawFrontend -> IO ()
shutdown :: FrontendSession -> IO ()
forceShutdown :: FrontendSession -> IO ()

-- | Add a frame to be drawn.
display :: FrontendSession -> SingleFrame -> IO ()
drawFrame :: ScreenContent -> ClientOptions -> FrontendSession -> SingleFrame -> IO ()
printScreen :: FrontendSession -> IO ()

-- | Translates modifiers to our own encoding.
modTranslate :: KeyModifier -> Modifier
keyTranslate :: Bool -> Keycode -> Key
colorToRGBA :: Color -> V4 Word8


-- | Text frontend based on ANSI (via ansi-terminal).
module Game.LambdaHack.Client.UI.Frontend.ANSI

-- | Starts the main program loop using the frontend input and output.
startup :: ScreenContent -> IO RawFrontend

-- | The name of the frontend.
frontendName :: String


-- | Display game data on the screen and receive user input using one of
--   the available raw frontends and derived operations.
module Game.LambdaHack.Client.UI.Frontend

-- | The instructions sent by clients to the raw frontend, indexed by the
--   returned value.
data FrontReq :: Type -> Type

-- | Show a frame.
[FrontFrame] :: Frame -> FrontReq ()

-- | Perform an explicit delay of the given length.
[FrontDelay] :: Int -> FrontReq ()

-- | Flush frames, display a frame and ask for a keypress.
[FrontKey] :: [KM] -> Frame -> FrontReq KMP

-- | Tell if a keypress is pending.
[FrontPressed] :: FrontReq Bool

-- | Discard a single key in the queue, if any.
[FrontDiscardKey] :: FrontReq ()

-- | Discard all keys in the queue.
[FrontResetKeys] :: FrontReq ()

-- | Shut the frontend down.
[FrontShutdown] :: FrontReq ()

-- | Take screenshot.
[FrontPrintScreen] :: FrontReq ()

-- | Connection channel between a frontend and a client. Frontend acts as a
--   server, serving keys, etc., when given frames to display.
newtype ChanFrontend
ChanFrontend :: (forall a. FrontReq a -> IO a) -> ChanFrontend

-- | Initialize the frontend chosen by the player via client options.
chanFrontendIO :: ScreenContent -> ClientOptions -> IO ChanFrontend

-- | The name of the chosen frontend.
frontendName :: ClientOptions -> String

-- | Machinery allocated for an individual frontend at its startup,
--   unchanged for its lifetime.
data FrontSetup
getKey :: FrontSetup -> RawFrontend -> [KM] -> Frame -> IO KMP
fchanFrontend :: FrontSetup -> RawFrontend -> ChanFrontend
display :: RawFrontend -> Frame -> IO ()
defaultMaxFps :: Double
microInSec :: Int
frameTimeoutThread :: Int -> MVar Int -> RawFrontend -> IO ()
lazyStartup :: ScreenContent -> IO RawFrontend
nullStartup :: ScreenContent -> IO RawFrontend
seqFrame :: SingleFrame -> IO ()


-- | General content types and operations.
module Game.LambdaHack.Client.UI.ContentClientUI

-- | Operations for all UI content types, gathered together.
data CCUI
CCUI :: InputContent -> ScreenContent -> CCUI
[coinput] :: CCUI -> InputContent
[coscreen] :: CCUI -> ScreenContent
emptyCCUI :: CCUI


-- | Verifying, aggregating and displaying binding of keys to commands.
module Game.LambdaHack.Client.UI.KeyBindings

-- | Produce a set of help/menu screens from the key bindings.
--   
--   When the intro screen mentions KP_5, this really is KP_Begin, but
--   since that is harder to understand we assume a different, non-default
--   state of NumLock in the help text than in the code that handles keys.
keyHelp :: CCUI -> FontSetup -> [(Text, OKX)]

-- | Turn the specified portion of bindings into a menu.
--   
--   The length of the button may be wrong if the two supplied fonts have
--   very different widths.
okxsN :: InputContent -> DisplayFont -> DisplayFont -> Int -> (HumanCmd -> Bool) -> Bool -> CmdCategory -> ([Text], [Text], [Text]) -> ([Text], [Text]) -> OKX


-- | Screen frames and animations.
module Game.LambdaHack.Client.UI.Animation

-- | Animation is a list of frame modifications to play one by one, where
--   each modification if a map from positions to level map symbols.
data Animation

-- | Render animations on top of a screen frame.
--   
--   Located in this module to keep <tt>Animation</tt> abstract.
renderAnim :: Int -> PreFrame -> Animation -> PreFrames

-- | Empty animation with a frame of delay, to be used to momentarily
--   display something for the player to see, e.g., the aiming line when
--   swerving it. Don't use this if there are multi-line messages on the
--   screen, because the text blinking is going to be distracting.
pushAndDelay :: Animation

-- | Attack animation. A part of it also reused for self-damage and
--   healing.
twirlSplash :: (Point, Point) -> Color -> Color -> Animation

-- | Short attack animation.
twirlSplashShort :: (Point, Point) -> Color -> Color -> Animation

-- | Attack that hits through a block.
blockHit :: (Point, Point) -> Color -> Color -> Animation

-- | Attack that is blocked.
blockMiss :: (Point, Point) -> Animation

-- | Attack that is subtle (e.g., damage dice 0).
subtleHit :: (Point, Point) -> Animation

-- | Death animation for an organic body.
deathBody :: Point -> Animation

-- | Death animation for an organic body, short version (e.g., for
--   enemies).
shortDeathBody :: Point -> Animation

-- | Mark actor location animation.
actorX :: Point -> Animation

-- | Actor teleport animation.
teleport :: (Point, Point) -> Animation

-- | Terrain feature vanishing animation.
vanish :: Point -> Animation

-- | Swap-places animation, both hostile and friendly.
swapPlaces :: (Point, Point) -> Animation
fadeout :: ScreenContent -> Bool -> Int -> Rnd Animation
blank :: Maybe AttrCharW32
cSym :: Color -> Char -> Maybe AttrCharW32
mapPosToOffset :: (Point, AttrCharW32) -> (PointUI, AttrString)
mzipSingleton :: Point -> Maybe AttrCharW32 -> OverlaySpace
mzipPairs :: (Point, Point) -> (Maybe AttrCharW32, Maybe AttrCharW32) -> OverlaySpace
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Animation.Animation
instance GHC.Show.Show Game.LambdaHack.Client.UI.Animation.Animation


-- | The default screen layout and features definition.
module Client.UI.Content.Screen

-- | Description of default screen layout and features.
standardLayoutAndFeatures :: ScreenContent


-- | General content types and operations.
module Game.LambdaHack.Common.Kind

-- | Verified and preprocessed content data of a particular kind.
data ContentData c

-- | Operations for all content types, gathered together.
--   
--   Warning: this type is not abstract, but its values should not be
--   created ad hoc, even for unit tests, but should be constructed with
--   <tt>makeData</tt> for each particular content kind, which includes
--   validation, and with <tt>speedupItem</tt>, etc., to ensure internal
--   consistency.
--   
--   The <tt>emptyCOps</tt> is one such valid by construction value of this
--   type, except for the <tt>cocave</tt> field. It's suitable for
--   bootstrapping and for tests not involving dungeon generation from cave
--   templates.
data COps
COps :: ContentData CaveKind -> ContentData FactionKind -> ContentData ItemKind -> ContentData ModeKind -> ContentData PlaceKind -> RuleContent -> ContentData TileKind -> ItemSpeedup -> TileSpeedup -> COps
[cocave] :: COps -> ContentData CaveKind
[cofact] :: COps -> ContentData FactionKind
[coitem] :: COps -> ContentData ItemKind
[comode] :: COps -> ContentData ModeKind
[coplace] :: COps -> ContentData PlaceKind
[corule] :: COps -> RuleContent
[cotile] :: COps -> ContentData TileKind
[coItemSpeedup] :: COps -> ItemSpeedup
[coTileSpeedup] :: COps -> TileSpeedup

-- | This is as empty, as possible, but still valid content, except for
--   <tt>cocave</tt> which is empty and not valid (making it valid would
--   require bloating most other contents).
emptyCOps :: COps

-- | Map from an item kind identifier to the mean aspect value for the
--   kind.
data ItemSpeedup
getKindMean :: ContentId ItemKind -> ItemSpeedup -> KindMean
speedupItem :: ContentData ItemKind -> ItemSpeedup

-- | Content element at given id.
okind :: ContentData a -> ContentId a -> a
omemberGroup :: ContentData a -> GroupName a -> Bool
oisSingletonGroup :: ContentData a -> GroupName a -> Bool

-- | The id of the unique member of a singleton content group.
ouniqGroup :: Show a => ContentData a -> GroupName a -> ContentId a

-- | Pick a random id belonging to a group and satisfying a predicate.
opick :: Show a => ContentData a -> GroupName a -> (a -> Bool) -> Rnd (Maybe (ContentId a))

-- | Fold strictly over all content <tt>a</tt>.
ofoldlWithKey' :: ContentData a -> (b -> ContentId a -> a -> b) -> b -> b

-- | Fold over the given group only.
ofoldlGroup' :: ContentData a -> GroupName a -> (b -> Int -> ContentId a -> a -> b) -> b -> b
omapVector :: ContentData a -> (a -> b) -> Vector b
oimapVector :: ContentData a -> (ContentId a -> a -> b) -> Vector b

-- | Size of content <tt>a</tt>.
olength :: ContentData a -> Int
linearInterpolation :: Int -> Int -> Rarity -> Int
emptyMultiGroupMode :: ModeKind
emptyMultiGroupItem :: ItemKind
emptyUnknownTile :: TileKind
emptyUIFactionGroupName :: GroupName FactionKind
emptyUIFaction :: FactionKind
instance GHC.Show.Show Game.LambdaHack.Common.Kind.COps
instance GHC.Classes.Eq Game.LambdaHack.Common.Kind.COps


-- | Saving and restoring game state, used by both server and clients.
module Game.LambdaHack.Common.Save
type ChanSave a = MVar (Maybe a)
saveToChan :: ChanSave a -> a -> IO ()
wrapInSaves :: Binary a => COps -> (a -> FilePath) -> (ChanSave a -> IO ()) -> IO ()

-- | Restore a saved game, if it exists. Initialize directory structure and
--   copy over data files, if needed.
restoreGame :: Binary a => RuleContent -> ClientOptions -> FilePath -> IO (Maybe a)
compatibleVersion :: Version -> Version -> Bool
delayPrint :: Text -> IO ()
saveNameCli :: RuleContent -> FactionId -> String
saveNameSer :: RuleContent -> String
bkpAllSaves :: RuleContent -> ClientOptions -> IO Bool

-- | Repeatedly save serialized snapshots of current state.
--   
--   Running with <tt>-N2</tt> ca reduce <tt>Max pause</tt> from 0.2s to
--   0.01s and <tt>bytes copied during GC</tt> 10-fold, but framerate nor
--   the frequency of not making a backup save are unaffected (at standard
--   backup settings), even with null frontend, because saving takes so few
--   resources. So, generally, backup save settings are relevant only due
--   to latency impact on very slow computers or in JS.
loopSave :: Binary a => COps -> (a -> FilePath) -> ChanSave a -> IO ()


-- | UI client options.
module Game.LambdaHack.Client.UI.UIOptionsParse

-- | Read and parse UI config file.
mkUIOptions :: RuleContent -> ClientOptions -> IO UIOptions

-- | Modify client options with UI options.
applyUIOptions :: COps -> UIOptions -> ClientOptions -> ClientOptions
configError :: String -> a
readError :: Read a => String -> a
parseConfig :: Config -> UIOptions


-- | Weapons, treasure and all the other items in the game.
module Game.LambdaHack.Common.Item

-- | Game items in actor possesion or strewn around the dungeon. The
--   information contained in this time is available to the player from the
--   moment the item is first seen and is never mutated.
--   
--   Some items are not created identified (<tt>IdentityCovered</tt>). Then
--   they are presented as having a template kind that is really not their
--   own, though usually close. Full kind information about item's kind is
--   available through the <tt>ItemKindIx</tt> index once the item is
--   identified and full information about the value of item's aspect
--   record is available elsewhere (both <tt>IdentityObvious</tt> and
--   <tt>IdentityCovered</tt> items may or may not need identification of
--   their aspect record).
data Item
Item :: ItemIdentity -> Maybe FactionId -> Flavour -> Item

-- | the kind of the item, or an indirection
[jkind] :: Item -> ItemIdentity

-- | the faction that created the item, if any
[jfid] :: Item -> Maybe FactionId

-- | flavour, always the real one, it's not hidden; people may not
--   recognize shape, but they remember colour and old vs fancy look
[jflavour] :: Item -> Flavour

-- | Either the explicit obvious kind of the item or the kind it's hidden
--   under, with the details covered under the index indirection.
data ItemIdentity
IdentityObvious :: ContentId ItemKind -> ItemIdentity
IdentityCovered :: ItemKindIx -> ContentId ItemKind -> ItemIdentity

-- | An index of the kind identifier of an item. Clients have partial
--   knowledge how these idexes map to kind ids. They gain knowledge by
--   identifying items. The indexes and kind identifiers are 1-1.
data ItemKindIx

-- | The secret part of the information about an item. If a faction knows
--   the aspect record of the item, this is the complete secret
--   information. Items that don't need second identification (the
--   <tt>kmConst</tt> flag is set) may be identified or not and both cases
--   are OK (their display flavour will differ and that may be the point).
data ItemDisco
ItemDiscoFull :: AspectRecord -> ItemDisco
ItemDiscoMean :: KindMean -> ItemDisco

-- | Full information about an item.
data ItemFull
ItemFull :: Item -> ContentId ItemKind -> ItemKind -> ItemDisco -> Bool -> ItemFull
[itemBase] :: ItemFull -> Item
[itemKindId] :: ItemFull -> ContentId ItemKind
[itemKind] :: ItemFull -> ItemKind
[itemDisco] :: ItemFull -> ItemDisco
[itemSuspect] :: ItemFull -> Bool
type ItemFullKit = (ItemFull, ItemQuant)

-- | The map of item kind indexes to item kind ids. The full map, as known
--   by the server, is 1-1. Because it's sparse and changes, we don't
--   represent it as an (unboxed) vector, until it becomes a bottleneck (if
--   ever, likely on JS, where only vectors are fast).
type DiscoveryKind = EnumMap ItemKindIx (ContentId ItemKind)

-- | The map of item ids to item aspect record. The full map is known by
--   the server.
type DiscoveryAspect = EnumMap ItemId AspectRecord

-- | The map of item kind indexes to identifiers of items that have that
--   kind. Used to update data about items when their kinds become known,
--   e.g., AI item use benefit data.
type ItemIxMap = EnumMap ItemKindIx (EnumSet ItemId)

-- | The fields are, in order: 1. whether the item should be kept in
--   equipment (not in stash) 2. the total benefit from picking the item up
--   (to use or to put in equipment) 3. the benefit of applying the item to
--   self 4. the (usually negative, for him) value of hitting a foe in
--   melee with it 5. the (usually negative, for him) value of flinging the
--   item at an opponent
data Benefit
Benefit :: Bool -> Double -> Double -> Double -> Double -> Benefit
[benInEqp] :: Benefit -> Bool
[benPickup] :: Benefit -> Double
[benApply] :: Benefit -> Double
[benMelee] :: Benefit -> Double
[benFling] :: Benefit -> Double
type DiscoveryBenefit = EnumMap ItemId Benefit

-- | The absolute level's local time at which an item's copy becomes
--   operational again. Even if item is not identified and so its timeout
--   unknown, it's enough to compare this to the local level time to learn
--   whether an item is recharged.
--   
--   This schema causes timeout jumps for items in stash, but timeout is
--   reset when items move, so this is a minor problem. Global time can't
--   be used even only for items in stash, or exploit would be possible
--   when an actor on a desolate level waits to recharge items for actors
--   on a busy level. It's probably impossible to avoid such exploits or,
--   otherwise, timeout jumps, particularly for faction where many actors
--   move on many levels and so an item in stash is not used by a single
--   actor at a time.
data ItemTimer
type ItemTimers = [ItemTimer]

-- | Number of items in a bag, together with recharging timer, in case of
--   items that need recharging, exists only temporarily or auto-activate
--   at regular intervals. Data invariant: the length of the timer should
--   be less or equal to the number of items.
type ItemQuant = (Int, ItemTimers)

-- | A bag of items, e.g., one of the stores of an actor or the items on a
--   particular floor position or embedded in a particular map tile.
type ItemBag = EnumMap ItemId ItemQuant

-- | All items in the dungeon (including those carried by actors), indexed
--   by item identifier.
type ItemDict = EnumMap ItemId Item
toItemKindIx :: Word16 -> ItemKindIx
quantSingle :: ItemQuant
itemToFull6 :: COps -> DiscoveryKind -> DiscoveryAspect -> ItemId -> Item -> ItemFull
aspectRecordFull :: ItemFull -> AspectRecord
strongestSlot :: DiscoveryBenefit -> EqpSlot -> [(ItemId, ItemFullKit)] -> [(Int, (ItemId, ItemFullKit))]
itemTimerZero :: ItemTimer
createItemTimer :: Time -> Delta Time -> ItemTimer
shiftItemTimer :: Delta Time -> ItemTimer -> ItemTimer
deltaOfItemTimer :: Time -> ItemTimer -> Delta Time
charging :: Time -> ItemTimer -> Bool
ncharges :: Time -> ItemQuant -> Int
hasCharge :: Time -> ItemQuant -> Bool
strongestMelee :: Bool -> Maybe DiscoveryBenefit -> Time -> [(ItemId, ItemFullKit)] -> [(Double, Bool, Int, Int, ItemId, ItemFullKit)]
unknownMeleeBonus :: [ItemFull] -> Bool
unknownSpeedBonus :: [ItemFull] -> Bool
conditionMeleeBonus :: [ItemFullKit] -> Int
conditionSpeedBonus :: [ItemFullKit] -> Int

-- | Damage calculation. The armor and hurt skills are additive. They can't
--   be multiplicative, because then 100% armor would minimize damage
--   regardless of even 200% hurt skill. However, additive skills make the
--   relative effectiveness of weapons dependent on the enemy, so even with
--   -100% hurt skill a kinetic weapon can't be removed from the list,
--   because an enemy may have negative armor skill. This is bad, but also
--   KISS.
armorHurtCalculation :: Bool -> Skills -> Skills -> Int
mergeItemQuant :: ItemQuant -> ItemQuant -> ItemQuant
listToolsToConsume :: [(ItemId, ItemFullKit)] -> [(ItemId, ItemFullKit)] -> [((CStore, Bool), (ItemId, ItemFullKit))]
subtractIidfromGrps :: (EnumMap CStore ItemBag, [(CStore, (ItemId, ItemFull))], [(Bool, Int, GroupName ItemKind)]) -> ((CStore, Bool), (ItemId, ItemFullKit)) -> (EnumMap CStore ItemBag, [(CStore, (ItemId, ItemFull))], [(Bool, Int, GroupName ItemKind)])
sortIids :: (ItemId -> ItemFull) -> [(ItemId, ItemQuant)] -> [(ItemId, ItemQuant)]
data TileAction
EmbedAction :: (ItemId, ItemQuant) -> TileAction
ToAction :: GroupName TileKind -> TileAction
WithAction :: [(Int, GroupName ItemKind)] -> GroupName TileKind -> TileAction
parseTileAction :: Bool -> Bool -> [(ItemKind, (ItemId, ItemQuant))] -> Feature -> Maybe TileAction
valueAtEqpSlot :: EqpSlot -> AspectRecord -> Int
unknownAspect :: (Aspect -> [Dice]) -> ItemFull -> Bool
countIidConsumed :: ItemFullKit -> [(Bool, Int, GroupName ItemKind)] -> (Int, Int, [(Bool, Int, GroupName ItemKind)])
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Item.ItemKindIx
instance Data.Hashable.Class.Hashable Game.LambdaHack.Common.Item.ItemKindIx
instance GHC.Ix.Ix Game.LambdaHack.Common.Item.ItemKindIx
instance GHC.Enum.Enum Game.LambdaHack.Common.Item.ItemKindIx
instance GHC.Classes.Ord Game.LambdaHack.Common.Item.ItemKindIx
instance GHC.Classes.Eq Game.LambdaHack.Common.Item.ItemKindIx
instance GHC.Show.Show Game.LambdaHack.Common.Item.ItemKindIx
instance GHC.Generics.Generic Game.LambdaHack.Common.Item.ItemIdentity
instance GHC.Classes.Eq Game.LambdaHack.Common.Item.ItemIdentity
instance GHC.Show.Show Game.LambdaHack.Common.Item.ItemIdentity
instance GHC.Generics.Generic Game.LambdaHack.Common.Item.Item
instance GHC.Classes.Eq Game.LambdaHack.Common.Item.Item
instance GHC.Show.Show Game.LambdaHack.Common.Item.Item
instance GHC.Classes.Eq Game.LambdaHack.Common.Item.ItemDisco
instance GHC.Classes.Ord Game.LambdaHack.Common.Item.ItemDisco
instance GHC.Show.Show Game.LambdaHack.Common.Item.ItemDisco
instance GHC.Show.Show Game.LambdaHack.Common.Item.ItemFull
instance GHC.Generics.Generic Game.LambdaHack.Common.Item.Benefit
instance GHC.Show.Show Game.LambdaHack.Common.Item.Benefit
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Item.ItemTimer
instance GHC.Classes.Eq Game.LambdaHack.Common.Item.ItemTimer
instance GHC.Show.Show Game.LambdaHack.Common.Item.ItemTimer
instance GHC.Show.Show Game.LambdaHack.Common.Item.TileAction
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Item.Benefit
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Item.Item
instance Data.Hashable.Class.Hashable Game.LambdaHack.Common.Item.ItemIdentity
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Item.ItemIdentity


-- | Possible causes of failure of request.
module Game.LambdaHack.Common.ReqFailure

-- | Possible causes of failure of request.
data ReqFailure
MoveUnskilled :: ReqFailure
MoveUnskilledAsleep :: ReqFailure
MoveNothing :: ReqFailure
MeleeUnskilled :: ReqFailure
MeleeSelf :: ReqFailure
MeleeDistant :: ReqFailure
MeleeNotWeapon :: ReqFailure
DisplaceUnskilled :: ReqFailure
DisplaceDistant :: ReqFailure
DisplaceAccess :: ReqFailure
DisplaceMultiple :: ReqFailure
DisplaceDying :: ReqFailure
DisplaceBraced :: ReqFailure
DisplaceImmobile :: ReqFailure
DisplaceSupported :: ReqFailure
AlterUnskilled :: ReqFailure
AlterUnwalked :: ReqFailure
AlterDistant :: ReqFailure
AlterBlockActor :: ReqFailure
AlterBlockItem :: ReqFailure
AlterNothing :: ReqFailure
CloseDistant :: ReqFailure
CloseClosed :: ReqFailure
CloseNothing :: ReqFailure
CloseNonClosable :: ReqFailure
WaitUnskilled :: ReqFailure
YellUnskilled :: ReqFailure
MoveItemUnskilled :: ReqFailure
EqpOverfull :: ReqFailure
EqpStackFull :: ReqFailure
ApplyUnskilled :: ReqFailure
ApplyFood :: ReqFailure
ApplyRead :: ReqFailure
ApplyPeriodic :: ReqFailure
ApplyOutOfReach :: ReqFailure
ApplyCharging :: ReqFailure
ApplyNoEffects :: ReqFailure
ItemNothing :: ReqFailure
ItemNotCalm :: ReqFailure
ItemOverStash :: ReqFailure
NotCalmPrecious :: ReqFailure
ProjectUnskilled :: ReqFailure
ProjectAimOnself :: ReqFailure
ProjectBlockTerrain :: ReqFailure
ProjectBlockActor :: ReqFailure
ProjectLobable :: ReqFailure
ProjectOutOfReach :: ReqFailure
ProjectFinderKeeper :: ReqFailure
NoChangeDunLeader :: ReqFailure
impossibleReqFailure :: ReqFailure -> Bool
showReqFailure :: ReqFailure -> Text
permittedPrecious :: Bool -> Bool -> ItemFull -> Either ReqFailure Bool
permittedProject :: Bool -> Int -> Bool -> ItemFull -> Either ReqFailure Bool
permittedProjectAI :: Int -> Bool -> ItemFull -> Bool
permittedApply :: RuleContent -> Time -> Int -> Bool -> Maybe CStore -> ItemFull -> ItemQuant -> Either ReqFailure Bool
instance GHC.Classes.Eq Game.LambdaHack.Common.ReqFailure.ReqFailure
instance GHC.Show.Show Game.LambdaHack.Common.ReqFailure.ReqFailure


-- | Inhabited dungeon levels and the operations to query and change them
--   as the game progresses.
module Game.LambdaHack.Common.Level

-- | The complete dungeon is a map from level identifiers to levels.
type Dungeon = EnumMap LevelId Level
dungeonBounds :: Dungeon -> (LevelId, LevelId)

-- | Levels in the current branch, one level up (or down) from the current.
ascendInBranch :: Dungeon -> Bool -> LevelId -> [LevelId]

-- | Compute the level identifier and stair position on the new level,
--   after a level change.
--   
--   We assume there is never a staircase up and down at the same position.
whereTo :: LevelId -> Point -> Bool -> Dungeon -> [(LevelId, Point)]

-- | Items located on map tiles.
type ItemFloor = EnumMap Point ItemBag

-- | Big actors located on map tiles.
type BigActorMap = EnumMap Point ActorId

-- | Collections of projectiles located on map tiles.
type ProjectileMap = EnumMap Point [ActorId]

-- | Tile kinds on the map.
type TileMap = Array (ContentId TileKind)

-- | Current smell on map tiles.
type SmellMap = EnumMap Point Time

-- | A view on single, inhabited dungeon level. <a>Remembered</a> fields
--   carry a subset of the info in the client copies of levels.
data Level
Level :: ContentId CaveKind -> AbsDepth -> ItemFloor -> ItemFloor -> BigActorMap -> ProjectileMap -> TileMap -> EntryMap -> Area -> SmellMap -> ([Point], [Point]) -> [Point] -> Int -> Int -> Time -> Bool -> Level

-- | the kind of cave the level is an instance of
[lkind] :: Level -> ContentId CaveKind

-- | absolute depth of the level
[ldepth] :: Level -> AbsDepth

-- | remembered items lying on the floor
[lfloor] :: Level -> ItemFloor

-- | remembered items embedded in the tile
[lembed] :: Level -> ItemFloor

-- | seen big (non-projectile) actors at positions on the level; could be
--   recomputed at resume, but small enough
[lbig] :: Level -> BigActorMap

-- | seen projectiles at positions on the level; could be recomputed at
--   resume
[lproj] :: Level -> ProjectileMap

-- | remembered level map
[ltile] :: Level -> TileMap

-- | room entrances on the level
[lentry] :: Level -> EntryMap

-- | area of the level
[larea] :: Level -> Area

-- | remembered smells on the level
[lsmell] :: Level -> SmellMap

-- | positions of (up, down) stairs
[lstair] :: Level -> ([Point], [Point])

-- | positions of IK.Escape tiles
[lescape] :: Level -> [Point]

-- | currently remembered clear tiles
[lseen] :: Level -> Int

-- | total number of explorable tiles
[lexpl] :: Level -> Int

-- | local time on the level (possibly frozen)
[ltime] :: Level -> Time

-- | whether the level is covered in darkness
[lnight] :: Level -> Bool
updateFloor :: (ItemFloor -> ItemFloor) -> Level -> Level
updateEmbed :: (ItemFloor -> ItemFloor) -> Level -> Level
updateBigMap :: (BigActorMap -> BigActorMap) -> Level -> Level
updateProjMap :: (ProjectileMap -> ProjectileMap) -> Level -> Level
updateTile :: (TileMap -> TileMap) -> Level -> Level
updateEntry :: (EntryMap -> EntryMap) -> Level -> Level
updateSmell :: (SmellMap -> SmellMap) -> Level -> Level

-- | Query for tile kinds on the map.
at :: Level -> Point -> ContentId TileKind
posToBigLvl :: Point -> Level -> Maybe ActorId
occupiedBigLvl :: Point -> Level -> Bool
posToProjsLvl :: Point -> Level -> [ActorId]
occupiedProjLvl :: Point -> Level -> Bool
posToAidsLvl :: Point -> Level -> [ActorId]

-- | Try to find a random position on the map satisfying conjunction of the
--   mandatory and an optional predicate. If the permitted number of
--   attempts is not enough, try again the same number of times without the
--   next optional predicate, and fall back to trying with only the
--   mandatory predicate.
findPosTry :: Int -> Level -> (Point -> ContentId TileKind -> Bool) -> [Point -> ContentId TileKind -> Bool] -> Rnd (Maybe Point)
findPosTry2 :: Int -> Level -> (Point -> ContentId TileKind -> Bool) -> [Point -> ContentId TileKind -> Bool] -> (Point -> ContentId TileKind -> Bool) -> [Point -> ContentId TileKind -> Bool] -> Rnd (Maybe Point)

-- | Generate a list of all passable points on (connected component of) the
--   level in the order of path distance from the starting position (BFS).
--   The starting position needn't be passable and is always included.
nearbyPassablePoints :: COps -> Level -> Point -> [Point]
nearbyFreePoints :: COps -> Level -> (ContentId TileKind -> Bool) -> Point -> [Point]
sortEmbeds :: COps -> ContentId TileKind -> [(ItemKind, (ItemId, ItemQuant))] -> [(ItemId, ItemQuant)]

-- | Entries of places on the map.
type EntryMap = EnumMap Point PlaceEntry
assertSparseItems :: ItemFloor -> ItemFloor
assertSparseProjectiles :: ProjectileMap -> ProjectileMap
instance GHC.Classes.Eq Game.LambdaHack.Common.Level.Level
instance GHC.Show.Show Game.LambdaHack.Common.Level.Level
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Level.Level


-- | Actors in the game: heroes, monsters, etc.
module Game.LambdaHack.Common.Actor

-- | Actor attributes that are changing throughout the game. If they appear
--   to be dublets of aspects from actor kinds, e.g. HP, they may be
--   results of casting the dice specified in their respective actor kind
--   and/or may be modified temporarily, but return to the original value
--   from their respective kind over time.
--   
--   Other properties of an actor, in particular its current aspects, are
--   derived from the actor's trunk, organs and equipment. A class of the
--   aspects, the boolean ones, are called flags. Another class are skills.
--   Stats are a subclass that determines if particular actions are
--   permitted for the actor (or faction).
data Actor
Actor :: ItemId -> Maybe Int -> Int64 -> ResDelta -> Int64 -> ResDelta -> Point -> Maybe Point -> LevelId -> FactionId -> Maybe ([Vector], Speed) -> ItemBag -> ItemBag -> Int -> Int -> Watchfulness -> Bool -> Actor

-- | the trunk organ of the actor's body
[btrunk] :: Actor -> ItemId

-- | continued team character identity index number in this game
[bnumber] :: Actor -> Maybe Int

-- | current hit points * 1M
[bhp] :: Actor -> Int64

-- | HP delta this turn * 1M
[bhpDelta] :: Actor -> ResDelta

-- | current calm * 1M
[bcalm] :: Actor -> Int64

-- | calm delta this turn * 1M
[bcalmDelta] :: Actor -> ResDelta

-- | current position
[bpos] :: Actor -> Point

-- | previous position, if any
[boldpos] :: Actor -> Maybe Point

-- | current level
[blid] :: Actor -> LevelId

-- | faction the actor currently belongs to
[bfid] :: Actor -> FactionId

-- | trajectory the actor must travel and his travel speed
[btrajectory] :: Actor -> Maybe ([Vector], Speed)

-- | organs
[borgan] :: Actor -> ItemBag

-- | personal equipment
[beqp] :: Actor -> ItemBag

-- | number of weapons among eqp and organs
[bweapon] :: Actor -> Int

-- | number of benign items among weapons
[bweapBenign] :: Actor -> Int

-- | state of the actor's watchfulness
[bwatch] :: Actor -> Watchfulness

-- | is a projectile? affects being able to fly through other projectiles,
--   etc.
[bproj] :: Actor -> Bool

-- | Representation of recent changes to HP of Calm of an actor. This is
--   reset every time the actor perfoms an action, so this is aggregated
--   over actor turn (move), not time turn. The resource changes recorded
--   in the tuple are, respectively, negative and positive.
data ResDelta
ResDelta :: (Int64, Int64) -> (Int64, Int64) -> ResDelta

-- | resource change this move
[resCurrentTurn] :: ResDelta -> (Int64, Int64)

-- | resource change previous move
[resPreviousTurn] :: ResDelta -> (Int64, Int64)
type ActorMaxSkills = EnumMap ActorId Skills
data Watchfulness
WWatch :: Watchfulness
WWait :: Int -> Watchfulness
WSleep :: Watchfulness
WWake :: Watchfulness
deltasSerious :: ResDelta -> Bool
deltasSeriousThisTurn :: ResDelta -> Bool
deltasHears :: ResDelta -> Bool
deltaBenign :: ResDelta -> Bool
deltaWasBenign :: ResDelta -> Bool
actorCanMelee :: ActorMaxSkills -> ActorId -> Actor -> Bool
actorCanMeleeToHarm :: ActorMaxSkills -> ActorId -> Actor -> Bool
actorWorthChasing :: ActorMaxSkills -> ActorId -> Actor -> Bool
actorWorthKilling :: ActorMaxSkills -> ActorId -> Actor -> Bool

-- | The speed from organs and gear; being pushed is ignored.
gearSpeed :: Skills -> Speed
actorTemplate :: ItemId -> Maybe Int -> Int64 -> Int64 -> Point -> LevelId -> FactionId -> Bool -> Actor
actorWaits :: Actor -> Bool
actorWaitsOrSleeps :: Actor -> Bool

-- | Projectile that ran out of steam or collided with obstacle, dies. Even
--   if it pierced through an obstacle, but lost its payload while altering
--   the obstacle during piercing, it dies, too.
actorDying :: Actor -> Bool
hpTooLow :: Actor -> Skills -> Bool

-- | Check if actor calm enough to perform some actions.
--   
--   If max Calm is zero, always holds, to permit removing disastrous
--   equipped items, which would otherwise be stuck forever.
calmEnough :: Actor -> Skills -> Bool
calmFull :: Actor -> Skills -> Bool
hpFull :: Actor -> Skills -> Bool

-- | Has the skill and can wake up easily, so can sleep safely.
canSleep :: Skills -> Bool

-- | Can't loot, not too aggresive, so sometimes prefers to sleep instead
--   of exploring.
prefersSleep :: Skills -> Bool
checkAdjacent :: Actor -> Actor -> Bool
eqpOverfull :: Actor -> Int -> Bool
eqpFreeN :: Actor -> Int
getCarriedIidsAndTrunk :: Actor -> [ItemId]
getCarriedIidCStore :: Actor -> [(ItemId, CStore)]

-- | All actors on the level, indexed by actor identifier.
type ActorDict = EnumMap ActorId Actor

-- | Chance, in parts per million, that a new monster is generated. Depends
--   on the number of monsters already present, and on the level depth and
--   its cave kind.
--   
--   Note that sometimes monsters spawn in groups, increasing danger, but
--   many monsters are generated asleep, decreasing initial danger.
monsterGenChance :: AbsDepth -> AbsDepth -> Int -> Int -> Int

-- | How long until an actor's smell vanishes from a tile.
smellTimeout :: Delta Time
instance GHC.Generics.Generic Game.LambdaHack.Common.Actor.ResDelta
instance GHC.Classes.Eq Game.LambdaHack.Common.Actor.ResDelta
instance GHC.Show.Show Game.LambdaHack.Common.Actor.ResDelta
instance GHC.Generics.Generic Game.LambdaHack.Common.Actor.Watchfulness
instance GHC.Classes.Eq Game.LambdaHack.Common.Actor.Watchfulness
instance GHC.Show.Show Game.LambdaHack.Common.Actor.Watchfulness
instance GHC.Generics.Generic Game.LambdaHack.Common.Actor.Actor
instance GHC.Classes.Eq Game.LambdaHack.Common.Actor.Actor
instance GHC.Show.Show Game.LambdaHack.Common.Actor.Actor
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Actor.Actor
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Actor.Watchfulness
instance Data.Binary.Class.Binary Game.LambdaHack.Common.Actor.ResDelta


-- | The common, for server and clients, main game state type and its
--   operations.
module Game.LambdaHack.Common.State

-- | The main game state, the basic one, pertaining to a single game, not
--   to a single playing session or an intersection of both. This state
--   persists between playing sessions, until the particular game ends.
--   Anything that persists between games is stored in server state, client
--   state or client UI session state.
--   
--   Another differentiating property of this state is that it's kept
--   separately on the server and each of the clients (players, human or
--   AI) and separately updated, according to what each player can observe.
--   It's never updated directly, but always through atomic commands
--   (<a>CmdAtomic</a>) that are filtered and interpreted differently on
--   server and on each client. Therefore, the type is a view on the game
--   state, not the real game state, except on the server that alone stores
--   the full game information.
data State
sdungeon :: State -> Dungeon
stotalDepth :: State -> AbsDepth
sactorD :: State -> ActorDict
sitemD :: State -> ItemDict
sitemIxMap :: State -> ItemIxMap
sfactionD :: State -> FactionDict
stime :: State -> Time
scops :: State -> COps
sgold :: State -> Int
shigh :: State -> ScoreDict
sgameModeId :: State -> ContentId ModeKind
sdiscoKind :: State -> DiscoveryKind
sdiscoAspect :: State -> DiscoveryAspect
sactorMaxSkills :: State -> ActorMaxSkills

-- | Initial complete global game state.
defStateGlobal :: Dungeon -> AbsDepth -> FactionDict -> COps -> ScoreDict -> ContentId ModeKind -> DiscoveryKind -> State

-- | Initial empty state.
emptyState :: State

-- | Local state created by removing secret information from global state
--   components.
localFromGlobal :: State -> State

-- | Update dungeon data within state.
updateDungeon :: (Dungeon -> Dungeon) -> State -> State

-- | Update dungeon depth.
updateDepth :: (AbsDepth -> AbsDepth) -> State -> State

-- | Update the actor dictionary.
updateActorD :: (ActorDict -> ActorDict) -> State -> State

-- | Update the item dictionary.
updateItemD :: (ItemDict -> ItemDict) -> State -> State

-- | Update the item kind index map.
updateItemIxMap :: (ItemIxMap -> ItemIxMap) -> State -> State

-- | Update faction data within state.
updateFactionD :: (FactionDict -> FactionDict) -> State -> State

-- | Update global time within state.
updateTime :: (Time -> Time) -> State -> State

-- | Update content data within state and recompute the cached data.
updateCOpsAndCachedData :: (COps -> COps) -> State -> State

-- | Update total gold value in the dungeon.
updateGold :: (Int -> Int) -> State -> State
updateDiscoKind :: (DiscoveryKind -> DiscoveryKind) -> State -> State
updateDiscoAspect :: (DiscoveryAspect -> DiscoveryAspect) -> State -> State
updateActorMaxSkills :: (ActorMaxSkills -> ActorMaxSkills) -> State -> State
getItemBody :: ItemId -> State -> Item
aspectRecordFromItem :: ItemId -> Item -> State -> AspectRecord
aspectRecordFromIid :: ItemId -> State -> AspectRecord
maxSkillsFromActor :: Actor -> State -> Skills
maxSkillsInDungeon :: State -> ActorMaxSkills
unknownLevel :: COps -> ContentId CaveKind -> AbsDepth -> Area -> ([Point], [Point]) -> [Point] -> Int -> Bool -> Level

-- | Create a map full of unknown tiles.
--   
--   <pre>
--   &gt;&gt;&gt; unknownTileMap (fromJust (toArea (0,0,0,0))) TK.unknownId 2 2
--   PointArray.Array with size (2,2)
--   </pre>
unknownTileMap :: Area -> ContentId TileKind -> X -> Y -> TileMap
instance GHC.Classes.Eq Game.LambdaHack.Common.State.State
instance GHC.Show.Show Game.LambdaHack.Common.State.State
instance Data.Binary.Class.Binary Game.LambdaHack.Common.State.State


-- | Operations on the <a>Actor</a> type, and related, that need the
--   <a>State</a> type, but not our custom monad types.
module Game.LambdaHack.Common.ActorState
fidActorNotProjGlobalAssocs :: FactionId -> State -> [(ActorId, Actor)]
actorAssocs :: (FactionId -> Bool) -> LevelId -> State -> [(ActorId, Actor)]
fidActorRegularAssocs :: FactionId -> LevelId -> State -> [(ActorId, Actor)]
fidActorRegularIds :: FactionId -> LevelId -> State -> [ActorId]
foeRegularAssocs :: FactionId -> LevelId -> State -> [(ActorId, Actor)]
foeRegularList :: FactionId -> LevelId -> State -> [Actor]
friendRegularAssocs :: FactionId -> LevelId -> State -> [(ActorId, Actor)]
friendRegularList :: FactionId -> LevelId -> State -> [Actor]
bagAssocs :: State -> ItemBag -> [(ItemId, Item)]
bagAssocsK :: State -> ItemBag -> [(ItemId, (Item, ItemQuant))]
posToBig :: Point -> LevelId -> State -> Maybe ActorId
posToBigAssoc :: Point -> LevelId -> State -> Maybe (ActorId, Actor)
posToProjs :: Point -> LevelId -> State -> [ActorId]
posToProjAssocs :: Point -> LevelId -> State -> [(ActorId, Actor)]
posToAids :: Point -> LevelId -> State -> [ActorId]
posToAidAssocs :: Point -> LevelId -> State -> [(ActorId, Actor)]

-- | Calculate loot's worth for a given faction.
calculateTotal :: FactionId -> State -> (ItemBag, Int)

-- | Price an item, taking count into consideration.
itemPrice :: Int -> ItemKind -> Int
findIid :: ActorId -> FactionId -> ItemId -> State -> [(ActorId, (Actor, CStore))]
combinedItems :: FactionId -> State -> ItemBag
getActorBody :: ActorId -> State -> Actor
getActorMaxSkills :: ActorId -> State -> Skills
actorCurrentSkills :: Maybe ActorId -> ActorId -> State -> Skills
canTraverse :: ActorId -> State -> Bool
getCarriedAssocsAndTrunk :: Actor -> State -> [(ItemId, Item)]
getContainerBag :: Container -> State -> ItemBag
getFloorBag :: LevelId -> Point -> State -> ItemBag
getEmbedBag :: LevelId -> Point -> State -> ItemBag
getBodyStoreBag :: Actor -> CStore -> State -> ItemBag
getFactionStashBag :: FactionId -> State -> ItemBag
mapActorItems_ :: Monad m => (CStore -> ItemId -> ItemQuant -> m ()) -> Actor -> State -> m ()
getActorAssocs :: ActorId -> CStore -> State -> [(ItemId, (Item, ItemQuant))]

-- | Checks if the actor is present on the current level. The order of
--   argument here and in other functions is set to allow
--   
--   <pre>
--   b &lt;- getsState (memActor a)
--   </pre>
memActor :: ActorId -> LevelId -> State -> Bool

-- | Get current time from the dungeon data.
getLocalTime :: LevelId -> State -> Time
regenCalmDelta :: ActorId -> Actor -> State -> Int64
actorInAmbient :: Actor -> State -> Bool
dispEnemy :: ActorId -> ActorId -> Skills -> State -> Bool
itemToFull :: ItemId -> State -> ItemFull
fullAssocs :: ActorId -> [CStore] -> State -> [(ItemId, ItemFull)]
kitAssocs :: ActorId -> [CStore] -> State -> [(ItemId, ItemFullKit)]
getItemKindId :: Item -> State -> ContentId ItemKind
getIidKindId :: ItemId -> State -> ContentId ItemKind
getItemKind :: Item -> State -> ItemKind
getIidKind :: ItemId -> State -> ItemKind
getItemKindIdServer :: Item -> State -> ContentId ItemKind
getIidKindIdServer :: ItemId -> State -> ContentId ItemKind
getItemKindServer :: Item -> State -> ItemKind
getIidKindServer :: ItemId -> State -> ItemKind
tileAlterable :: LevelId -> Point -> State -> Bool

-- | Determine the dungeon level of the container. If the item is in the
--   shared stash, the level depends on which actor asks, not where the
--   stash is located physically.
lidFromC :: Container -> State -> LevelId
posFromC :: Container -> State -> Point

-- | Require that any non-dying foe is adjacent. We include even
--   projectiles that explode when stricken down, because they can be
--   caught and then they don't explode, so it makes sense to focus on
--   handling them. If there are many projectiles in a single adjacent
--   position, we only test the first one, the one that would be hit in
--   melee (this is not optimal if the actor would need to flee instead of
--   meleeing, but fleeing with *many* projectiles adjacent is a possible
--   waste of a move anyway).
anyFoeAdj :: ActorId -> State -> Bool
anyHarmfulFoeAdj :: ActorMaxSkills -> ActorId -> State -> Bool
adjacentBigAssocs :: Actor -> State -> [(ActorId, Actor)]
adjacentProjAssocs :: Actor -> State -> [(ActorId, Actor)]
armorHurtBonus :: ActorId -> ActorId -> State -> Int

-- | Check if any non-dying foe is adjacent to any of our normal actors and
--   either can harm them via melee or can attack from a distance.
--   Otherwise no point meleeing him. Projectiles are ignored, because they
--   are not actively attempted to melee, see <tt>meleeAny</tt>. This is
--   regardless of whether our actor can melee or just needs to flee, in
--   which case alert is needed so that he is not slowed down by others.
--   However, if our actor can't move nor melee, no real combat is taking
--   place. This is needed only by AI and computed as lazily as possible.
inMelee :: ActorMaxSkills -> FactionId -> LevelId -> State -> Bool


-- | Game state reading monad and basic operations.
module Game.LambdaHack.Common.MonadStateRead

-- | Monad for reading game state. A state monad with state modification
--   disallowed (another constraint is needed to permit that). The basic
--   server and client monads are like that, because server and clients
--   freely modify their internal session data, but don't modify the main
--   game state, except in very restricted and synchronized way.
class (Monad m, Functor m, Applicative m) => MonadStateRead m
getsState :: MonadStateRead m => (State -> a) -> m a
getState :: MonadStateRead m => m State
getLevel :: MonadStateRead m => LevelId -> m Level
getGameMode :: MonadStateRead m => m ModeKind
isNoConfirmsGame :: MonadStateRead m => m Bool
getEntryArena :: MonadStateRead m => Faction -> m LevelId
pickWeaponM :: MonadStateRead m => Bool -> Maybe DiscoveryBenefit -> [(ItemId, ItemFullKit)] -> Skills -> ActorId -> m [(Double, Bool, Int, Int, ItemId, ItemFullKit)]
displayTaunt :: MonadStateRead m => Bool -> (Rnd (Text, Text) -> m (Text, Text)) -> ActorId -> m (Text, Text)


-- | Description of effects.
module Game.LambdaHack.Client.UI.EffectDescription
data DetailLevel
DetailLow :: DetailLevel
DetailMedium :: DetailLevel
DetailHigh :: DetailLevel
DetailAll :: DetailLevel
defaultDetailLevel :: DetailLevel

-- | Suffix to append to a basic content name if the content causes the
--   effect.
--   
--   We show absolute time in seconds, not <tt>moves</tt>, because actors
--   can have different speeds (and actions can potentially take different
--   time intervals). We call the time taken by one player move, when
--   walking, a <tt>move</tt>. <tt>Turn</tt> and <tt>clip</tt> are used
--   mostly internally, the former as an absolute time unit. We show
--   distances in <tt>steps</tt>, because one step, from a tile to another
--   tile, is always 1 meter. We don't call steps <tt>tiles</tt>, reserving
--   that term for the context of terrain kinds or units of area.
effectToSuffix :: DetailLevel -> Effect -> Text
detectToObject :: DetectKind -> Text
detectToVerb :: DetectKind -> Text
skillName :: Skill -> Text
skillDesc :: Skill -> Text
skillToDecorator :: Skill -> Actor -> Int -> Text
skillsInDisplayOrder :: [Skill]
kindAspectToSuffix :: Aspect -> Text
aspectToSentence :: Aspect -> Maybe Text
affixDice :: Dice -> Text
describeToolsAlternative :: [[(Int, GroupName ItemKind)]] -> Text
describeCrafting :: [(Int, GroupName ItemKind)] -> [(Int, GroupName ItemKind)] -> Effect -> (Text, Text, Text)
wrapInParens :: Text -> Text
conditionToObject :: Condition -> Text
activationFlagToObject :: ActivationFlag -> Text
slotToSentence :: EqpSlot -> Text
tmodToSuff :: Text -> ThrowMod -> Text
affixBonus :: Int -> Text
wrapInChevrons :: Text -> Text
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.EffectDescription.DetailLevel
instance GHC.Enum.Bounded Game.LambdaHack.Client.UI.EffectDescription.DetailLevel
instance GHC.Enum.Enum Game.LambdaHack.Client.UI.EffectDescription.DetailLevel
instance GHC.Classes.Ord Game.LambdaHack.Client.UI.EffectDescription.DetailLevel
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.EffectDescription.DetailLevel
instance GHC.Show.Show Game.LambdaHack.Client.UI.EffectDescription.DetailLevel
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.EffectDescription.DetailLevel


-- | UI aspects of actors.
module Game.LambdaHack.Client.UI.ActorUI
data ActorUI
ActorUI :: Char -> Text -> Text -> Color -> ActorUI

-- | individual map symbol
[bsymbol] :: ActorUI -> Char

-- | individual name
[bname] :: ActorUI -> Text

-- | individual pronoun
[bpronoun] :: ActorUI -> Text

-- | individual map color
[bcolor] :: ActorUI -> Color
type ActorDictUI = EnumMap ActorId ActorUI
keySelected :: (ActorId, Actor, ActorUI) -> (Bool, Bool, Bool, Char, Color, ActorId)

-- | The part of speech describing the actor.
partActor :: ActorUI -> Part

-- | The part of speech containing the actor's pronoun.
partPronoun :: ActorUI -> Part
tryFindActor :: State -> (ActorId -> Actor -> Bool) -> Maybe (ActorId, Actor)
tryFindHeroK :: ActorDictUI -> FactionId -> Int -> State -> Maybe (ActorId, Actor)
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.ActorUI.ActorUI
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.ActorUI.ActorUI
instance GHC.Show.Show Game.LambdaHack.Client.UI.ActorUI.ActorUI
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.ActorUI.ActorUI


-- | Client-specific game state components.
module Game.LambdaHack.Client.State

-- | Client state, belonging to a single faction.
data StateClient
StateClient :: Int -> EnumMap ActorId TgtAndPath -> EnumMap ActorId (Point, Time) -> EnumSet LevelId -> EnumMap ActorId BfsAndPath -> () -> DiscoveryBenefit -> PerLid -> AlterLid -> SMGen -> Maybe ActorId -> FactionId -> Bool -> EnumSet LevelId -> ClientOptions -> (PrimArray PointI, PrimArray PointI) -> Challenge -> Challenge -> Int -> StateClient

-- | a parameter of the aiming digital line
[seps] :: StateClient -> Int

-- | targets of our actors in the dungeon; this is only useful for AI and
--   for directing non-pointmen, in particular with following doctrines,
--   where non-pointmen go to the pointman's target
[stargetD] :: StateClient -> EnumMap ActorId TgtAndPath

-- | the position and time of last fleeing attempt (regardless if
--   succeeded)
[sfleeD] :: StateClient -> EnumMap ActorId (Point, Time)

-- | the set of fully explored levels
[sexplored] :: StateClient -> EnumSet LevelId

-- | pathfinding data for our actors
[sbfsD] :: StateClient -> EnumMap ActorId BfsAndPath
[sundo] :: StateClient -> ()

-- | remembered AI benefits of items; could be recomputed at resume, but
--   they are costly to generate and not too large
[sdiscoBenefit] :: StateClient -> DiscoveryBenefit

-- | faction perception indexed by level
[sfper] :: StateClient -> PerLid

-- | cached alter skill data for positions (actually,
--   <tt>Tile.alterMinWalk</tt> instead)
[salter] :: StateClient -> AlterLid

-- | current random generator
[srandom] :: StateClient -> SMGen

-- | candidate new leader of the faction; Faction.gleader is the old leader
[_sleader] :: StateClient -> Maybe ActorId

-- | faction controlled by the client
[_sside] :: StateClient -> FactionId

-- | exit the game loop
[squit] :: StateClient -> Bool

-- | whether we are in melee, per level
[scondInMelee] :: StateClient -> EnumSet LevelId

-- | client options
[soptions] :: StateClient -> ClientOptions

-- | Instead of a BFS queue (list) we use these two arrays, for (JS) speed.
--   They need to be per-client distinct, because sometimes multiple
--   clients interleave BFS computation.
[stabs] :: StateClient -> (PrimArray PointI, PrimArray PointI)

-- | current game challenge setup
[scurChal] :: StateClient -> Challenge

-- | next game challenge setup
[snxtChal] :: StateClient -> Challenge

-- | whether to mark suspect features
[smarkSuspect] :: StateClient -> Int
type AlterLid = EnumMap LevelId (Array Word8)

-- | Pathfinding distances to all reachable positions of an actor and a
--   shortest paths to some of the positions.
data BfsAndPath
BfsInvalid :: BfsAndPath
BfsAndPath :: Array BfsDistance -> EnumMap Point AndPath -> BfsAndPath

-- | Actor's target and a path to it, if any.
data TgtAndPath
TgtAndPath :: Target -> Maybe AndPath -> TgtAndPath
[tapTgt] :: TgtAndPath -> Target
[tapPath] :: TgtAndPath -> Maybe AndPath

-- | The type of na actor target.
data Target

-- | target an enemy
TEnemy :: ActorId -> Target

-- | target a friend or neutral
TNonEnemy :: ActorId -> Target

-- | target a concrete spot
TPoint :: TGoal -> LevelId -> Point -> Target

-- | target position relative to actor
TVector :: Vector -> Target

-- | The goal of an actor.
data TGoal

-- | shared inventory stash of our or an enemy faction
TStash :: FactionId -> TGoal

-- | last seen position of the targeted actor
TEnemyPos :: ActorId -> TGoal

-- | embedded item that can be triggered; in <tt>TPoint (TEmbed bag p) _
--   q</tt> usually <tt>bag</tt> is embbedded in <tt>p</tt> and <tt>q</tt>
--   is an adjacent open tile
TEmbed :: ItemBag -> Point -> TGoal

-- | item lying on the ground
TItem :: ItemBag -> TGoal

-- | smell potentially left by enemies
TSmell :: TGoal

-- | a blocking tile to be approached (and, e.g., revealed to be walkable
--   or altered or searched)
TBlock :: TGoal

-- | an unknown tile to be explored
TUnknown :: TGoal

-- | a known tile to be patrolled
TKnown :: TGoal

-- | a hideout to either flee to or find a hidden enemy sniper in
THideout :: TGoal

-- | Initial empty game client state.
emptyStateClient :: FactionId -> StateClient

-- | Cycle the <a>smarkSuspect</a> setting.
cycleMarkSuspect :: Int -> StateClient -> StateClient

-- | Update target parameters within client state.
updateTarget :: ActorId -> (Maybe Target -> Maybe Target) -> StateClient -> StateClient

-- | Get target parameters from client state.
getTarget :: ActorId -> StateClient -> Maybe Target

-- | Update picked leader within state. Verify actor's faction.
updateLeader :: ActorId -> State -> StateClient -> StateClient
sside :: StateClient -> FactionId
sleader :: StateClient -> Maybe ActorId
instance GHC.Show.Show Game.LambdaHack.Client.State.BfsAndPath
instance GHC.Generics.Generic Game.LambdaHack.Client.State.TGoal
instance GHC.Classes.Eq Game.LambdaHack.Client.State.TGoal
instance GHC.Show.Show Game.LambdaHack.Client.State.TGoal
instance GHC.Generics.Generic Game.LambdaHack.Client.State.Target
instance GHC.Classes.Eq Game.LambdaHack.Client.State.Target
instance GHC.Show.Show Game.LambdaHack.Client.State.Target
instance GHC.Generics.Generic Game.LambdaHack.Client.State.TgtAndPath
instance GHC.Show.Show Game.LambdaHack.Client.State.TgtAndPath
instance Data.Binary.Class.Binary Game.LambdaHack.Client.State.StateClient
instance Data.Binary.Class.Binary Game.LambdaHack.Client.State.TgtAndPath
instance Data.Binary.Class.Binary Game.LambdaHack.Client.State.Target
instance Data.Binary.Class.Binary Game.LambdaHack.Client.State.TGoal


-- | The client UI session state.
module Game.LambdaHack.Client.UI.SessionUI

-- | The information that is used across a human player playing session,
--   including many consecutive games in a single session, including
--   playing different teams. Some of it is saved, some is reset when a new
--   playing session starts. Nothing is tied to a faction/team, but instead
--   all to UI configuration and UI input and display history. An important
--   component is the frontend session.
data SessionUI
SessionUI :: Maybe RequestUI -> ReqDelay -> Bool -> Bool -> Maybe Target -> Maybe Target -> ActorDictUI -> ItemDictUI -> ItemRoles -> Maybe (CStore, CStore) -> ChanFrontend -> CCUI -> UIOptions -> Maybe AimMode -> Bool -> Maybe (ItemId, CStore, Bool) -> EnumSet ActorId -> Maybe RunParams -> History -> EnumMap (ContentId ModeKind) (Map Challenge Int) -> EnumSet (ContentId ModeKind) -> EnumSet (ContentId ModeKind) -> PointUI -> Bool -> KeyMacroFrame -> [KeyMacroFrame] -> EnumSet ActorId -> Int -> Bool -> Int -> Bool -> Int -> Bool -> Bool -> Maybe Bool -> Set Msg -> Bool -> Map String Int -> ChosenLore -> Bool -> Bool -> Bool -> POSIXTime -> POSIXTime -> Time -> Int -> Int -> SMGen -> SessionUI

-- | request created by a UI query but not yet sent to the server
[sreqPending] :: SessionUI -> Maybe RequestUI

-- | server delayed sending query to client or receiving request from
--   client
[sreqDelay] :: SessionUI -> ReqDelay

-- | player is now queried for a command
[sreqQueried] :: SessionUI -> Bool

-- | player requested to regain control from AI ASAP
[sregainControl] :: SessionUI -> Bool

-- | the common xhair
[sxhair] :: SessionUI -> Maybe Target

-- | xhair set for last GoTo
[sxhairGoTo] :: SessionUI -> Maybe Target

-- | assigned actor UI presentations
[sactorUI] :: SessionUI -> ActorDictUI

-- | assigned item first seen level
[sitemUI] :: SessionUI -> ItemDictUI

-- | assignment of roles to items
[sroles] :: SessionUI -> ItemRoles

-- | last item move stores
[slastItemMove] :: SessionUI -> Maybe (CStore, CStore)

-- | connection with the frontend
[schanF] :: SessionUI -> ChanFrontend

-- | UI client content
[sccui] :: SessionUI -> CCUI

-- | UI options as set by the player
[sUIOptions] :: SessionUI -> UIOptions

-- | aiming mode
[saimMode] :: SessionUI -> Maybe AimMode

-- | last mouse aiming not vacuus
[sxhairMoused] :: SessionUI -> Bool

-- | selected item, if any, it's store and whether to override suitability
--   check
[sitemSel] :: SessionUI -> Maybe (ItemId, CStore, Bool)

-- | the set of currently selected actors
[sselected] :: SessionUI -> EnumSet ActorId

-- | parameters of the current run, if any
[srunning] :: SessionUI -> Maybe RunParams

-- | history of messages
[shistory] :: SessionUI -> History

-- | the number of games won by the UI faction per game mode and per
--   difficulty level
[svictories] :: SessionUI -> EnumMap (ContentId ModeKind) (Map Challenge Int)

-- | camped games
[scampings] :: SessionUI -> EnumSet (ContentId ModeKind)

-- | restarted games
[srestarts] :: SessionUI -> EnumSet (ContentId ModeKind)

-- | mouse pointer position
[spointer] :: SessionUI -> PointUI

-- | whether to auto-clear prompts
[sautoYes] :: SessionUI -> Bool

-- | the head of the key macro stack
[smacroFrame] :: SessionUI -> KeyMacroFrame

-- | the tail of the key macro stack
[smacroStack] :: SessionUI -> [KeyMacroFrame]

-- | actors that just got out of sight
[slastLost] :: SessionUI -> EnumSet ActorId

-- | player just waited this many times
[swaitTimes] :: SessionUI -> Int

-- | the player just exited AI automation
[swasAutomated] :: SessionUI -> Bool

-- | mark leader and party FOV
[smarkVision] :: SessionUI -> Int

-- | mark smell, if the leader can smell
[smarkSmell] :: SessionUI -> Bool

-- | next game scenario number
[snxtScenario] :: SessionUI -> Int

-- | whether current game is a tutorial
[scurTutorial] :: SessionUI -> Bool

-- | whether next game is to be tutorial
[snxtTutorial] :: SessionUI -> Bool

-- | override display of tutorial hints
[soverrideTut] :: SessionUI -> Maybe Bool

-- | tutorial hints already shown this game
[susedHints] :: SessionUI -> Set Msg

-- | whether to mute all new messages
[smuteMessages] :: SessionUI -> Bool

-- | indices of last used menu items
[smenuIxMap] :: SessionUI -> Map String Int

-- | last lore chosen to display
[schosenLore] :: SessionUI -> ChosenLore

-- | current level needs displaying
[sdisplayNeeded] :: SessionUI -> Bool

-- | a frame was already displayed this turn
[sturnDisplayed] :: SessionUI -> Bool

-- | whether no visible report created last UI faction turn or the report
--   wiped out from screen since
[sreportNull] :: SessionUI -> Bool

-- | this session start time
[sstart] :: SessionUI -> POSIXTime

-- | this game start time
[sgstart] :: SessionUI -> POSIXTime

-- | clips from start of session to current game start
[sallTime] :: SessionUI -> Time

-- | this game current frame count
[snframes] :: SessionUI -> Int

-- | frame count from start of session to current game start
[sallNframes] :: SessionUI -> Int

-- | current random generator for UI
[srandomUI] :: SessionUI -> SMGen
data ReqDelay
ReqDelayNot :: ReqDelay
ReqDelayHandled :: ReqDelay
ReqDelayAlarm :: ReqDelay
type ItemDictUI = EnumMap ItemId LevelId

-- | A collection of item identifier sets indicating what roles (possibly
--   many) an item has assigned.
newtype ItemRoles
ItemRoles :: EnumMap SLore (EnumSet ItemId) -> ItemRoles

-- | Current aiming mode of a client.
data AimMode
AimMode :: LevelId -> DetailLevel -> AimMode
[aimLevelId] :: AimMode -> LevelId
[detailLevel] :: AimMode -> DetailLevel

-- | In-game macros. We record menu navigation keystrokes and keystrokes
--   bound to commands with one exception --- we exclude keys that invoke
--   the <tt>Record</tt> command, to avoid surprises. Keys are kept in the
--   same order in which they're meant to be replayed, i.e. the first
--   element of the list is replayed also as the first one.
newtype KeyMacro
KeyMacro :: [KM] -> KeyMacro
[unKeyMacro] :: KeyMacro -> [KM]

-- | Local macro buffer frame. Predefined macros have their own in-game
--   macro buffer, allowing them to record in-game macro, queue actions and
--   repeat the last macro's action. Running predefined macro pushes new
--   <tt>KeyMacroFrame</tt> onto the stack. We pop buffers from the stack
--   if locally there are no actions pending to be handled.
data KeyMacroFrame
KeyMacroFrame :: Either [KM] KeyMacro -> KeyMacro -> Maybe KM -> KeyMacroFrame

-- | record keystrokes in Left; repeat from Right
[keyMacroBuffer] :: KeyMacroFrame -> Either [KM] KeyMacro

-- | actions pending to be handled
[keyPending] :: KeyMacroFrame -> KeyMacro

-- | last pressed key
[keyLast] :: KeyMacroFrame -> Maybe KM

-- | Parameters of the current run.
data RunParams
RunParams :: ActorId -> [ActorId] -> Bool -> Maybe Text -> Int -> RunParams

-- | the original leader from run start
[runLeader] :: RunParams -> ActorId

-- | the list of actors that take part
[runMembers] :: RunParams -> [ActorId]

-- | initial run continuation by any run participant, including run leader
[runInitial] :: RunParams -> Bool

-- | message with the next stop reason
[runStopMsg] :: RunParams -> Maybe Text

-- | waiting for others to move out of the way
[runWaiting] :: RunParams -> Int

-- | Last lore being aimed at.
data ChosenLore
ChosenLore :: [(ActorId, Actor)] -> [(ItemId, ItemQuant)] -> ChosenLore
ChosenNothing :: ChosenLore
emptySessionUI :: UIOptions -> SessionUI
emptyMacroFrame :: KeyMacroFrame
cycleMarkVision :: Int -> SessionUI -> SessionUI
toggleMarkSmell :: SessionUI -> SessionUI
cycleOverrideTut :: Int -> SessionUI -> SessionUI
getActorUI :: ActorId -> SessionUI -> ActorUI
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.SessionUI.ReqDelay
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.SessionUI.ItemRoles
instance GHC.Show.Show Game.LambdaHack.Client.UI.SessionUI.ItemRoles
instance GHC.Generics.Generic Game.LambdaHack.Client.UI.SessionUI.AimMode
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.SessionUI.AimMode
instance GHC.Show.Show Game.LambdaHack.Client.UI.SessionUI.AimMode
instance GHC.Base.Monoid Game.LambdaHack.Client.UI.SessionUI.KeyMacro
instance GHC.Base.Semigroup Game.LambdaHack.Client.UI.SessionUI.KeyMacro
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.SessionUI.KeyMacro
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.SessionUI.KeyMacro
instance GHC.Show.Show Game.LambdaHack.Client.UI.SessionUI.KeyMacro
instance GHC.Show.Show Game.LambdaHack.Client.UI.SessionUI.KeyMacroFrame
instance GHC.Show.Show Game.LambdaHack.Client.UI.SessionUI.RunParams
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.SessionUI.SessionUI
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.SessionUI.RunParams
instance Data.Binary.Class.Binary Game.LambdaHack.Client.UI.SessionUI.AimMode


-- | Basic client monad and related operations.
module Game.LambdaHack.Client.MonadClient

-- | Monad for reading client state.
class MonadStateRead m => MonadClientRead m
getsClient :: MonadClientRead m => (StateClient -> a) -> m a
liftIO :: MonadClientRead m => IO a -> m a

-- | Monad for writing to client state.
class MonadClientRead m => MonadClient m
modifyClient :: MonadClient m => (StateClient -> StateClient) -> m ()
getClient :: MonadClientRead m => m StateClient
putClient :: MonadClient m => StateClient -> m ()
debugPossiblyPrint :: MonadClient m => Text -> m ()
createTabBFS :: MonadClient m => m (PrimArray PointI)
dumpTextFile :: MonadClientRead m => Text -> FilePath -> m FilePath

-- | Invoke pseudo-random computation with the generator kept in the state.
rndToAction :: MonadClient m => Rnd a -> m a
condInMeleeM :: MonadClientRead m => LevelId -> m Bool
insertInMeleeM :: MonadClient m => LevelId -> m ()


-- | Common client monad operations.
module Game.LambdaHack.Client.CommonM

-- | Get the current perception of a client.
getPerFid :: MonadClientRead m => LevelId -> m Perception

-- | Calculate the position of an actor's target. This matches
--   <tt>pathGoal</tt>, but sometimes path is not defined.
aidTgtToPos :: Maybe ActorId -> LevelId -> Maybe Target -> State -> Maybe Point

-- | Counts the number of steps until the projectile would hit a
--   non-projectile actor or obstacle. Starts searching with the given eps
--   and returns the first found eps for which the number reaches the
--   distance between actor and target position, or Nothing if none can be
--   found. Treats unknown tiles as walkable, but prefers known.
makeLine :: Bool -> Actor -> Point -> Int -> COps -> Level -> Maybe Int
currentSkillsClient :: MonadClientRead m => ActorId -> m Skills
pickWeaponClient :: MonadClient m => ActorId -> ActorId -> m (Maybe RequestTimed)
updateSalter :: MonadClient m => LevelId -> [(Point, ContentId TileKind)] -> m ()
createSalter :: State -> AlterLid


-- | Client monad for interacting with a human through UI.
module Game.LambdaHack.Client.UI.MonadClientUI

-- | The monad that gives the client access to UI operations, but not to
--   modifying client state, except for the client-side pointman (as
--   opposed to pointman stores in faction data in main game state), which
--   is more of a UI concept, but is shared with AI to be able to keep it
--   when switching AI on/off and to save on typing.
class MonadClientRead m => MonadClientUI m
getsSession :: MonadClientUI m => (SessionUI -> a) -> m a
modifySession :: MonadClientUI m => (SessionUI -> SessionUI) -> m ()
updateClientLeader :: MonadClientUI m => ActorId -> m ()
getCacheBfs :: MonadClientUI m => ActorId -> m (Array BfsDistance)
getCachePath :: MonadClientUI m => ActorId -> Point -> m (Maybe AndPath)
clientPrintUI :: MonadClientUI m => Text -> m ()
debugPossiblyPrintUI :: MonadClientUI m => Text -> m ()
getSession :: MonadClientUI m => m SessionUI
putSession :: MonadClientUI m => SessionUI -> m ()

-- | Push frames or delays to the frame queue. The frames depict the
--   <tt>lid</tt> level.
displayFrames :: MonadClientUI m => LevelId -> PreFrames3 -> m ()

-- | Write <a>FrontKey</a> UI request to the frontend, read the reply, set
--   pointer, return key.
connFrontendFrontKey :: MonadClientUI m => [KM] -> PreFrame3 -> m KM
setFrontAutoYes :: MonadClientUI m => Bool -> m ()
frontendShutdown :: MonadClientUI m => m ()
printScreen :: MonadClientUI m => m ()

-- | Initialize the frontend chosen by the player via client options.
chanFrontend :: MonadClientUI m => ScreenContent -> ClientOptions -> m ChanFrontend
anyKeyPressed :: MonadClientUI m => m Bool
discardPressedKey :: MonadClientUI m => m ()
resetPressedKeys :: MonadClientUI m => m ()
revCmdMap :: MonadClientUI m => m (HumanCmd -> KM)
getReportUI :: MonadClientUI m => Bool -> m Report
getMiniHintAiming :: MonadClientUI m => m Text
computeChosenLore :: MonadClientUI m => m ([(ActorId, Actor)], [(ItemId, ItemQuant)])
getArenaUI :: MonadClientUI m => m LevelId
viewedLevelUI :: MonadClientUI m => m LevelId
mxhairToPos :: MonadClientUI m => m (Maybe Point)
xhairToPos :: MonadClientUI m => m Point
setXHairFromGUI :: MonadClientUI m => Maybe Target -> m ()
clearAimMode :: MonadClientUI m => m ()
getFontSetup :: MonadClientUI m => m FontSetup
scoreToSlideshow :: MonadClientUI m => Int -> Status -> m Slideshow
defaultHistory :: MonadClientUI m => m History
tellAllClipPS :: MonadClientUI m => m ()
tellGameClipPS :: MonadClientUI m => m ()
elapsedSessionTimeGT :: MonadClientRead m => POSIXTime -> Int -> m Bool
resetSessionStart :: MonadClientUI m => m ()
resetGameStart :: MonadClientUI m => m ()

-- | The part of speech describing the actor or the "you" pronoun if he is
--   the leader of the observer's faction.
partActorLeader :: MonadClientUI m => ActorId -> m Part

-- | The part of speech with the actor's pronoun or "you" if a leader of
--   the client's faction.
partPronounLeader :: MonadClientUI m => ActorId -> m Part

-- | Try to read saved client game state from the file system.
tryRestore :: MonadClientUI m => m (Maybe (StateClient, Maybe SessionUI))

-- | Invoke pseudo-random computation with the generator kept in the
--   session.
rndToActionUI :: MonadClientUI m => Rnd a -> m a
tryOpenBrowser :: MonadClientUI m => String -> m Bool

-- | Write a UI request to the frontend and read a corresponding reply.
connFrontend :: MonadClientUI m => FrontReq a -> m a
displayFrame :: MonadClientUI m => Maybe Frame -> m ()


-- | Running and disturbance.
--   
--   The general rule is: whatever is behind you (and so ignored
--   previously), determines what you ignore moving forward. This is
--   calcaulated separately for the tiles to the left, to the right and in
--   the middle along the running direction. So, if you want to ignore
--   something start running when you stand on it (or to the right or left,
--   respectively) or by entering it (or passing to the right or left,
--   respectively).
--   
--   Some things are never ignored, such as: enemies seen, imporant
--   messages heard, solid tiles and actors in the way.
module Game.LambdaHack.Client.UI.RunM

-- | Continue running in the given direction.
continueRun :: MonadClientUI m => LevelId -> RunParams -> m (Either Text RequestTimed)

-- | This function implements the actual logic of running. It checks if we
--   have to stop running because something interesting cropped up, it
--   ajusts the direction given by the vector if we reached a corridor's
--   corner (we never change direction except in corridors) and it
--   increments the counter of traversed tiles.
--   
--   Note that while goto-xhair commands ignore items on the way, here we
--   stop wnenever we touch an item. Running is more cautious to compensate
--   that the player cannot specify the end-point of running. It's also
--   more suited to open, already explored terrain. Goto-xhair works better
--   with unknown terrain, e.g., it stops whenever an item is spotted, but
--   then ignores the item, leaving it to the player to mark the item
--   position as a goal of the next goto.
continueRunDir :: MonadClientUI m => RunParams -> m (Either Text Vector)
walkableDir :: COps -> Level -> Point -> Vector -> Bool
tryTurning :: MonadClientRead m => ActorId -> m (Either Text Vector)
checkAndRun :: MonadClientRead m => ActorId -> Vector -> m (Either Text Vector)


-- | Monadic operations on game messages.
module Game.LambdaHack.Client.UI.MsgM

-- | Add a shared message to the current report. Say if it was a duplicate.
msgAddDuplicate :: (MonadClientUI m, MsgShared a) => a -> Text -> m Bool

-- | Add a message comprising of two different texts, one to show, the
--   other to save to messages log, to the current report.
msgAddDistinct :: MonadClientUI m => MsgClassDistinct -> (Text, Text) -> m ()

-- | Add a message to the current report.
msgAdd :: (MonadClientUI m, MsgShared a) => a -> Text -> m ()

-- | Add a message to the current report. End previously collected report,
--   if any, with newline.
msgLnAdd :: (MonadClientUI m, MsgShared a) => a -> Text -> m ()

-- | Add a prompt with basic keys description.
promptMainKeys :: MonadClientUI m => m ()

-- | Store new report in the history and archive old report.
recordHistory :: MonadClientUI m => m ()

-- | Add a tutorial hint message to the current report.
tutorialHintMsgAdd :: MonadClientUI m => TutorialHints -> m ()


-- | Breadth first search and related algorithms using the client monad.
module Game.LambdaHack.Client.BfsM
invalidateBfsAid :: MonadClient m => ActorId -> m ()
invalidateBfsPathAid :: MonadClient m => ActorId -> m ()
invalidateBfsLid :: MonadClient m => LevelId -> m ()
invalidateBfsPathLid :: MonadClient m => Actor -> m ()
invalidateBfsAll :: MonadClient m => m ()
invalidateBfsPathAll :: MonadClient m => m ()
createBfs :: MonadClientRead m => Bool -> Word8 -> ActorId -> m (Array BfsDistance)

-- | Get cached BFS array and path or, if not stored, generate and store
--   first.
getCacheBfsAndPath :: forall m. MonadClient m => ActorId -> Point -> m (Array BfsDistance, Maybe AndPath)

-- | Get cached BFS array or, if not stored, generate and store first.
getCacheBfs :: MonadClient m => ActorId -> m (Array BfsDistance)

-- | Get cached BFS path or, if not stored, generate and store first.
getCachePath :: MonadClient m => ActorId -> Point -> m (Maybe AndPath)
createPath :: MonadClient m => ActorId -> Target -> m TgtAndPath
condBFS :: MonadClientRead m => ActorId -> m (Bool, Word8)

-- | Furthest (wrt paths) known position.
furthestKnown :: MonadClient m => ActorId -> m Point

-- | Closest reachable unknown tile position, if any.
--   
--   Note: some of these tiles are behind suspect tiles and they are chosen
--   in preference to more distant directly accessible unknown tiles. This
--   is in principle OK, but in dungeons with few hidden doors AI is at a
--   disadvantage (and with many hidden doors, it fares as well as a human
--   that deduced the dungeon properties). Changing Bfs to accomodate all
--   dungeon styles would be complex and would slow down the engine.
--   
--   If the level has inaccessible open areas (at least from the stairs AI
--   used) the level will be nevertheless here finally labeled as explored,
--   to enable transition to other levels. We should generally avoid such
--   levels, because digging and/or trying to find other stairs leading to
--   disconnected areas is not KISS so we don't do this in AI, so AI is at
--   a disadvantage.
--   
--   If the closest unknown is more than 126 tiles away from the targeting
--   actor, the level will marked as explored. We could complicate the code
--   and not mark if the unknown is too far as opposed to inaccessible, but
--   then if it is both too distant and inaccessible, AI would be
--   permanently stuck on such levels. To cope with this, escapes need to
--   be placed on open or small levels, or in dispersed enough that they
--   don't appear in such potentially unexplored potions of caves. Other
--   than that, this is rather harmless and hard to exploit, so let it be.
--   The principled way to fix this would be to extend BFS to
--   <tt>Word16</tt>, but then it takes too long to compute on maze levels,
--   so we'd need to optimize hard for JS.
closestUnknown :: MonadClient m => ActorId -> m (Maybe Point)

-- | Finds smells closest to the actor, except under the actor, because
--   actors consume smell only moving over them, not standing. Of the
--   closest, prefers the newest smell.
closestSmell :: MonadClient m => ActorId -> m [(Int, (Point, Time))]
data FleeViaStairsOrEscape
ViaStairs :: FleeViaStairsOrEscape
ViaStairsUp :: FleeViaStairsOrEscape
ViaStairsDown :: FleeViaStairsOrEscape
ViaEscape :: FleeViaStairsOrEscape
ViaExit :: FleeViaStairsOrEscape
ViaNothing :: FleeViaStairsOrEscape
ViaAnything :: FleeViaStairsOrEscape
embedBenefit :: MonadClientRead m => FleeViaStairsOrEscape -> ActorId -> [(Point, ItemBag)] -> m [(Double, (Point, ItemBag))]

-- | Closest (wrt paths) AI-triggerable tiles with embedded items. In AI,
--   the level the actor is on is either explored or the actor already has
--   a weapon equipped, so no need to explore further, he tries to find
--   enemies on other levels, but before that, he triggers other tiles in
--   hope of some loot or beneficial effect to enter next level with.
closestTriggers :: MonadClient m => FleeViaStairsOrEscape -> ActorId -> m [(Int, (Point, (Point, ItemBag)))]

-- | Check whether the actor has enough gear to go look for enemies. We
--   assume weapons in equipment are better than any among organs or at
--   least provide some essential diversity. Disabled if, due to doctrine,
--   actors follow leader and so would repeatedly move towards and away
--   from stairs at leader change, depending on current leader's gear.
--   Number of items of a single kind is ignored, because variety is
--   needed.
condEnoughGearM :: MonadClientRead m => ActorId -> m Bool

-- | Closest (wrt paths) items.
closestItems :: MonadClient m => ActorId -> m [(Int, (Point, ItemBag))]

-- | Closest (wrt paths) enemy actors.
closestFoes :: MonadClient m => [(ActorId, Actor)] -> ActorId -> m [(Int, (ActorId, Actor))]

-- | Closest (wrt paths) enemy or our unguarded stash locations. If it's
--   ours, we want to guard it, it enemy, loot it. Neutral and friendly
--   stashes not chased to avoid loops of bloodless takeovers.
closestStashes :: MonadClient m => ActorId -> m [(Int, (FactionId, Point))]
oursExploringAssocs :: FactionId -> State -> [(ActorId, Actor)]

-- | Find the nearest walkable position in dark, if any. Deterministic, to
--   let all friends gather up and defend in the same shelter. Ignore
--   position underfoot.
closestHideout :: MonadClient m => ActorId -> m (Maybe (Point, Int))
unexploredDepth :: MonadClientRead m => Bool -> LevelId -> m Bool
updatePathFromBfs :: MonadClient m => Bool -> BfsAndPath -> ActorId -> Point -> m (Array BfsDistance, Maybe AndPath)
instance GHC.Classes.Eq Game.LambdaHack.Client.BfsM.FleeViaStairsOrEscape
instance GHC.Show.Show Game.LambdaHack.Client.BfsM.FleeViaStairsOrEscape


-- | Assorted conditions used later on in AI logic.
module Game.LambdaHack.Client.AI.ConditionM

-- | Require that a target enemy is visible by the party.
condAimEnemyTargetedM :: MonadClientRead m => ActorId -> m Bool

-- | Require that a target enemy or enemy stash is visible by the party.
condAimEnemyOrStashM :: MonadClientRead m => ActorId -> m Bool

-- | Require that a target enemy is remembered on the actor's level.
condAimEnemyOrRememberedM :: MonadClientRead m => ActorId -> m Bool

-- | Require that a target non-enemy is visible by the party.
condAimNonEnemyPresentM :: MonadClientRead m => ActorId -> m Bool

-- | Require that the target is crucial to success, e.g., an item, or that
--   it's not too far away and so the changes to get it are high.
condAimCrucialM :: MonadClientRead m => ActorId -> m Bool

-- | Check if the target is a nonmoving enemy.
condTgtNonmovingEnemyM :: MonadClientRead m => ActorId -> m Bool

-- | Require the actor stands on or adjacent to a triggerable tile (e.g.,
--   stairs).
condAdjTriggerableM :: MonadStateRead m => Skills -> ActorId -> m Bool

-- | Produce the chess-distance-sorted list of non-low-HP, melee-cabable
--   foes on the level. We don't consider path-distance, because we are
--   interested in how soon the foe can close in to hit us, which can
--   diverge greately from path distance for short distances, e.g., when
--   terrain gets revealed. We don't consider non-moving actors, because
--   they can't chase us and also because they can't be aggresive so to
--   resolve the stalemate, the opposing AI has to be aggresive by ignoring
--   them and closing in to melee distance.
meleeThreatDistList :: [(ActorId, Actor)] -> ActorId -> State -> [(Int, (ActorId, Actor))]

-- | Require the actor blocks the paths of any of his party members.
condBlocksFriendsM :: MonadClientRead m => ActorId -> m Bool

-- | Require the actor stands over a weapon that would be auto-equipped, if
--   only it was a desirable item (checked elsewhere).
condFloorWeaponM :: MonadStateRead m => ActorId -> m Bool

-- | Check whether the actor has no weapon in equipment.
condNoEqpWeaponM :: MonadStateRead m => ActorId -> m Bool

-- | Require that the actor can project any items.
condCanProjectM :: MonadClientRead m => Int -> ActorId -> m Bool
condProjectListM :: MonadClientRead m => Int -> ActorId -> m [(Double, CStore, ItemId, ItemFull, ItemQuant)]

-- | Produce the list of items from the given stores available to the actor
--   and the items' values.
benAvailableItems :: DiscoveryBenefit -> ActorId -> [CStore] -> State -> [(Benefit, CStore, ItemId, ItemFull, ItemQuant)]
hinders :: Bool -> Bool -> Skills -> ItemFull -> Bool

-- | Require that the actor stands over a desirable item.
condDesirableFloorItemM :: MonadClientRead m => ActorId -> m Bool

-- | Produce the list of items on the ground beneath the actor that are
--   worth picking up.
benGroundItems :: MonadClientRead m => ActorId -> m [(Benefit, CStore, ItemId, ItemFull, ItemQuant)]
desirableItem :: COps -> Bool -> Double -> AspectRecord -> ItemKind -> Int -> Bool
condSupport :: MonadClientRead m => [(ActorId, Actor)] -> Int -> ActorId -> m Bool
condAloneM :: MonadStateRead m => [(ActorId, Actor)] -> ActorId -> m Bool

-- | Require that the actor stands in the dark and so would be betrayed by
--   his own equipped light,
condShineWouldBetrayM :: MonadStateRead m => ActorId -> m Bool

-- | Produce a list of acceptable adjacent points to flee to.
fleeList :: MonadClientRead m => [(ActorId, Actor)] -> ActorId -> m ([(Int, Point)], [(Int, Point)])


-- | Let AI pick the best target for an actor.
module Game.LambdaHack.Client.AI.PickTargetM

-- | Verify and possibly change the target of an actor. This function both
--   updates the target in the client state and returns the new target
--   explicitly.
refreshTarget :: MonadClient m => [(ActorId, Actor)] -> [(ActorId, Actor)] -> (ActorId, Actor) -> m (Maybe TgtAndPath)
computeTarget :: forall m. MonadClient m => [(ActorId, Actor)] -> [(ActorId, Actor)] -> ActorId -> m (Maybe TgtAndPath)


-- | Picking the AI actor to move and refreshing leader and non-leader
--   targets.
module Game.LambdaHack.Client.AI.PickActorM

-- | Pick a new leader from among the actors on the current level. Refresh
--   the target of the new leader, even if unchanged.
pickActorToMove :: MonadClient m => [(ActorId, Actor)] -> [(ActorId, Actor)] -> Maybe ActorId -> m ActorId

-- | Inspect the doctrines of the actor and set his target according to it.
setTargetFromDoctrines :: MonadClient m => [(ActorId, Actor)] -> [(ActorId, Actor)] -> ActorId -> m ()


-- | AI procedure for picking the best action for an actor.
module Game.LambdaHack.Client.AI.PickActionM

-- | Pick the most desirable AI ation for the actor.
pickAction :: MonadClient m => [(ActorId, Actor)] -> [(ActorId, Actor)] -> ActorId -> Bool -> m RequestTimed
actionStrategy :: MonadClient m => [(ActorId, Actor)] -> [(ActorId, Actor)] -> LevelId -> ActorId -> Bool -> m (Strategy RequestTimed)
waitBlockNow :: MonadClientRead m => m (Strategy RequestTimed)
yellNow :: MonadClientRead m => m (Strategy RequestTimed)
pickup :: MonadClientRead m => ActorId -> Bool -> m (Strategy RequestTimed)
equipItems :: MonadClientRead m => ActorId -> m (Strategy RequestTimed)
yieldUnneeded :: MonadClientRead m => ActorId -> m (Strategy RequestTimed)
unEquipItems :: MonadClientRead m => ActorId -> m (Strategy RequestTimed)
groupByEqpSlot :: [(ItemId, ItemFullKit)] -> EnumMap EqpSlot [(ItemId, ItemFullKit)]
bestByEqpSlot :: DiscoveryBenefit -> [(ItemId, ItemFullKit)] -> [(ItemId, ItemFullKit)] -> [([(Int, (ItemId, ItemFullKit))], [(Int, (ItemId, ItemFullKit))])]
harmful :: DiscoveryBenefit -> ItemId -> Bool
meleeBlocker :: MonadClient m => Skills -> ActorId -> m (Strategy RequestTimed)
meleeAny :: MonadClient m => ActorId -> m (Strategy RequestTimed)
trigger :: MonadClientRead m => ActorId -> FleeViaStairsOrEscape -> m (Strategy RequestTimed)
projectItem :: MonadClientRead m => Skills -> ActorId -> m (Strategy RequestTimed)
data ApplyItemGroup
applyItem :: MonadClientRead m => Skills -> ActorId -> ApplyItemGroup -> m (Strategy RequestTimed)
flee :: MonadClient m => Skills -> ActorId -> Bool -> [(Int, Point)] -> m (Strategy RequestTimed)
displaceFoe :: MonadClientRead m => ActorId -> m (Strategy RequestTimed)
displaceBlocker :: MonadClientRead m => ActorId -> Bool -> m (Strategy RequestTimed)
displaceTgt :: MonadClientRead m => ActorId -> Point -> Bool -> m (Strategy RequestTimed)
chase :: MonadClientRead m => Skills -> ActorId -> Bool -> Bool -> m (Strategy RequestTimed)
moveTowards :: MonadClientRead m => Skills -> ActorId -> Bool -> Point -> Point -> Bool -> m (Strategy Vector)
moveOrRunAid :: MonadClientRead m => Skills -> ActorId -> Vector -> m (Maybe RequestTimed)
instance GHC.Classes.Eq Game.LambdaHack.Client.AI.PickActionM.ApplyItemGroup


-- | Ways for the client to use AI to produce server requests, based on the
--   client's view of the game state.
module Game.LambdaHack.Client.AI

-- | Handle the move of an actor under AI control (regardless if the whole
--   faction is under human or computer control).
queryAI :: MonadClient m => ActorId -> m RequestAI

-- | Pick an actor to move and an action for him to perform, given an
--   optional previous candidate actor and action and the server-proposed
--   actor.
pickActorAndAction :: MonadClient m => [(ActorId, Actor)] -> [(ActorId, Actor)] -> Maybe ActorId -> ActorId -> m (ActorId, RequestTimed, Maybe (Point, Time))


-- | The monad for writing to the main game state.
module Game.LambdaHack.Atomic.MonadStateWrite

-- | The monad for writing to the main game state. Atomic updates
--   (<tt>UpdAtomic</tt>) are given semantics in this monad.
class MonadStateRead m => MonadStateWrite m
modifyState :: MonadStateWrite m => (State -> State) -> m ()
putState :: MonadStateWrite m => State -> m ()

-- | Exception signifying that atomic action failed because the information
--   it carries is inconsistent with the client's state, (e.g., because the
--   client knows too little to understand the command or already deduced
--   the state change from earlier commands or is confused, amnesiac or
--   sees illusory actors or tiles). Whenever we know the failure is
--   logically impossible, we don't throw the <tt>AtomicFail</tt>
--   exception, but insert a normal assertion or <tt>error</tt> call, which
--   are never caught nor handled.
newtype AtomicFail
AtomicFail :: String -> AtomicFail
atomicFail :: String -> a
updateLevel :: MonadStateWrite m => LevelId -> (Level -> Level) -> m ()
updateActor :: MonadStateWrite m => ActorId -> (Actor -> Actor) -> m ()
updateFaction :: MonadStateWrite m => FactionId -> (Faction -> Faction) -> m ()
moveActorMap :: MonadStateWrite m => ActorId -> Actor -> Actor -> m ()
swapActorMap :: MonadStateWrite m => ActorId -> Actor -> ActorId -> Actor -> m ()
insertBagContainer :: MonadStateWrite m => ItemBag -> Container -> m ()
insertItemContainer :: MonadStateWrite m => ItemId -> ItemQuant -> Container -> m ()
insertItemActor :: MonadStateWrite m => ItemId -> ItemQuant -> ActorId -> CStore -> m ()
deleteBagContainer :: MonadStateWrite m => ItemBag -> Container -> m ()
deleteItemContainer :: MonadStateWrite m => ItemId -> ItemQuant -> Container -> m ()
deleteItemActor :: MonadStateWrite m => ItemId -> ItemQuant -> ActorId -> CStore -> m ()
itemsMatch :: Item -> Item -> Bool
addItemToActorMaxSkills :: MonadStateWrite m => ItemId -> Item -> Int -> ActorId -> m ()
resetActorMaxSkills :: MonadStateWrite m => m ()
insertItemFloor :: MonadStateWrite m => ItemId -> ItemQuant -> LevelId -> Point -> m ()
insertItemEmbed :: MonadStateWrite m => ItemId -> ItemQuant -> LevelId -> Point -> m ()
insertItemOrgan :: MonadStateWrite m => ItemId -> ItemQuant -> ActorId -> m ()
insertItemEqp :: MonadStateWrite m => ItemId -> ItemQuant -> ActorId -> m ()
insertItemStash :: MonadStateWrite m => ItemId -> ItemQuant -> FactionId -> m ()
deleteItemFloor :: MonadStateWrite m => ItemId -> ItemQuant -> LevelId -> Point -> m ()
deleteItemEmbed :: MonadStateWrite m => ItemId -> ItemQuant -> LevelId -> Point -> m ()
deleteItemOrgan :: MonadStateWrite m => ItemId -> ItemQuant -> ActorId -> m ()
deleteItemEqp :: MonadStateWrite m => ItemId -> ItemQuant -> ActorId -> m ()
deleteItemStash :: MonadStateWrite m => ItemId -> ItemQuant -> FactionId -> m ()
rmFromBag :: ItemQuant -> ItemId -> ItemBag -> ItemBag
instance GHC.Show.Show Game.LambdaHack.Atomic.MonadStateWrite.AtomicFail
instance GHC.Exception.Type.Exception Game.LambdaHack.Atomic.MonadStateWrite.AtomicFail


-- | A set of atomic commands shared by client and server. These are the
--   largest building blocks that have no components that can be observed
--   in isolation.
--   
--   We try to make atomic commands respect the laws of energy and mass
--   conservation, unless they really can't, e.g., monster spawning. For
--   example item removal from equipment, in isolation, is not an atomic
--   command, but item dropped from equipment to the ground is. This makes
--   it easier to undo the commands. In principle, the commands are the
--   only way to affect the basic game state (<a>State</a>).
--   
--   See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Client-server-architecture</a>.
module Game.LambdaHack.Atomic.CmdAtomic

-- | Abstract syntax of atomic commands, that is, atomic game state
--   transformations.
data CmdAtomic

-- | atomic updates
UpdAtomic :: UpdAtomic -> CmdAtomic

-- | atomic special effects
SfxAtomic :: SfxAtomic -> CmdAtomic

-- | Abstract syntax of atomic updates, that is, atomic commands that
--   really change the <a>State</a>. Most of them are an encoding of a game
--   state diff, though they also carry some intentional hints that help
--   clients determine whether and how to communicate it to players.
data UpdAtomic
UpdRegisterItems :: [(ItemId, Item)] -> UpdAtomic
UpdCreateActor :: ActorId -> Actor -> [(ItemId, Item)] -> UpdAtomic
UpdDestroyActor :: ActorId -> Actor -> [(ItemId, Item)] -> UpdAtomic
UpdCreateItem :: Bool -> ItemId -> Item -> ItemQuant -> Container -> UpdAtomic
UpdDestroyItem :: Bool -> ItemId -> Item -> ItemQuant -> Container -> UpdAtomic
UpdSpotActor :: ActorId -> Actor -> UpdAtomic
UpdLoseActor :: ActorId -> Actor -> UpdAtomic
UpdSpotItem :: Bool -> ItemId -> ItemQuant -> Container -> UpdAtomic
UpdLoseItem :: Bool -> ItemId -> ItemQuant -> Container -> UpdAtomic
UpdSpotItemBag :: Bool -> Container -> ItemBag -> UpdAtomic
UpdLoseItemBag :: Bool -> Container -> ItemBag -> UpdAtomic
UpdMoveActor :: ActorId -> Point -> Point -> UpdAtomic
UpdWaitActor :: ActorId -> Watchfulness -> Watchfulness -> UpdAtomic
UpdDisplaceActor :: ActorId -> ActorId -> UpdAtomic
UpdMoveItem :: ItemId -> Int -> ActorId -> CStore -> CStore -> UpdAtomic
UpdRefillHP :: ActorId -> Int64 -> UpdAtomic
UpdRefillCalm :: ActorId -> Int64 -> UpdAtomic
UpdTrajectory :: ActorId -> Maybe ([Vector], Speed) -> Maybe ([Vector], Speed) -> UpdAtomic
UpdQuitFaction :: FactionId -> Maybe Status -> Maybe Status -> Maybe (FactionAnalytics, GenerationAnalytics) -> UpdAtomic
UpdSpotStashFaction :: Bool -> FactionId -> LevelId -> Point -> UpdAtomic
UpdLoseStashFaction :: Bool -> FactionId -> LevelId -> Point -> UpdAtomic
UpdLeadFaction :: FactionId -> Maybe ActorId -> Maybe ActorId -> UpdAtomic
UpdDiplFaction :: FactionId -> FactionId -> Diplomacy -> Diplomacy -> UpdAtomic
UpdDoctrineFaction :: FactionId -> Doctrine -> Doctrine -> UpdAtomic
UpdAutoFaction :: FactionId -> Bool -> UpdAtomic
UpdRecordKill :: ActorId -> ContentId ItemKind -> Int -> UpdAtomic
UpdAlterTile :: LevelId -> Point -> ContentId TileKind -> ContentId TileKind -> UpdAtomic
UpdAlterExplorable :: LevelId -> Int -> UpdAtomic
UpdAlterGold :: Int -> UpdAtomic
UpdSearchTile :: ActorId -> Point -> ContentId TileKind -> UpdAtomic
UpdHideTile :: ActorId -> Point -> ContentId TileKind -> UpdAtomic
UpdSpotTile :: LevelId -> [(Point, ContentId TileKind)] -> UpdAtomic
UpdLoseTile :: LevelId -> [(Point, ContentId TileKind)] -> UpdAtomic
UpdSpotEntry :: LevelId -> [(Point, PlaceEntry)] -> UpdAtomic
UpdLoseEntry :: LevelId -> [(Point, PlaceEntry)] -> UpdAtomic
UpdAlterSmell :: LevelId -> Point -> Time -> Time -> UpdAtomic
UpdSpotSmell :: LevelId -> [(Point, Time)] -> UpdAtomic
UpdLoseSmell :: LevelId -> [(Point, Time)] -> UpdAtomic
UpdTimeItem :: ItemId -> Container -> ItemTimers -> ItemTimers -> UpdAtomic
UpdAgeGame :: EnumSet LevelId -> UpdAtomic
UpdUnAgeGame :: EnumSet LevelId -> UpdAtomic
UpdDiscover :: Container -> ItemId -> ContentId ItemKind -> AspectRecord -> UpdAtomic
UpdCover :: Container -> ItemId -> ContentId ItemKind -> AspectRecord -> UpdAtomic
UpdDiscoverKind :: Container -> ItemKindIx -> ContentId ItemKind -> UpdAtomic
UpdCoverKind :: Container -> ItemKindIx -> ContentId ItemKind -> UpdAtomic
UpdDiscoverAspect :: Container -> ItemId -> AspectRecord -> UpdAtomic
UpdCoverAspect :: Container -> ItemId -> AspectRecord -> UpdAtomic
UpdDiscoverServer :: ItemId -> AspectRecord -> UpdAtomic
UpdCoverServer :: ItemId -> AspectRecord -> UpdAtomic
UpdPerception :: LevelId -> Perception -> Perception -> UpdAtomic
UpdRestart :: FactionId -> PerLid -> State -> Challenge -> ClientOptions -> SMGen -> UpdAtomic
UpdRestartServer :: State -> UpdAtomic
UpdResume :: FactionId -> PerLid -> UpdAtomic
UpdResumeServer :: State -> UpdAtomic
UpdKillExit :: FactionId -> UpdAtomic
UpdWriteSave :: UpdAtomic
UpdHearFid :: FactionId -> Maybe Int -> HearMsg -> UpdAtomic
UpdMuteMessages :: FactionId -> Bool -> UpdAtomic

-- | Symbolic representation of text messages about heard noises, sent by
--   server to clients and shown to players and used by AI.
data HearMsg
HearUpd :: UpdAtomic -> HearMsg
HearStrike :: ContentId ItemKind -> HearMsg
HearSummon :: Bool -> GroupName ItemKind -> Dice -> HearMsg
HearCollideTile :: HearMsg
HearTaunt :: Text -> HearMsg

-- | Abstract syntax of atomic special effects, that is, atomic commands
--   that only display special effects and don't change <a>State</a> nor
--   client state.
data SfxAtomic
SfxStrike :: ActorId -> ActorId -> ItemId -> SfxAtomic
SfxRecoil :: ActorId -> ActorId -> ItemId -> SfxAtomic
SfxSteal :: ActorId -> ActorId -> ItemId -> SfxAtomic
SfxRelease :: ActorId -> ActorId -> ItemId -> SfxAtomic
SfxProject :: ActorId -> ItemId -> SfxAtomic
SfxReceive :: ActorId -> ItemId -> SfxAtomic
SfxApply :: ActorId -> ItemId -> SfxAtomic
SfxCheck :: ActorId -> ItemId -> SfxAtomic
SfxTrigger :: ActorId -> LevelId -> Point -> ContentId TileKind -> SfxAtomic
SfxShun :: ActorId -> LevelId -> Point -> ContentId TileKind -> SfxAtomic
SfxEffect :: FactionId -> ActorId -> ItemId -> Effect -> Int64 -> SfxAtomic
SfxItemApplied :: Bool -> ItemId -> Container -> SfxAtomic
SfxMsgFid :: FactionId -> SfxMsg -> SfxAtomic
SfxRestart :: SfxAtomic
SfxCollideTile :: ActorId -> Point -> SfxAtomic
SfxTaunt :: Bool -> ActorId -> SfxAtomic

-- | Symbolic representation of text messages sent by server to clients and
--   shown to players.
data SfxMsg
SfxUnexpected :: ReqFailure -> SfxMsg
SfxExpected :: Text -> ReqFailure -> SfxMsg
SfxExpectedEmbed :: ItemId -> LevelId -> ReqFailure -> SfxMsg
SfxFizzles :: ItemId -> Container -> SfxMsg
SfxNothingHappens :: ItemId -> Container -> SfxMsg
SfxNoItemsForTile :: [[(Int, GroupName ItemKind)]] -> SfxMsg
SfxVoidDetection :: DetectKind -> SfxMsg
SfxUnimpressed :: ActorId -> SfxMsg
SfxSummonLackCalm :: ActorId -> SfxMsg
SfxSummonTooManyOwn :: ActorId -> SfxMsg
SfxSummonTooManyAll :: ActorId -> SfxMsg
SfxSummonFailure :: ActorId -> SfxMsg
SfxLevelNoMore :: SfxMsg
SfxLevelPushed :: SfxMsg
SfxBracedImmune :: ActorId -> SfxMsg
SfxEscapeImpossible :: SfxMsg
SfxStasisProtects :: SfxMsg
SfxWaterParalysisResisted :: SfxMsg
SfxTransImpossible :: SfxMsg
SfxIdentifyNothing :: SfxMsg
SfxPurposeNothing :: SfxMsg
SfxPurposeTooFew :: Int -> Int -> SfxMsg
SfxPurposeUnique :: SfxMsg
SfxPurposeNotCommon :: SfxMsg
SfxRerollNothing :: SfxMsg
SfxRerollNotRandom :: SfxMsg
SfxDupNothing :: SfxMsg
SfxDupUnique :: SfxMsg
SfxDupValuable :: SfxMsg
SfxColdFish :: SfxMsg
SfxReadyGoods :: SfxMsg
SfxTimerExtended :: ActorId -> ItemId -> CStore -> Delta Time -> SfxMsg
SfxCollideActor :: ActorId -> ActorId -> SfxMsg
SfxItemYield :: ItemId -> Int -> LevelId -> SfxMsg
undoUpdAtomic :: UpdAtomic -> Maybe UpdAtomic
undoSfxAtomic :: SfxAtomic -> SfxAtomic
undoCmdAtomic :: CmdAtomic -> Maybe CmdAtomic
instance GHC.Show.Show Game.LambdaHack.Atomic.CmdAtomic.UpdAtomic
instance GHC.Show.Show Game.LambdaHack.Atomic.CmdAtomic.HearMsg
instance GHC.Show.Show Game.LambdaHack.Atomic.CmdAtomic.SfxMsg
instance GHC.Show.Show Game.LambdaHack.Atomic.CmdAtomic.SfxAtomic
instance GHC.Show.Show Game.LambdaHack.Atomic.CmdAtomic.CmdAtomic


-- | Representation and computation of visiblity of atomic commands by
--   clients.
--   
--   See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Client-server-architecture</a>.
module Game.LambdaHack.Atomic.PosAtomicRead

-- | The type representing visibility of atomic commands to factions, based
--   on the position of the command, etc. Note that the server sees and
--   smells all positions. Also note that hearing is not covered because it
--   gives very restricted information, so hearing doesn't equal seeing
--   (and we assume smelling actors get lots of data from smells).
data PosAtomic

-- | whomever sees all the positions, notices
PosSight :: LevelId -> [Point] -> PosAtomic

-- | observers and the faction notice
PosFidAndSight :: FactionId -> LevelId -> [Point] -> PosAtomic

-- | whomever smells all the positions, notices
PosSmell :: LevelId -> [Point] -> PosAtomic

-- | whomever sees all the positions, notices
PosSightLevels :: [(LevelId, Point)] -> PosAtomic

-- | only the faction notices, server doesn't
PosFid :: FactionId -> PosAtomic

-- | faction and server notices
PosFidAndSer :: FactionId -> PosAtomic

-- | only the server notices
PosSer :: PosAtomic

-- | everybody notices
PosAll :: PosAtomic

-- | never broadcasted, but sent manually
PosNone :: PosAtomic

-- | Produce the positions where the atomic update takes place or, more
--   generally, the conditions under which the update can be noticed by a
--   client.
--   
--   The goal of this mechanics is to ensure that atomic commands involving
--   some positions visible by a client convey similar information as the
--   client would get by directly observing the changes of the portion of
--   server state limited to the visible positions. Consequently, when the
--   visible commands are later applied to the client's state, the state
--   stays consistent --- in sync with the server state and correctly
--   limited by visiblity. There is some wiggle room both in what "in sync"
--   and "visible" means and how they propagate through time.
--   
--   E.g., <tt>UpdDisplaceActor</tt> in a black room between two enemy
--   actors, with only one actor carrying a 0-radius light would not be
--   distinguishable by looking at the state (or the screen) from
--   <tt>UpdMoveActor</tt> of the illuminated actor, hence such
--   <tt>UpdDisplaceActor</tt> should not be observable, but
--   <tt>UpdMoveActor</tt> in similar cotext would be (or the former should
--   be perceived as the latter). However, to simplify, we assign as strict
--   visibility requirements to <tt>UpdMoveActor</tt> as to
--   <tt>UpdDisplaceActor</tt> and fall back to <tt>UpdSpotActor</tt>
--   (which provides minimal information that does not contradict state) if
--   the visibility is lower.
posUpdAtomic :: MonadStateRead m => UpdAtomic -> m PosAtomic

-- | Produce the positions where the atomic special effect takes place.
posSfxAtomic :: MonadStateRead m => SfxAtomic -> m PosAtomic

-- | All items introduced by the atomic command, to be used in it.
iidUpdAtomic :: UpdAtomic -> [ItemId]

-- | All items introduced by the atomic special effect, to be used in it.
iidSfxAtomic :: SfxAtomic -> [ItemId]

-- | Decompose an atomic action that is outside a client's visiblity. The
--   decomposed actions give less information that the original command,
--   but some of them may fall within the visibility range of the client.
--   The original action may give more information than even the total sum
--   of all actions it's broken into. E.g., <tt>UpdMoveActor</tt> informs
--   about the continued existence of the actor between moves vs popping
--   out of existence and then back in.
--   
--   This is computed in server's <tt>State</tt> from before performing the
--   command.
breakUpdAtomic :: MonadStateRead m => UpdAtomic -> m [UpdAtomic]

-- | What is the main map level the <tt>PosAtomic</tt> refers to, if any.
lidOfPos :: PosAtomic -> Maybe LevelId

-- | Given the client, its perception and an atomic command, determine if
--   the client notices the command.
seenAtomicCli :: Bool -> FactionId -> PerLid -> PosAtomic -> Bool

-- | Determine whether the server would see a command that has the given
--   visibilty conditions.
seenAtomicSer :: PosAtomic -> Bool
pointsProjBody :: Actor -> [Point] -> PosAtomic
posProjBody :: Actor -> PosAtomic
singleAid :: MonadStateRead m => ActorId -> m PosAtomic
doubleAid :: MonadStateRead m => ActorId -> ActorId -> m PosAtomic
singleContainerStash :: MonadStateRead m => Container -> m PosAtomic
singleContainerActor :: MonadStateRead m => Container -> m PosAtomic
instance GHC.Classes.Eq Game.LambdaHack.Atomic.PosAtomicRead.PosAtomic
instance GHC.Show.Show Game.LambdaHack.Atomic.PosAtomicRead.PosAtomic


-- | Semantics of atomic commands shared by client and server.
--   
--   See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Client-server-architecture</a>.
module Game.LambdaHack.Atomic.HandleAtomicWrite

-- | The game-state semantics of atomic game commands. There is no
--   corresponding definition for special effects (<tt>SfxAtomic</tt>),
--   because they don't modify <a>State</a>.
--   
--   For each of the commands, we are guaranteed that the client, the
--   command is addressed to, perceives all the positions the command
--   affects (as computed by <a>posUpdAtomic</a>). In the code for each
--   semantic function we additonally verify the client is aware of any
--   relevant items and/or actors and we throw the <tt>AtomicFail</tt>
--   exception if it's not. The server keeps copies of all clients' states
--   and, before sending a command to a client, applies it to the client's
--   state copy. If <tt>AtomicFail</tt> is signalled, the command is
--   ignored for that client. This enables simpler server code that
--   addresses commands to all clients that can see it, even though not all
--   are able to process it.
handleUpdAtomic :: MonadStateWrite m => UpdAtomic -> m ()
updRegisterItems :: MonadStateWrite m => [(ItemId, Item)] -> m ()
updCreateActor :: MonadStateWrite m => ActorId -> Actor -> [(ItemId, Item)] -> m ()
updDestroyActor :: MonadStateWrite m => ActorId -> Actor -> [(ItemId, Item)] -> m ()
updCreateItem :: MonadStateWrite m => ItemId -> Item -> ItemQuant -> Container -> m ()
updDestroyItem :: MonadStateWrite m => ItemId -> Item -> ItemQuant -> Container -> m ()
updSpotItemBag :: MonadStateWrite m => Container -> ItemBag -> m ()
updLoseItemBag :: MonadStateWrite m => Container -> ItemBag -> m ()
updMoveActor :: MonadStateWrite m => ActorId -> Point -> Point -> m ()
updWaitActor :: MonadStateWrite m => ActorId -> Watchfulness -> Watchfulness -> m ()
updDisplaceActor :: MonadStateWrite m => ActorId -> ActorId -> m ()
updMoveItem :: MonadStateWrite m => ItemId -> Int -> ActorId -> CStore -> CStore -> m ()
updRefillHP :: MonadStateWrite m => ActorId -> Int64 -> m ()
updRefillCalm :: MonadStateWrite m => ActorId -> Int64 -> m ()
updTrajectory :: MonadStateWrite m => ActorId -> Maybe ([Vector], Speed) -> Maybe ([Vector], Speed) -> m ()
updQuitFaction :: MonadStateWrite m => FactionId -> Maybe Status -> Maybe Status -> m ()
updSpotStashFaction :: MonadStateWrite m => FactionId -> LevelId -> Point -> m ()
updLoseStashFaction :: MonadStateWrite m => FactionId -> LevelId -> Point -> m ()
updLeadFaction :: MonadStateWrite m => FactionId -> Maybe ActorId -> Maybe ActorId -> m ()
updDiplFaction :: MonadStateWrite m => FactionId -> FactionId -> Diplomacy -> Diplomacy -> m ()
updDoctrineFaction :: MonadStateWrite m => FactionId -> Doctrine -> Doctrine -> m ()
updAutoFaction :: MonadStateWrite m => FactionId -> Bool -> m ()
updRecordKill :: MonadStateWrite m => ActorId -> ContentId ItemKind -> Int -> m ()
updAlterTile :: MonadStateWrite m => LevelId -> Point -> ContentId TileKind -> ContentId TileKind -> m ()
updAlterExplorable :: MonadStateWrite m => LevelId -> Int -> m ()
updSearchTile :: MonadStateWrite m => ActorId -> Point -> ContentId TileKind -> m ()
updSpotTile :: MonadStateWrite m => LevelId -> [(Point, ContentId TileKind)] -> m ()
updLoseTile :: MonadStateWrite m => LevelId -> [(Point, ContentId TileKind)] -> m ()
updAlterSmell :: MonadStateWrite m => LevelId -> Point -> Time -> Time -> m ()
updSpotSmell :: MonadStateWrite m => LevelId -> [(Point, Time)] -> m ()
updLoseSmell :: MonadStateWrite m => LevelId -> [(Point, Time)] -> m ()
updTimeItem :: MonadStateWrite m => ItemId -> Container -> ItemTimers -> ItemTimers -> m ()
updAgeGame :: MonadStateWrite m => EnumSet LevelId -> m ()
updUnAgeGame :: MonadStateWrite m => EnumSet LevelId -> m ()
ageLevel :: MonadStateWrite m => Delta Time -> LevelId -> m ()
updDiscover :: MonadStateWrite m => Container -> ItemId -> ContentId ItemKind -> AspectRecord -> m ()
updCover :: Container -> ItemId -> ContentId ItemKind -> AspectRecord -> m ()
updDiscoverKind :: MonadStateWrite m => Container -> ItemKindIx -> ContentId ItemKind -> m ()
discoverKind :: MonadStateWrite m => ItemKindIx -> ContentId ItemKind -> m ()
updCoverKind :: Container -> ItemKindIx -> ContentId ItemKind -> m ()
updDiscoverAspect :: MonadStateWrite m => Container -> ItemId -> AspectRecord -> m ()
discoverAspect :: MonadStateWrite m => ItemId -> AspectRecord -> m ()
updCoverAspect :: Container -> ItemId -> AspectRecord -> m ()
updDiscoverServer :: MonadStateWrite m => ItemId -> AspectRecord -> m ()
updCoverServer :: MonadStateWrite m => ItemId -> AspectRecord -> m ()
updRestart :: MonadStateWrite m => State -> m ()
updRestartServer :: MonadStateWrite m => State -> m ()
updResumeServer :: MonadStateWrite m => State -> m ()


-- | Atomic game state transformations, their representation and semantics.
--   
--   See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Client-server-architecture</a>.
module Game.LambdaHack.Atomic

-- | Abstract syntax of atomic commands, that is, atomic game state
--   transformations.
data CmdAtomic

-- | atomic updates
UpdAtomic :: UpdAtomic -> CmdAtomic

-- | atomic special effects
SfxAtomic :: SfxAtomic -> CmdAtomic

-- | Abstract syntax of atomic updates, that is, atomic commands that
--   really change the <a>State</a>. Most of them are an encoding of a game
--   state diff, though they also carry some intentional hints that help
--   clients determine whether and how to communicate it to players.
data UpdAtomic
UpdRegisterItems :: [(ItemId, Item)] -> UpdAtomic
UpdCreateActor :: ActorId -> Actor -> [(ItemId, Item)] -> UpdAtomic
UpdDestroyActor :: ActorId -> Actor -> [(ItemId, Item)] -> UpdAtomic
UpdCreateItem :: Bool -> ItemId -> Item -> ItemQuant -> Container -> UpdAtomic
UpdDestroyItem :: Bool -> ItemId -> Item -> ItemQuant -> Container -> UpdAtomic
UpdSpotActor :: ActorId -> Actor -> UpdAtomic
UpdLoseActor :: ActorId -> Actor -> UpdAtomic
UpdSpotItem :: Bool -> ItemId -> ItemQuant -> Container -> UpdAtomic
UpdLoseItem :: Bool -> ItemId -> ItemQuant -> Container -> UpdAtomic
UpdSpotItemBag :: Bool -> Container -> ItemBag -> UpdAtomic
UpdLoseItemBag :: Bool -> Container -> ItemBag -> UpdAtomic
UpdMoveActor :: ActorId -> Point -> Point -> UpdAtomic
UpdWaitActor :: ActorId -> Watchfulness -> Watchfulness -> UpdAtomic
UpdDisplaceActor :: ActorId -> ActorId -> UpdAtomic
UpdMoveItem :: ItemId -> Int -> ActorId -> CStore -> CStore -> UpdAtomic
UpdRefillHP :: ActorId -> Int64 -> UpdAtomic
UpdRefillCalm :: ActorId -> Int64 -> UpdAtomic
UpdTrajectory :: ActorId -> Maybe ([Vector], Speed) -> Maybe ([Vector], Speed) -> UpdAtomic
UpdQuitFaction :: FactionId -> Maybe Status -> Maybe Status -> Maybe (FactionAnalytics, GenerationAnalytics) -> UpdAtomic
UpdSpotStashFaction :: Bool -> FactionId -> LevelId -> Point -> UpdAtomic
UpdLoseStashFaction :: Bool -> FactionId -> LevelId -> Point -> UpdAtomic
UpdLeadFaction :: FactionId -> Maybe ActorId -> Maybe ActorId -> UpdAtomic
UpdDiplFaction :: FactionId -> FactionId -> Diplomacy -> Diplomacy -> UpdAtomic
UpdDoctrineFaction :: FactionId -> Doctrine -> Doctrine -> UpdAtomic
UpdAutoFaction :: FactionId -> Bool -> UpdAtomic
UpdRecordKill :: ActorId -> ContentId ItemKind -> Int -> UpdAtomic
UpdAlterTile :: LevelId -> Point -> ContentId TileKind -> ContentId TileKind -> UpdAtomic
UpdAlterExplorable :: LevelId -> Int -> UpdAtomic
UpdAlterGold :: Int -> UpdAtomic
UpdSearchTile :: ActorId -> Point -> ContentId TileKind -> UpdAtomic
UpdHideTile :: ActorId -> Point -> ContentId TileKind -> UpdAtomic
UpdSpotTile :: LevelId -> [(Point, ContentId TileKind)] -> UpdAtomic
UpdLoseTile :: LevelId -> [(Point, ContentId TileKind)] -> UpdAtomic
UpdSpotEntry :: LevelId -> [(Point, PlaceEntry)] -> UpdAtomic
UpdLoseEntry :: LevelId -> [(Point, PlaceEntry)] -> UpdAtomic
UpdAlterSmell :: LevelId -> Point -> Time -> Time -> UpdAtomic
UpdSpotSmell :: LevelId -> [(Point, Time)] -> UpdAtomic
UpdLoseSmell :: LevelId -> [(Point, Time)] -> UpdAtomic
UpdTimeItem :: ItemId -> Container -> ItemTimers -> ItemTimers -> UpdAtomic
UpdAgeGame :: EnumSet LevelId -> UpdAtomic
UpdUnAgeGame :: EnumSet LevelId -> UpdAtomic
UpdDiscover :: Container -> ItemId -> ContentId ItemKind -> AspectRecord -> UpdAtomic
UpdCover :: Container -> ItemId -> ContentId ItemKind -> AspectRecord -> UpdAtomic
UpdDiscoverKind :: Container -> ItemKindIx -> ContentId ItemKind -> UpdAtomic
UpdCoverKind :: Container -> ItemKindIx -> ContentId ItemKind -> UpdAtomic
UpdDiscoverAspect :: Container -> ItemId -> AspectRecord -> UpdAtomic
UpdCoverAspect :: Container -> ItemId -> AspectRecord -> UpdAtomic
UpdDiscoverServer :: ItemId -> AspectRecord -> UpdAtomic
UpdCoverServer :: ItemId -> AspectRecord -> UpdAtomic
UpdPerception :: LevelId -> Perception -> Perception -> UpdAtomic
UpdRestart :: FactionId -> PerLid -> State -> Challenge -> ClientOptions -> SMGen -> UpdAtomic
UpdRestartServer :: State -> UpdAtomic
UpdResume :: FactionId -> PerLid -> UpdAtomic
UpdResumeServer :: State -> UpdAtomic
UpdKillExit :: FactionId -> UpdAtomic
UpdWriteSave :: UpdAtomic
UpdHearFid :: FactionId -> Maybe Int -> HearMsg -> UpdAtomic
UpdMuteMessages :: FactionId -> Bool -> UpdAtomic

-- | Symbolic representation of text messages about heard noises, sent by
--   server to clients and shown to players and used by AI.
data HearMsg
HearUpd :: UpdAtomic -> HearMsg
HearStrike :: ContentId ItemKind -> HearMsg
HearSummon :: Bool -> GroupName ItemKind -> Dice -> HearMsg
HearCollideTile :: HearMsg
HearTaunt :: Text -> HearMsg

-- | Abstract syntax of atomic special effects, that is, atomic commands
--   that only display special effects and don't change <a>State</a> nor
--   client state.
data SfxAtomic
SfxStrike :: ActorId -> ActorId -> ItemId -> SfxAtomic
SfxRecoil :: ActorId -> ActorId -> ItemId -> SfxAtomic
SfxSteal :: ActorId -> ActorId -> ItemId -> SfxAtomic
SfxRelease :: ActorId -> ActorId -> ItemId -> SfxAtomic
SfxProject :: ActorId -> ItemId -> SfxAtomic
SfxReceive :: ActorId -> ItemId -> SfxAtomic
SfxApply :: ActorId -> ItemId -> SfxAtomic
SfxCheck :: ActorId -> ItemId -> SfxAtomic
SfxTrigger :: ActorId -> LevelId -> Point -> ContentId TileKind -> SfxAtomic
SfxShun :: ActorId -> LevelId -> Point -> ContentId TileKind -> SfxAtomic
SfxEffect :: FactionId -> ActorId -> ItemId -> Effect -> Int64 -> SfxAtomic
SfxItemApplied :: Bool -> ItemId -> Container -> SfxAtomic
SfxMsgFid :: FactionId -> SfxMsg -> SfxAtomic
SfxRestart :: SfxAtomic
SfxCollideTile :: ActorId -> Point -> SfxAtomic
SfxTaunt :: Bool -> ActorId -> SfxAtomic

-- | Symbolic representation of text messages sent by server to clients and
--   shown to players.
data SfxMsg
SfxUnexpected :: ReqFailure -> SfxMsg
SfxExpected :: Text -> ReqFailure -> SfxMsg
SfxExpectedEmbed :: ItemId -> LevelId -> ReqFailure -> SfxMsg
SfxFizzles :: ItemId -> Container -> SfxMsg
SfxNothingHappens :: ItemId -> Container -> SfxMsg
SfxNoItemsForTile :: [[(Int, GroupName ItemKind)]] -> SfxMsg
SfxVoidDetection :: DetectKind -> SfxMsg
SfxUnimpressed :: ActorId -> SfxMsg
SfxSummonLackCalm :: ActorId -> SfxMsg
SfxSummonTooManyOwn :: ActorId -> SfxMsg
SfxSummonTooManyAll :: ActorId -> SfxMsg
SfxSummonFailure :: ActorId -> SfxMsg
SfxLevelNoMore :: SfxMsg
SfxLevelPushed :: SfxMsg
SfxBracedImmune :: ActorId -> SfxMsg
SfxEscapeImpossible :: SfxMsg
SfxStasisProtects :: SfxMsg
SfxWaterParalysisResisted :: SfxMsg
SfxTransImpossible :: SfxMsg
SfxIdentifyNothing :: SfxMsg
SfxPurposeNothing :: SfxMsg
SfxPurposeTooFew :: Int -> Int -> SfxMsg
SfxPurposeUnique :: SfxMsg
SfxPurposeNotCommon :: SfxMsg
SfxRerollNothing :: SfxMsg
SfxRerollNotRandom :: SfxMsg
SfxDupNothing :: SfxMsg
SfxDupUnique :: SfxMsg
SfxDupValuable :: SfxMsg
SfxColdFish :: SfxMsg
SfxReadyGoods :: SfxMsg
SfxTimerExtended :: ActorId -> ItemId -> CStore -> Delta Time -> SfxMsg
SfxCollideActor :: ActorId -> ActorId -> SfxMsg
SfxItemYield :: ItemId -> Int -> LevelId -> SfxMsg

-- | The game-state semantics of atomic game commands. There is no
--   corresponding definition for special effects (<tt>SfxAtomic</tt>),
--   because they don't modify <a>State</a>.
--   
--   For each of the commands, we are guaranteed that the client, the
--   command is addressed to, perceives all the positions the command
--   affects (as computed by <a>posUpdAtomic</a>). In the code for each
--   semantic function we additonally verify the client is aware of any
--   relevant items and/or actors and we throw the <tt>AtomicFail</tt>
--   exception if it's not. The server keeps copies of all clients' states
--   and, before sending a command to a client, applies it to the client's
--   state copy. If <tt>AtomicFail</tt> is signalled, the command is
--   ignored for that client. This enables simpler server code that
--   addresses commands to all clients that can see it, even though not all
--   are able to process it.
handleUpdAtomic :: MonadStateWrite m => UpdAtomic -> m ()

-- | The type representing visibility of atomic commands to factions, based
--   on the position of the command, etc. Note that the server sees and
--   smells all positions. Also note that hearing is not covered because it
--   gives very restricted information, so hearing doesn't equal seeing
--   (and we assume smelling actors get lots of data from smells).
data PosAtomic

-- | whomever sees all the positions, notices
PosSight :: LevelId -> [Point] -> PosAtomic

-- | observers and the faction notice
PosFidAndSight :: FactionId -> LevelId -> [Point] -> PosAtomic

-- | whomever smells all the positions, notices
PosSmell :: LevelId -> [Point] -> PosAtomic

-- | whomever sees all the positions, notices
PosSightLevels :: [(LevelId, Point)] -> PosAtomic

-- | only the faction notices, server doesn't
PosFid :: FactionId -> PosAtomic

-- | faction and server notices
PosFidAndSer :: FactionId -> PosAtomic

-- | only the server notices
PosSer :: PosAtomic

-- | everybody notices
PosAll :: PosAtomic

-- | never broadcasted, but sent manually
PosNone :: PosAtomic

-- | Produce the positions where the atomic update takes place or, more
--   generally, the conditions under which the update can be noticed by a
--   client.
--   
--   The goal of this mechanics is to ensure that atomic commands involving
--   some positions visible by a client convey similar information as the
--   client would get by directly observing the changes of the portion of
--   server state limited to the visible positions. Consequently, when the
--   visible commands are later applied to the client's state, the state
--   stays consistent --- in sync with the server state and correctly
--   limited by visiblity. There is some wiggle room both in what "in sync"
--   and "visible" means and how they propagate through time.
--   
--   E.g., <tt>UpdDisplaceActor</tt> in a black room between two enemy
--   actors, with only one actor carrying a 0-radius light would not be
--   distinguishable by looking at the state (or the screen) from
--   <tt>UpdMoveActor</tt> of the illuminated actor, hence such
--   <tt>UpdDisplaceActor</tt> should not be observable, but
--   <tt>UpdMoveActor</tt> in similar cotext would be (or the former should
--   be perceived as the latter). However, to simplify, we assign as strict
--   visibility requirements to <tt>UpdMoveActor</tt> as to
--   <tt>UpdDisplaceActor</tt> and fall back to <tt>UpdSpotActor</tt>
--   (which provides minimal information that does not contradict state) if
--   the visibility is lower.
posUpdAtomic :: MonadStateRead m => UpdAtomic -> m PosAtomic

-- | Produce the positions where the atomic special effect takes place.
posSfxAtomic :: MonadStateRead m => SfxAtomic -> m PosAtomic

-- | All items introduced by the atomic command, to be used in it.
iidUpdAtomic :: UpdAtomic -> [ItemId]

-- | All items introduced by the atomic special effect, to be used in it.
iidSfxAtomic :: SfxAtomic -> [ItemId]

-- | Decompose an atomic action that is outside a client's visiblity. The
--   decomposed actions give less information that the original command,
--   but some of them may fall within the visibility range of the client.
--   The original action may give more information than even the total sum
--   of all actions it's broken into. E.g., <tt>UpdMoveActor</tt> informs
--   about the continued existence of the actor between moves vs popping
--   out of existence and then back in.
--   
--   This is computed in server's <tt>State</tt> from before performing the
--   command.
breakUpdAtomic :: MonadStateRead m => UpdAtomic -> m [UpdAtomic]

-- | What is the main map level the <tt>PosAtomic</tt> refers to, if any.
lidOfPos :: PosAtomic -> Maybe LevelId

-- | Given the client, its perception and an atomic command, determine if
--   the client notices the command.
seenAtomicCli :: Bool -> FactionId -> PerLid -> PosAtomic -> Bool

-- | Determine whether the server would see a command that has the given
--   visibilty conditions.
seenAtomicSer :: PosAtomic -> Bool

-- | The monad for writing to the main game state. Atomic updates
--   (<tt>UpdAtomic</tt>) are given semantics in this monad.
class MonadStateRead m => MonadStateWrite m
modifyState :: MonadStateWrite m => (State -> State) -> m ()
putState :: MonadStateWrite m => State -> m ()

-- | Exception signifying that atomic action failed because the information
--   it carries is inconsistent with the client's state, (e.g., because the
--   client knows too little to understand the command or already deduced
--   the state change from earlier commands or is confused, amnesiac or
--   sees illusory actors or tiles). Whenever we know the failure is
--   logically impossible, we don't throw the <tt>AtomicFail</tt>
--   exception, but insert a normal assertion or <tt>error</tt> call, which
--   are never caught nor handled.
newtype AtomicFail
AtomicFail :: String -> AtomicFail


-- | Abstract syntax of responses.
--   
--   See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Client-server-architecture</a>.
module Game.LambdaHack.Client.Response

-- | Abstract syntax of responses sent by server to an AI or UI client (or
--   a universal client that can handle both roles, which is why this type
--   is not separated into distinct AI and UI types). A response tells a
--   client how to update game state or what information to send to the
--   server.
data Response

-- | change <tt>State</tt> by performing this atomic update
RespUpdAtomicNoState :: UpdAtomic -> Response

-- | put the given <tt>State</tt>, which results from performing the atomic
--   update
RespUpdAtomic :: State -> UpdAtomic -> Response

-- | compute an AI move for the actor and send (the semantics of) it
RespQueryAI :: ActorId -> Response

-- | perform special effects (animations, messages, etc.)
RespSfxAtomic :: SfxAtomic -> Response

-- | check if the UI client wants to regain control
RespQueryUIunderAI :: Response

-- | prompt the human player for a command and send (the semantics of) it
RespQueryUI :: Response
instance GHC.Show.Show Game.LambdaHack.Client.Response.Response


-- | Descriptions of items.
module Game.LambdaHack.Client.UI.ItemDescription

-- | The part of speech describing the item.
partItem :: Int -> FactionId -> FactionDict -> Time -> ItemFull -> ItemQuant -> (Part, Part)
partItemShort :: Int -> FactionId -> FactionDict -> Time -> ItemFull -> ItemQuant -> (Part, Part)
partItemShortest :: Int -> FactionId -> FactionDict -> Time -> ItemFull -> ItemQuant -> (Part, Part)
partItemHigh :: Int -> FactionId -> FactionDict -> Time -> ItemFull -> ItemQuant -> ([Text], Part, Part)
partItemWsDetail :: DetailLevel -> Int -> FactionId -> FactionDict -> Int -> Time -> ItemFull -> ItemQuant -> Part
partItemWs :: Int -> FactionId -> FactionDict -> Int -> Time -> ItemFull -> ItemQuant -> Part
partItemWsShortest :: Int -> FactionId -> FactionDict -> Int -> Time -> ItemFull -> ItemQuant -> Part
partItemWsShort :: Int -> FactionId -> FactionDict -> Int -> Time -> ItemFull -> ItemQuant -> Part
partItemWsLong :: Int -> FactionId -> FactionDict -> Int -> Time -> ItemFull -> ItemQuant -> Part
partItemWsRanged :: Int -> FactionId -> FactionDict -> Bool -> DetailLevel -> Int -> Int -> Time -> ItemFull -> ItemQuant -> Part
partItemShortAW :: Int -> FactionId -> FactionDict -> Time -> ItemFull -> ItemQuant -> Part
partItemMediumAW :: Int -> FactionId -> FactionDict -> Time -> ItemFull -> ItemQuant -> Part
partItemShortWownW :: Int -> FactionId -> FactionDict -> Part -> Time -> ItemFull -> ItemQuant -> Part
viewItem :: ItemFull -> AttrCharW32
viewItemBenefitColored :: DiscoveryBenefit -> ItemId -> ItemFull -> AttrCharW32
itemDesc :: Int -> Bool -> FactionId -> FactionDict -> Int -> ItemDialogMode -> Time -> LevelId -> ItemFull -> ItemQuant -> AttrString
partItemN :: Int -> FactionId -> FactionDict -> Bool -> DetailLevel -> Int -> Time -> ItemFull -> ItemQuant -> (Part, Part)
textAllPowers :: Int -> DetailLevel -> Bool -> ItemFull -> ([Text], [Text], [Text])


-- | Display game data on the screen using one of the available frontends
--   (determined at compile time with cabal flags).
module Game.LambdaHack.Client.UI.DrawM
targetDesc :: MonadClientUI m => Maybe Target -> m (Maybe Text, Maybe Text)
targetDescXhair :: MonadClientUI m => m (Maybe Text, Maybe Text, Maybe Watchfulness)

-- | Draw the whole screen: level map and status area.
drawHudFrame :: MonadClientUI m => ColorMode -> LevelId -> m PreFrame
checkWarningHP :: UIOptions -> ActorId -> Int64 -> State -> Bool
checkWarningCalm :: UIOptions -> ActorId -> Int64 -> State -> Bool
drawFrameTerrain :: forall m. MonadClientUI m => LevelId -> m (Vector Word32)
drawFrameContent :: forall m. MonadClientUI m => LevelId -> m FrameForall
drawFramePath :: forall m. MonadClientUI m => LevelId -> m (FrameForall, FrameForall)
drawFrameActor :: forall m. MonadClientUI m => LevelId -> m FrameForall
drawFrameExtra :: forall m. MonadClientUI m => ColorMode -> LevelId -> m FrameForall
drawFrameStatus :: MonadClientUI m => LevelId -> m AttrString
drawArenaStatus :: COps -> Level -> Int -> AttrString
drawLeaderStatus :: MonadClientUI m => Int -> m AttrString
drawLeaderDamage :: MonadClientUI m => Int -> ActorId -> m AttrString
drawSelected :: MonadClientUI m => LevelId -> Int -> EnumSet ActorId -> m (Int, AttrString)
checkWarnings :: UIOptions -> ActorId -> State -> (Bool, Bool)


-- | A set of Frame monad operations.
module Game.LambdaHack.Client.UI.FrameM

-- | Draw the current level with the overlay on top.
drawOverlay :: MonadClientUI m => ColorMode -> Bool -> FontOverlayMap -> LevelId -> m PreFrame3
promptGetKey :: MonadClientUI m => ColorMode -> FontOverlayMap -> Bool -> [KM] -> m KM
addToMacro :: Map KM CmdTriple -> KM -> KeyMacroFrame -> KeyMacroFrame
dropEmptyMacroFrames :: KeyMacroFrame -> [KeyMacroFrame] -> (KeyMacroFrame, [KeyMacroFrame])
lastMacroFrame :: KeyMacroFrame -> [KeyMacroFrame] -> KeyMacroFrame
stopPlayBack :: MonadClientUI m => m ()

-- | Render animations on top of the current screen frame.
renderAnimFrames :: MonadClientUI m => LevelId -> Animation -> Maybe Bool -> m PreFrames3

-- | Render and display animations on top of the current screen frame.
animate :: MonadClientUI m => LevelId -> Animation -> m ()

-- | We wipe any actions in progress, but keep the data needed to repeat
--   the last global macros and the last command.
resetPlayBack :: MonadClientUI m => m ()
restoreLeaderFromRun :: MonadClientUI m => m ()
basicFrameForAnimation :: MonadClientUI m => LevelId -> Maybe Bool -> m PreFrame3


-- | Monadic operations on slideshows and related data.
module Game.LambdaHack.Client.UI.SlideshowM

-- | Add current report to the overlay, split the result and produce,
--   possibly, many slides.
overlayToSlideshow :: MonadClientUI m => Int -> [KM] -> OKX -> m Slideshow

-- | Split current report into a slideshow.
reportToSlideshow :: MonadClientUI m => [KM] -> m Slideshow

-- | Split current report into a slideshow. Keep report unchanged. Assume
--   the game either halts waiting for a key after this is shown, or many
--   slides are produced, all but the last are displayed with player promts
--   between and the last is either shown in full or ignored if inside
--   macro (can be recovered from history, if important). Unless the
--   prompts interrupt the macro, which is as well.
reportToSlideshowKeepHalt :: MonadClientUI m => Bool -> [KM] -> m Slideshow

-- | Display a message. Return value indicates if the player wants to
--   continue. Feature: if many pages, only the last SPACE exits (but first
--   ESC).
displaySpaceEsc :: MonadClientUI m => ColorMode -> Text -> m Bool

-- | Display a message. Ignore keypresses. Feature: if many pages, only the
--   last SPACE exits (but first ESC).
displayMore :: MonadClientUI m => ColorMode -> Text -> m ()
displayMoreKeep :: MonadClientUI m => ColorMode -> Text -> m ()

-- | Print a yes/no question and return the player's answer. Use black and
--   white colours to turn player's attention to the choice.
displayYesNo :: MonadClientUI m => ColorMode -> Text -> m Bool
getConfirms :: MonadClientUI m => ColorMode -> [KM] -> Slideshow -> m KM

-- | Display a, potentially, multi-screen menu and return the chosen key or
--   menu slot (and save the index in the whole menu so that the cursor can
--   again be placed at that spot next time menu is displayed).
--   
--   This function is one of only two sources of menus and so, effectively,
--   UI modes.
displayChoiceScreen :: forall m. MonadClientUI m => String -> ColorMode -> Bool -> Slideshow -> [KM] -> m KeyOrSlot

-- | Display a, potentially, multi-screen menu and return the chosen key or
--   menu slot (and save the index in the whole menu so that the cursor can
--   again be placed at that spot next time menu is displayed).
--   Additionally, display something on the right half of the screen,
--   depending on which menu item is currently highlighted
--   
--   This function is one of only two sources of menus and so, effectively,
--   UI modes.
displayChoiceScreenWithRightPane :: forall m. MonadClientUI m => (KeyOrSlot -> m OKX) -> Bool -> String -> ColorMode -> Bool -> Slideshow -> [KM] -> m KeyOrSlot

-- | A specialized variant of <a>displayChoiceScreenWithRightPane</a>.
displayChoiceScreenWithDefItemKey :: MonadClientUI m => (Int -> MenuSlot -> m OKX) -> Slideshow -> [KM] -> String -> m KeyOrSlot

-- | A variant providing for a keypress the information about the label of
--   the menu slot which was selected during the keypress.
displayChoiceScreenWithRightPaneKMKM :: forall m. MonadClientUI m => (KeyOrSlot -> m OKX) -> Bool -> String -> ColorMode -> Bool -> Slideshow -> [KM] -> m (Either (KM, KeyOrSlot) MenuSlot)

-- | Push the frame depicting the current level to the frame queue. Only
--   one line of the report is shown, as in animations, because it may not
--   be our turn, so we can't clear the message to see what is underneath.
pushFrame :: MonadClientUI m => Bool -> m ()
pushReportFrame :: MonadClientUI m => m ()
getMenuIx :: MonadClientUI m => String -> Int -> Int -> Int -> m Int
saveMenuIx :: MonadClientUI m => String -> Int -> Int -> m ()

-- | This is one step of UI menu management user session.
--   
--   There is limited looping involved to return a changed position in the
--   menu each time so that the surrounding code has anything interesting
--   to do. The exception is when finally confirming a selection, in which
--   case it's usually not changed compared to last step, but it's
--   presented differently to indicate it was confirmed.
--   
--   Any extra keys in the <a>OKX</a> argument on top of the those in
--   <tt>Slideshow</tt> argument need to be contained in the
--   <tt>[K.KM]</tt> argument. Otherwise they are not accepted.
stepChoiceScreen :: forall m. MonadClientUI m => Bool -> ColorMode -> Bool -> Slideshow -> [KM] -> m (Int, Int, Int, Int -> OKX -> m (Bool, Either (KM, KeyOrSlot) MenuSlot, Int))
navigationKeys :: [KM]

-- | Find a position in a menu. The arguments go from first menu line and
--   menu page to the last, in order. Their indexing is from 0. We select
--   the nearest item with the index equal or less to the pointer.
findKYX :: Int -> [OKX] -> Maybe (OKX, KYX, Int)
drawHighlight :: Int -> ButtonWidth -> Int -> AttrString -> AttrString
basicFrameWithoutReport :: MonadClientUI m => LevelId -> Maybe Bool -> m PreFrame3


-- | Helper functions for both inventory management and human commands.
module Game.LambdaHack.Client.UI.HandleHelperM

-- | Message describing the cause of failure of human command.
data FailError
showFailError :: FailError -> Text
type MError = Maybe FailError
mergeMError :: MError -> MError -> MError
type FailOrCmd a = Either FailError a
failWith :: MonadClientUI m => Text -> m (FailOrCmd a)
failSer :: MonadClientUI m => ReqFailure -> m (FailOrCmd a)
failMsg :: MonadClientUI m => Text -> m MError
weaveJust :: FailOrCmd a -> Either MError a

-- | Switches current pointman to the previous in the whole dungeon,
--   wrapping.
pointmanCycle :: MonadClientUI m => ActorId -> Bool -> Direction -> m MError

-- | Switches current pointman to the next on the level, if any, wrapping.
pointmanCycleLevel :: MonadClientUI m => ActorId -> Bool -> Direction -> m MError
partyAfterLeader :: MonadClientUI m => ActorId -> m [(ActorId, Actor, ActorUI)]

-- | Select a faction leader. False, if nothing to do.
pickLeader :: MonadClientUI m => Bool -> ActorId -> m Bool

-- | Perform look around in the current position of the xhair. Does nothing
--   outside aiming mode.
doLook :: MonadClientUI m => m ()
pickLeaderWithPointer :: MonadClientUI m => ActorId -> m MError
itemOverlay :: MonadClientUI m => [(ItemId, ItemQuant)] -> ItemDialogMode -> m OKX
skillsOverlay :: MonadClientUI m => ActorId -> m OKX

-- | Extract whole-dungeon statistics for each place kind, counting the
--   number of occurrences of each type of <a>PlaceEntry</a> for the given
--   place kind and gathering the set of levels on which any entry for that
--   place kind can be found.
placesFromState :: ContentData PlaceKind -> Bool -> State -> EnumMap (ContentId PlaceKind) (EnumSet LevelId, Int, Int, Int)
placesOverlay :: MonadClientUI m => m OKX
factionsFromState :: ItemRoles -> State -> [(FactionId, Faction)]
factionsOverlay :: MonadClientUI m => m OKX
describeMode :: MonadClientUI m => Bool -> ContentId ModeKind -> m (EnumMap DisplayFont Overlay)
modesOverlay :: MonadClientUI m => m OKX
pickNumber :: MonadClientUI m => Bool -> Int -> m (Either MError Int)
guardItemSize :: Actor -> State -> Int

-- | Produces a textual description of items at a position.
lookAtItems :: MonadClientUI m => Bool -> Point -> LevelId -> Maybe ActorId -> Maybe (Part, Bool) -> m (Text, Maybe Person)
lookAtStash :: MonadClientUI m => Point -> LevelId -> m Text

-- | Produces a textual description of everything at the requested level's
--   position.
lookAtPosition :: MonadClientUI m => Point -> LevelId -> m [(MsgClassShow, Text)]
displayOneMenuItem :: MonadClientUI m => (MenuSlot -> m OKX) -> [KM] -> Int -> MenuSlot -> m KM
okxItemLoreInline :: MonadClientUI m => (ItemId -> ItemFull -> Int -> Text) -> Int -> ItemDialogMode -> [(ItemId, ItemQuant)] -> Int -> MenuSlot -> m OKX
okxItemLoreMsg :: MonadClientUI m => (ItemId -> ItemFull -> Int -> Text) -> Int -> ItemDialogMode -> [(ItemId, ItemQuant)] -> MenuSlot -> m OKX
itemDescOverlays :: MonadClientUI m => Bool -> Int -> ItemDialogMode -> ItemId -> ItemQuant -> ItemFull -> Int -> m (Overlay, Overlay)
cycleLore :: MonadClientUI m => [m KM] -> [m KM] -> m ()
spoilsBlurb :: Text -> Int -> Int -> Text
ppContainerWownW :: MonadClientUI m => (ActorId -> m Part) -> Bool -> Container -> m [Part]
nxtGameMode :: COps -> Int -> (ContentId ModeKind, ModeKind)
itemOverlayFromState :: LevelId -> [(ItemId, ItemQuant)] -> Bool -> CCUI -> FactionId -> DiscoveryBenefit -> FontSetup -> State -> OKX

-- | Produces a textual description of the tile at a position.
lookAtTile :: MonadClientUI m => Bool -> Point -> LevelId -> Maybe ActorId -> Maybe Person -> m (Text, Text, [(Int, Part)])

-- | Produces a textual description of actors at a position.
lookAtActors :: MonadClientUI m => Point -> LevelId -> m (Text, Maybe (Part, Bool), Text)
guardItemVerbs :: Actor -> State -> [Part]
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.HandleHelperM.FailError
instance GHC.Show.Show Game.LambdaHack.Client.UI.HandleHelperM.FailError


-- | Display all the initial (not including high scores) screens at game
--   over.
module Game.LambdaHack.Client.UI.Watch.WatchQuitM
quitFactionUI :: MonadClientUI m => FactionId -> Maybe Status -> Maybe (FactionAnalytics, GenerationAnalytics) -> m ()
displayGameOverLoot :: MonadClientUI m => (ItemBag, Int) -> GenerationAnalytics -> m KM
displayGameOverAnalytics :: MonadClientUI m => FactionAnalytics -> GenerationAnalytics -> m KM
displayGameOverLore :: MonadClientUI m => SLore -> Bool -> GenerationAnalytics -> m KM
viewFinalLore :: forall m. MonadClientUI m => String -> ItemBag -> Text -> (ItemId -> ItemFull -> Int -> Text) -> ItemDialogMode -> m KM


-- | Common code for displaying atomic update and SFX commands.
module Game.LambdaHack.Client.UI.Watch.WatchCommonM
fadeOutOrIn :: MonadClientUI m => Bool -> m ()
markDisplayNeeded :: MonadClientUI m => LevelId -> m ()
lookAtMove :: MonadClientUI m => ActorId -> m ()
stopAtMove :: MonadClientUI m => ActorId -> m ()
aidVerbMU :: (MonadClientUI m, MsgShared a) => a -> ActorId -> Part -> m ()
aidVerbDuplicateMU :: (MonadClientUI m, MsgShared a) => a -> ActorId -> Part -> m Bool
itemVerbMUGeneral :: MonadClientUI m => Bool -> ItemId -> ItemQuant -> Part -> Container -> m Text
itemVerbMU :: (MonadClientUI m, MsgShared a) => a -> ItemId -> ItemQuant -> Part -> Container -> m ()
itemVerbMUShort :: (MonadClientUI m, MsgShared a) => a -> ItemId -> ItemQuant -> Part -> Container -> m ()
itemAidVerbMU :: (MonadClientUI m, MsgShared a) => a -> ActorId -> Part -> ItemId -> Either Int Int -> m ()
mitemAidVerbMU :: (MonadClientUI m, MsgShared a) => a -> ActorId -> Part -> ItemId -> Maybe Part -> m ()
itemAidDistinctMU :: MonadClientUI m => MsgClassDistinct -> ActorId -> Part -> Part -> ItemId -> m ()
manyItemsAidVerbMU :: (MonadClientUI m, MsgShared a) => a -> ActorId -> Part -> [(ItemId, ItemQuant)] -> (Int -> Either (Maybe Int) Int) -> m ()


-- | Display atomic update commands received by the client.
module Game.LambdaHack.Client.UI.Watch.WatchUpdAtomicM

-- | Visualize atomic updates sent to the client. This is done in the
--   global state after the command is executed and after the client state
--   is modified by the command. Doesn't modify client state (except a few
--   fields), but only client session (e.g., by displaying messages). This
--   is enforced by types.
watchRespUpdAtomicUI :: MonadClientUI m => UpdAtomic -> m ()
assignItemRole :: MonadClientUI m => Container -> ItemId -> m ()
data Threat
createActorUI :: MonadClientUI m => Bool -> ActorId -> Actor -> m ()
destroyActorUI :: MonadClientUI m => Bool -> ActorId -> Actor -> m ()
spotItemBag :: forall m. MonadClientUI m => Bool -> Container -> ItemBag -> m ()
recordItemLid :: MonadClientUI m => ItemId -> Container -> m ()
moveActor :: MonadClientUI m => ActorId -> Point -> Point -> m ()
displaceActorUI :: MonadClientUI m => ActorId -> ActorId -> m ()
moveItemUI :: MonadClientUI m => ItemId -> Int -> ActorId -> CStore -> CStore -> m ()
discover :: MonadClientUI m => Container -> ItemId -> m ()
ppHearMsg :: MonadClientUI m => Maybe Int -> HearMsg -> m Text
ppHearDistanceAdjective :: Maybe Int -> Text
ppHearDistanceAdverb :: Maybe Int -> Text
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.Watch.WatchUpdAtomicM.Threat


-- | Display atomic SFX commands received by the client.
module Game.LambdaHack.Client.UI.Watch.WatchSfxAtomicM

-- | Display special effects (text, animation) sent to the client. Don't
--   modify client state (except a few fields), but only client session
--   (e.g., by displaying messages). This is enforced by types.
watchRespSfxAtomicUI :: MonadClientUI m => SfxAtomic -> m ()
returnJustLeft :: MonadClientUI m => (MsgClassShowAndSave, Text) -> m (Maybe (Either (MsgClassShowAndSave, Text) (MsgClassDistinct, (Text, Text))))
ppSfxMsg :: MonadClientUI m => SfxMsg -> m (Maybe (Either (MsgClassShowAndSave, Text) (MsgClassDistinct, (Text, Text))))
strike :: MonadClientUI m => Bool -> ActorId -> ActorId -> ItemId -> m ()


-- | Display atomic commands received by the client.
module Game.LambdaHack.Client.UI.Watch

-- | Visualize atomic updates sent to the client. This is done in the
--   global state after the command is executed and after the client state
--   is modified by the command. Doesn't modify client state (except a few
--   fields), but only client session (e.g., by displaying messages). This
--   is enforced by types.
watchRespUpdAtomicUI :: MonadClientUI m => UpdAtomic -> m ()

-- | Display special effects (text, animation) sent to the client. Don't
--   modify client state (except a few fields), but only client session
--   (e.g., by displaying messages). This is enforced by types.
watchRespSfxAtomicUI :: MonadClientUI m => SfxAtomic -> m ()


-- | UI of inventory management.
module Game.LambdaHack.Client.UI.InventoryM
data Suitability
SuitsEverything :: Suitability
SuitsSomething :: (Maybe CStore -> ItemFull -> ItemQuant -> Bool) -> Suitability
data ResultItemDialogMode
RStore :: CStore -> [ItemId] -> ResultItemDialogMode
ROwned :: ItemId -> ResultItemDialogMode
RLore :: SLore -> MenuSlot -> [(ItemId, ItemQuant)] -> ResultItemDialogMode
RSkills :: MenuSlot -> ResultItemDialogMode
RPlaces :: MenuSlot -> ResultItemDialogMode
RFactions :: MenuSlot -> ResultItemDialogMode
RModes :: MenuSlot -> ResultItemDialogMode

-- | Let the human player choose a single, preferably suitable, item from a
--   list of items. Don't display stores empty for all actors. Start with a
--   non-empty store.
getFull :: MonadClientUI m => ActorId -> m Suitability -> (Actor -> ActorUI -> Skills -> ItemDialogMode -> State -> Text) -> (Actor -> ActorUI -> Skills -> ItemDialogMode -> State -> Text) -> [CStore] -> Bool -> Bool -> m (Either Text (CStore, [(ItemId, ItemQuant)]))

-- | Let a human player choose any item from a given group. Note that this
--   does not guarantee the chosen item belongs to the group, as the player
--   can override the choice. Used e.g., for applying and projecting.
getGroupItem :: MonadClientUI m => ActorId -> m Suitability -> Text -> Text -> Text -> Text -> [CStore] -> m (Either Text (CStore, ItemId))

-- | Display all items from a store and let the human player choose any or
--   switch to any other store. Used, e.g., for viewing inventory and item
--   descriptions.
getStoreItem :: MonadClientUI m => ActorId -> ItemDialogMode -> m (Either Text ResultItemDialogMode)
skillCloseUp :: MonadClientUI m => ActorId -> MenuSlot -> m (Text, AttrString)
placeCloseUp :: MonadClientUI m => [(ContentId PlaceKind, (EnumSet LevelId, Int, Int, Int))] -> Bool -> MenuSlot -> m (Text, [(DisplayFont, [AttrString])])
factionCloseUp :: MonadClientUI m => [(FactionId, Faction)] -> MenuSlot -> m (Text, [(DisplayFont, [AttrString])])
data ItemDialogState
ISuitable :: ItemDialogState
IAll :: ItemDialogState
accessModeBag :: ActorId -> State -> ItemDialogMode -> ItemBag
storeItemPrompt :: FactionId -> Actor -> ActorUI -> Skills -> ItemDialogMode -> State -> Text

-- | Let the human player choose a single, preferably suitable, item from a
--   list of items.
getItem :: MonadClientUI m => ActorId -> m Suitability -> (Actor -> ActorUI -> Skills -> ItemDialogMode -> State -> Text) -> (Actor -> ActorUI -> Skills -> ItemDialogMode -> State -> Text) -> ItemDialogMode -> [ItemDialogMode] -> Bool -> Bool -> m (Either Text ResultItemDialogMode)
data DefItemKey m
DefItemKey :: Either Text KM -> Bool -> ~m (Either Text ResultItemDialogMode) -> DefItemKey m
[defLabel] :: DefItemKey m -> Either Text KM
[defCond] :: DefItemKey m -> Bool
[defAction] :: DefItemKey m -> ~m (Either Text ResultItemDialogMode)
transition :: forall m. MonadClientUI m => ActorId -> m Suitability -> (Actor -> ActorUI -> Skills -> ItemDialogMode -> State -> Text) -> (Actor -> ActorUI -> Skills -> ItemDialogMode -> State -> Text) -> Bool -> ItemDialogMode -> [ItemDialogMode] -> ItemDialogState -> m (Either Text ResultItemDialogMode)
runDefMessage :: MonadClientUI m => [(KM, DefItemKey m)] -> Text -> m ()
runDefAction :: MonadClientUI m => [(KM, DefItemKey m)] -> (MenuSlot -> Either Text ResultItemDialogMode) -> KeyOrSlot -> m (Either Text ResultItemDialogMode)
runDefSkills :: MonadClientUI m => [(KM, DefItemKey m)] -> Text -> ActorId -> m (Either Text ResultItemDialogMode)
skillsInRightPane :: MonadClientUI m => ActorId -> Int -> MenuSlot -> m OKX
runDefPlaces :: MonadClientUI m => [(KM, DefItemKey m)] -> Text -> m (Either Text ResultItemDialogMode)
placesInRightPane :: MonadClientUI m => [(ContentId PlaceKind, (EnumSet LevelId, Int, Int, Int))] -> Int -> MenuSlot -> m OKX
runDefFactions :: MonadClientUI m => [(KM, DefItemKey m)] -> Text -> m (Either Text ResultItemDialogMode)
factionsInRightPane :: MonadClientUI m => [(FactionId, Faction)] -> Int -> MenuSlot -> m OKX
runDefModes :: MonadClientUI m => [(KM, DefItemKey m)] -> Text -> m (Either Text ResultItemDialogMode)
runDefInventory :: MonadClientUI m => [(KM, DefItemKey m)] -> Text -> ActorId -> ItemDialogMode -> [(ItemId, ItemQuant)] -> m (Either Text ResultItemDialogMode)
instance GHC.Classes.Eq Game.LambdaHack.Client.UI.InventoryM.ItemDialogState
instance GHC.Show.Show Game.LambdaHack.Client.UI.InventoryM.ItemDialogState
instance GHC.Show.Show Game.LambdaHack.Client.UI.InventoryM.ResultItemDialogMode


-- | Semantics of <a>Game.LambdaHack.Client.UI.HumanCmd</a> client commands
--   that do not return server requests,, but only change internal client
--   state. None of such commands takes game time.
module Game.LambdaHack.Client.UI.HandleHumanLocalM
macroHuman :: MonadClientUI m => [String] -> m ()

-- | Push a new macro frame to the stack whenever repeating a macro.
macroHumanTransition :: [KM] -> KeyMacroFrame -> [KeyMacroFrame] -> (KeyMacroFrame, [KeyMacroFrame])

-- | Display items from a given container store and possibly let the user
--   chose one.
chooseItemHuman :: MonadClientUI m => ActorId -> ItemDialogMode -> m MError
chooseItemDialogMode :: forall m. MonadClientUI m => ActorId -> Bool -> ItemDialogMode -> m (FailOrCmd ActorId)
chooseItemProjectHuman :: forall m. (MonadClient m, MonadClientUI m) => ActorId -> [TriggerItem] -> m MError
chooseItemApplyHuman :: forall m. MonadClientUI m => ActorId -> [TriggerItem] -> m MError

-- | On top of <a>permittedProjectClient</a>, it also checks legality of
--   aiming at the target and projection range. It also modifies
--   <tt>eps</tt>.
psuitReq :: (MonadClient m, MonadClientUI m) => ActorId -> m (Either Text (ItemFull -> Either ReqFailure (Point, Bool)))

-- | <pre>
--   &gt;&gt;&gt; let trigger1 = HumanCmd.TriggerItem{tiverb="verb", tiobject="object", tisymbols=[toContentSymbol 'a', toContentSymbol 'b']}
--   
--   &gt;&gt;&gt; let trigger2 = HumanCmd.TriggerItem{tiverb="verb2", tiobject="object2", tisymbols=[toContentSymbol 'c']}
--   
--   &gt;&gt;&gt; triggerSymbols [trigger1, trigger2]
--   "abc"
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; triggerSymbols []
--   ""
--   </pre>
triggerSymbols :: [TriggerItem] -> [ContentSymbol ItemKind]
pickLeaderHuman :: MonadClientUI m => Int -> m MError
pickLeaderWithPointerHuman :: MonadClientUI m => ActorId -> m MError

-- | Switch current pointman to the previous in the whole dungeon,
--   wrapping.
pointmanCycleHuman :: MonadClientUI m => ActorId -> Direction -> m MError

-- | Switch current pointman to the next on the viewed level, if any,
--   wrapping.
pointmanCycleLevelHuman :: MonadClientUI m => ActorId -> Direction -> m MError
selectActorHuman :: MonadClientUI m => ActorId -> m ()
selectNoneHuman :: MonadClientUI m => m ()
selectWithPointerHuman :: MonadClientUI m => m MError
repeatHuman :: MonadClientUI m => Int -> m ()
repeatHumanTransition :: Int -> KeyMacroFrame -> [KeyMacroFrame] -> (KeyMacroFrame, [KeyMacroFrame])
repeatLastHuman :: MonadClientUI m => Int -> m ()
repeatLastHumanTransition :: Int -> KeyMacroFrame -> KeyMacroFrame

-- | Starts and stops recording of macros.
recordHuman :: MonadClientUI m => m ()
recordHumanTransition :: KeyMacroFrame -> (KeyMacroFrame, Text)
allHistoryHuman :: forall m. MonadClientUI m => m ()
markVisionHuman :: MonadClientUI m => Int -> m ()
markSmellHuman :: MonadClientUI m => m ()
markSuspectHuman :: MonadClient m => Int -> m ()
markAnimHuman :: MonadClient m => m ()
overrideTutHuman :: MonadClientUI m => Int -> m ()
printScreenHuman :: MonadClientUI m => m ()

-- | End aiming mode, rejecting the current position, unless when on remote
--   level, in which case, return to our level.
cancelHuman :: MonadClientUI m => m ()

-- | Accept the current crosshair position as target, ending aiming mode,
--   if active.
acceptHuman :: (MonadClient m, MonadClientUI m) => ActorId -> m ()

-- | Cycle detail level of aiming mode descriptions, starting up.
detailCycleHuman :: MonadClientUI m => m ()
clearTargetIfItemClearHuman :: (MonadClient m, MonadClientUI m) => ActorId -> m ()
itemClearHuman :: MonadClientUI m => m ()

-- | Move the xhair. Assumes aiming mode.
moveXhairHuman :: MonadClientUI m => Vector -> Int -> m MError

-- | Start aiming.
aimTgtHuman :: MonadClientUI m => m ()

-- | Cycle aiming mode. Do not change position of the xhair, switch target
--   to point at different things at that position.
aimFloorHuman :: MonadClientUI m => m ()
aimEnemyHuman :: MonadClientUI m => m ()
aimItemHuman :: MonadClientUI m => m ()

-- | Change the displayed level in aiming mode to (at most) k levels
--   shallower. Enters aiming mode, if not already in one.
aimAscendHuman :: MonadClientUI m => Int -> m MError

-- | Tweak the <tt>eps</tt> parameter of the aiming digital line.
epsIncrHuman :: (MonadClient m, MonadClientUI m) => Direction -> m ()
xhairUnknownHuman :: (MonadClient m, MonadClientUI m) => ActorId -> m MError
xhairItemHuman :: (MonadClient m, MonadClientUI m) => ActorId -> m MError
xhairStairHuman :: (MonadClient m, MonadClientUI m) => ActorId -> Bool -> m MError
xhairPointerFloorHuman :: MonadClientUI m => m ()
xhairPointerMuteHuman :: MonadClientUI m => m ()
xhairPointerEnemyHuman :: MonadClientUI m => m ()
aimPointerFloorHuman :: MonadClientUI m => m ()
aimPointerEnemyHuman :: MonadClientUI m => m ()
chooseItemDialogModeLore :: forall m. MonadClientUI m => m (Maybe ResultItemDialogMode)
projectCheck :: MonadClientUI m => ActorId -> Point -> m (Maybe ReqFailure)
posFromXhair :: (MonadClient m, MonadClientUI m) => ActorId -> m (Either Text Point)
permittedApplyClient :: MonadClientUI m => ActorId -> m (Maybe CStore -> ItemFull -> ItemQuant -> Either ReqFailure Bool)

-- | End aiming mode, accepting the current position.
endAiming :: (MonadClient m, MonadClientUI m) => ActorId -> m ()
endAimingMsg :: MonadClientUI m => ActorId -> m ()
flashAiming :: MonadClientUI m => m ()
permittedProjectClient :: MonadClientUI m => ActorId -> m (ItemFull -> Either ReqFailure Bool)

-- | Check whether one is permitted to aim (for projecting) at a target.
--   The check is stricter for actor targets, assuming the player simply
--   wants to hit a single actor. In order to fine tune trick-shots, e.g.,
--   piercing many actors, other aiming modes should be used. Returns a
--   different <tt>seps</tt> if needed to reach the target.
--   
--   Note: Simple Perception check is not enough for the check, e.g.,
--   because the target actor can be obscured by a glass wall.
xhairLegalEps :: MonadClientUI m => ActorId -> m (Either Text Int)


-- | Semantics of <a>Game.LambdaHack.Client.UI.HumanCmd</a> client commands
--   that return server requests. A couple of them do not take time, the
--   rest does. Here prompts and menus are displayed, but any feedback
--   resulting from the commands (e.g., from inventory manipulation) is
--   generated later on, by the server, for all clients that witness the
--   results of the commands.
module Game.LambdaHack.Client.UI.HandleHumanGlobalM

-- | Pick command depending on area the mouse pointer is in. The first
--   matching area is chosen. If none match, only interrupt.
byAreaHuman :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> [(CmdArea, HumanCmd)] -> m (Either MError ReqUI)
byAimModeHuman :: MonadClientUI m => m (Either MError ReqUI) -> m (Either MError ReqUI) -> m (Either MError ReqUI)
composeIfLocalHuman :: MonadClientUI m => m (Either MError ReqUI) -> m (Either MError ReqUI) -> m (Either MError ReqUI)
composeUnlessErrorHuman :: MonadClientUI m => m (Either MError ReqUI) -> m (Either MError ReqUI) -> m (Either MError ReqUI)
compose2ndLocalHuman :: MonadClientUI m => m (Either MError ReqUI) -> m (Either MError ReqUI) -> m (Either MError ReqUI)
loopOnNothingHuman :: MonadClientUI m => m (Either MError ReqUI) -> m (Either MError ReqUI)
executeIfClearHuman :: MonadClientUI m => m (Either MError ReqUI) -> m (Either MError ReqUI)

-- | Leader waits a turn (and blocks, etc.).
waitHuman :: MonadClientUI m => ActorId -> m (FailOrCmd RequestTimed)

-- | Leader waits a 1/10th of a turn (and doesn't block, etc.).
waitHuman10 :: MonadClientUI m => ActorId -> m (FailOrCmd RequestTimed)

-- | Leader yells or yawns, if sleeping.
yellHuman :: MonadClientUI m => ActorId -> m (FailOrCmd RequestTimed)
moveRunHuman :: (MonadClient m, MonadClientUI m) => ActorId -> Bool -> Bool -> Bool -> Bool -> Vector -> m (FailOrCmd RequestTimed)
runOnceAheadHuman :: MonadClientUI m => ActorId -> m (Either MError RequestTimed)
moveOnceToXhairHuman :: (MonadClient m, MonadClientUI m) => ActorId -> m (FailOrCmd RequestTimed)
runOnceToXhairHuman :: (MonadClient m, MonadClientUI m) => ActorId -> m (FailOrCmd RequestTimed)
continueToXhairHuman :: (MonadClient m, MonadClientUI m) => ActorId -> m (FailOrCmd RequestTimed)
moveItemHuman :: forall m. MonadClientUI m => ActorId -> [CStore] -> CStore -> Maybe Text -> Bool -> m (FailOrCmd RequestTimed)
projectHuman :: (MonadClient m, MonadClientUI m) => ActorId -> m (FailOrCmd RequestTimed)
applyHuman :: MonadClientUI m => ActorId -> m (FailOrCmd RequestTimed)

-- | Ask for a direction and alter a tile, if possible.
alterDirHuman :: MonadClientUI m => ActorId -> m (FailOrCmd RequestTimed)

-- | Try to alter a tile using a feature under the pointer.
alterWithPointerHuman :: MonadClientUI m => ActorId -> m (FailOrCmd RequestTimed)

-- | Close nearby open tile; ask for direction, if there is more than one.
closeDirHuman :: MonadClientUI m => ActorId -> m (FailOrCmd RequestTimed)

-- | Display command help.
helpHuman :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> m (Either MError ReqUI)

-- | Display hint or, if already displayed, display help.
hintHuman :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> m (Either MError ReqUI)

-- | Display the dashboard.
dashboardHuman :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> m (Either MError ReqUI)
itemMenuHuman :: MonadClientUI m => ActorId -> (KM -> HumanCmd -> m (Either MError ReqUI)) -> m (Either MError ReqUI)
chooseItemMenuHuman :: MonadClientUI m => ActorId -> (KM -> HumanCmd -> m (Either MError ReqUI)) -> ItemDialogMode -> m (Either MError ReqUI)

-- | Display the main menu.
mainMenuHuman :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> m (Either MError ReqUI)

-- | Display the main menu and set <tt>swasAutomated</tt>.
mainMenuAutoOnHuman :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> m (Either MError ReqUI)

-- | Display the main menu and unset <tt>swasAutomated</tt>.
mainMenuAutoOffHuman :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> m (Either MError ReqUI)

-- | Display the settings menu.
settingsMenuHuman :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> m (Either MError ReqUI)

-- | Display the challenge menu.
challengeMenuHuman :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> m (Either MError ReqUI)
gameDifficultyIncr :: MonadClient m => Int -> m ()
gameFishToggle :: MonadClient m => m ()
gameGoodsToggle :: MonadClient m => m ()
gameWolfToggle :: MonadClient m => m ()
gameKeeperToggle :: MonadClient m => m ()
gameScenarioIncr :: MonadClientUI m => Int -> m ()
gameExitWithHuman :: MonadClientUI m => ExitStrategy -> m (FailOrCmd ReqUI)
data ExitStrategy
Restart :: ExitStrategy
Quit :: ExitStrategy
gameDropHuman :: MonadClientUI m => m ReqUI
gameExitHuman :: Monad m => m ReqUI
gameSaveHuman :: MonadClientUI m => m ReqUI
doctrineHuman :: MonadClientUI m => m (FailOrCmd ReqUI)
automateHuman :: MonadClientUI m => m (FailOrCmd ReqUI)
automateToggleHuman :: MonadClientUI m => m (FailOrCmd ReqUI)
automateBackHuman :: MonadClientUI m => m (Either MError ReqUI)
areaToRectangles :: MonadClientUI m => CmdArea -> m [Maybe Area]

-- | Actor attacks an enemy actor or his own projectile.
meleeAid :: (MonadClient m, MonadClientUI m) => ActorId -> ActorId -> m (FailOrCmd RequestTimed)

-- | Actor swaps position with another.
displaceAid :: MonadClientUI m => ActorId -> ActorId -> m (FailOrCmd RequestTimed)

-- | Leader moves or searches or alters. No visible actor at the position.
moveSearchAlter :: MonadClientUI m => ActorId -> Bool -> Vector -> m (FailOrCmd RequestTimed)
alterCommon :: MonadClientUI m => ActorId -> Bool -> Point -> m (FailOrCmd RequestTimed)
goToXhair :: (MonadClient m, MonadClientUI m) => ActorId -> Bool -> Bool -> m (FailOrCmd RequestTimed)
goToXhairExplorationMode :: (MonadClient m, MonadClientUI m) => ActorId -> Bool -> Bool -> m (FailOrCmd RequestTimed)
goToXhairGoTo :: (MonadClient m, MonadClientUI m) => ActorId -> Bool -> Bool -> m (FailOrCmd RequestTimed)
multiActorGoTo :: (MonadClient m, MonadClientUI m) => LevelId -> Point -> RunParams -> m (FailOrCmd (Bool, Vector))
moveOrSelectItem :: forall m. MonadClientUI m => ActorId -> [CStore] -> CStore -> Maybe Text -> Bool -> m (FailOrCmd RequestTimed)
selectItemsToMove :: forall m. MonadClientUI m => ActorId -> [CStore] -> CStore -> Maybe Text -> Bool -> m (FailOrCmd (CStore, [(ItemId, ItemQuant)]))
moveItems :: forall m. MonadClientUI m => ActorId -> [CStore] -> (CStore, [(ItemId, ItemQuant)]) -> CStore -> m RequestTimed
projectItem :: (MonadClient m, MonadClientUI m) => ActorId -> (CStore, (ItemId, ItemFull)) -> m (FailOrCmd RequestTimed)
applyItem :: MonadClientUI m => ActorId -> (CStore, (ItemId, ItemFullKit)) -> m (FailOrCmd RequestTimed)

-- | Try to alter a tile using a feature at the given position.
--   
--   We don't check if the tile is interesting, e.g., if any embedded item
--   can be triggered, because the player explicitely requested the action.
--   Consequently, even if all embedded items are recharching, the time
--   will be wasted and the server will describe the failure in detail.
alterTileAtPos :: MonadClientUI m => ActorId -> Point -> m (FailOrCmd RequestTimed)

-- | Verify that the tile can be transformed or any embedded item effect
--   triggered and the player is aware if the effect is dangerous or grave,
--   such as ending the game.
verifyAlters :: forall m. MonadClientUI m => ActorId -> Bool -> Point -> m (FailOrCmd ())
processTileActions :: forall m. MonadClientUI m => ActorId -> Bool -> Point -> [TileAction] -> m (FailOrCmd ())
verifyEscape :: MonadClientUI m => m (FailOrCmd ())
verifyToolEffect :: MonadClientUI m => LevelId -> CStore -> ItemFull -> m (FailOrCmd ())

-- | Close tile at given position.
closeTileAtPos :: MonadClientUI m => ActorId -> Point -> m (FailOrCmd RequestTimed)

-- | Adds message with proper names.
msgAddDone :: MonadClientUI m => Bool -> ActorId -> Point -> Text -> m ()

-- | Prompts user to pick a point.
pickPoint :: MonadClientUI m => ActorId -> Text -> m (Maybe Point)
generateMenu :: MonadClientUI m => (KM -> HumanCmd -> m (Either MError ReqUI)) -> FontOverlayMap -> [(Text, HumanCmd, Maybe HumanCmd, Maybe FontOverlayMap)] -> [String] -> String -> m (Either MError ReqUI)


-- | Semantics of human player commands.
module Game.LambdaHack.Client.UI.HandleHumanM

-- | The semantics of human player commands in terms of the client monad,
--   in context of the given <tt>km</tt> as the last action.
--   
--   Some time cosuming commands are enabled even in aiming mode, but
--   cannot be invoked in aiming mode on a remote level (level different
--   than the level of the leader). Commands that require a pointman fail
--   when no leader is designated.
cmdSemInCxtOfKM :: (MonadClient m, MonadClientUI m) => KM -> HumanCmd -> m (Either MError ReqUI)
updateKeyLast :: KM -> HumanCmd -> KeyMacroFrame -> KeyMacroFrame

-- | Commands that are forbidden on a remote level, because they would
--   usually take time when invoked on one, but not necessarily do what the
--   player expects. Note that some commands that normally take time are
--   not included, because they don't take time in aiming mode or their
--   individual sanity conditions include a remote level check.
noRemoteHumanCmd :: HumanCmd -> Bool
data CmdLeaderNeed m
cmdSemantics :: (MonadClient m, MonadClientUI m) => HumanCmd -> m (Either MError ReqUI)
cmdSemanticsLeader :: (MonadClient m, MonadClientUI m) => HumanCmd -> CmdLeaderNeed m
addNoError :: Monad m => m () -> CmdLeaderNeed m
addLeader :: Monad m => (ActorId -> m ()) -> CmdLeaderNeed m
weaveLeader :: Monad m => (ActorId -> m (FailOrCmd ReqUI)) -> CmdLeaderNeed m


-- | Ways for the client to use player input via UI to produce server
--   requests, based on the client's view (visualized for the player) of
--   the game state.
--   
--   This module is leaking quite a bit of implementation details for the
--   sake of <a>Game.LambdaHack.Client.LoopM</a>. After multiplayer is
--   enabled again and the new requirements sorted out, this should be
--   redesigned and some code moved down the module hierarhy tree, exposing
--   a smaller API here.
module Game.LambdaHack.Client.UI

-- | Handle the move of a human player.
queryUI :: (MonadClient m, MonadClientUI m) => m (Maybe RequestUI)
queryUIunderAI :: (MonadClient m, MonadClientUI m) => m RequestUI

-- | The monad that gives the client access to UI operations, but not to
--   modifying client state, except for the client-side pointman (as
--   opposed to pointman stores in faction data in main game state), which
--   is more of a UI concept, but is shared with AI to be able to keep it
--   when switching AI on/off and to save on typing.
class MonadClientRead m => MonadClientUI m
getsSession :: MonadClientUI m => (SessionUI -> a) -> m a
modifySession :: MonadClientUI m => (SessionUI -> SessionUI) -> m ()
updateClientLeader :: MonadClientUI m => ActorId -> m ()
getCacheBfs :: MonadClientUI m => ActorId -> m (Array BfsDistance)
getCachePath :: MonadClientUI m => ActorId -> Point -> m (Maybe AndPath)
putSession :: MonadClientUI m => SessionUI -> m ()
anyKeyPressed :: MonadClientUI m => m Bool
resetPressedKeys :: MonadClientUI m => m ()

-- | The information that is used across a human player playing session,
--   including many consecutive games in a single session, including
--   playing different teams. Some of it is saved, some is reset when a new
--   playing session starts. Nothing is tied to a faction/team, but instead
--   all to UI configuration and UI input and display history. An important
--   component is the frontend session.
data SessionUI
SessionUI :: Maybe RequestUI -> ReqDelay -> Bool -> Bool -> Maybe Target -> Maybe Target -> ActorDictUI -> ItemDictUI -> ItemRoles -> Maybe (CStore, CStore) -> ChanFrontend -> CCUI -> UIOptions -> Maybe AimMode -> Bool -> Maybe (ItemId, CStore, Bool) -> EnumSet ActorId -> Maybe RunParams -> History -> EnumMap (ContentId ModeKind) (Map Challenge Int) -> EnumSet (ContentId ModeKind) -> EnumSet (ContentId ModeKind) -> PointUI -> Bool -> KeyMacroFrame -> [KeyMacroFrame] -> EnumSet ActorId -> Int -> Bool -> Int -> Bool -> Int -> Bool -> Bool -> Maybe Bool -> Set Msg -> Bool -> Map String Int -> ChosenLore -> Bool -> Bool -> Bool -> POSIXTime -> POSIXTime -> Time -> Int -> Int -> SMGen -> SessionUI

-- | request created by a UI query but not yet sent to the server
[sreqPending] :: SessionUI -> Maybe RequestUI

-- | server delayed sending query to client or receiving request from
--   client
[sreqDelay] :: SessionUI -> ReqDelay

-- | player is now queried for a command
[sreqQueried] :: SessionUI -> Bool

-- | player requested to regain control from AI ASAP
[sregainControl] :: SessionUI -> Bool

-- | the common xhair
[sxhair] :: SessionUI -> Maybe Target

-- | xhair set for last GoTo
[sxhairGoTo] :: SessionUI -> Maybe Target

-- | assigned actor UI presentations
[sactorUI] :: SessionUI -> ActorDictUI

-- | assigned item first seen level
[sitemUI] :: SessionUI -> ItemDictUI

-- | assignment of roles to items
[sroles] :: SessionUI -> ItemRoles

-- | last item move stores
[slastItemMove] :: SessionUI -> Maybe (CStore, CStore)

-- | connection with the frontend
[schanF] :: SessionUI -> ChanFrontend

-- | UI client content
[sccui] :: SessionUI -> CCUI

-- | UI options as set by the player
[sUIOptions] :: SessionUI -> UIOptions

-- | aiming mode
[saimMode] :: SessionUI -> Maybe AimMode

-- | last mouse aiming not vacuus
[sxhairMoused] :: SessionUI -> Bool

-- | selected item, if any, it's store and whether to override suitability
--   check
[sitemSel] :: SessionUI -> Maybe (ItemId, CStore, Bool)

-- | the set of currently selected actors
[sselected] :: SessionUI -> EnumSet ActorId

-- | parameters of the current run, if any
[srunning] :: SessionUI -> Maybe RunParams

-- | history of messages
[shistory] :: SessionUI -> History

-- | the number of games won by the UI faction per game mode and per
--   difficulty level
[svictories] :: SessionUI -> EnumMap (ContentId ModeKind) (Map Challenge Int)

-- | camped games
[scampings] :: SessionUI -> EnumSet (ContentId ModeKind)

-- | restarted games
[srestarts] :: SessionUI -> EnumSet (ContentId ModeKind)

-- | mouse pointer position
[spointer] :: SessionUI -> PointUI

-- | whether to auto-clear prompts
[sautoYes] :: SessionUI -> Bool

-- | the head of the key macro stack
[smacroFrame] :: SessionUI -> KeyMacroFrame

-- | the tail of the key macro stack
[smacroStack] :: SessionUI -> [KeyMacroFrame]

-- | actors that just got out of sight
[slastLost] :: SessionUI -> EnumSet ActorId

-- | player just waited this many times
[swaitTimes] :: SessionUI -> Int

-- | the player just exited AI automation
[swasAutomated] :: SessionUI -> Bool

-- | mark leader and party FOV
[smarkVision] :: SessionUI -> Int

-- | mark smell, if the leader can smell
[smarkSmell] :: SessionUI -> Bool

-- | next game scenario number
[snxtScenario] :: SessionUI -> Int

-- | whether current game is a tutorial
[scurTutorial] :: SessionUI -> Bool

-- | whether next game is to be tutorial
[snxtTutorial] :: SessionUI -> Bool

-- | override display of tutorial hints
[soverrideTut] :: SessionUI -> Maybe Bool

-- | tutorial hints already shown this game
[susedHints] :: SessionUI -> Set Msg

-- | whether to mute all new messages
[smuteMessages] :: SessionUI -> Bool

-- | indices of last used menu items
[smenuIxMap] :: SessionUI -> Map String Int

-- | last lore chosen to display
[schosenLore] :: SessionUI -> ChosenLore

-- | current level needs displaying
[sdisplayNeeded] :: SessionUI -> Bool

-- | a frame was already displayed this turn
[sturnDisplayed] :: SessionUI -> Bool

-- | whether no visible report created last UI faction turn or the report
--   wiped out from screen since
[sreportNull] :: SessionUI -> Bool

-- | this session start time
[sstart] :: SessionUI -> POSIXTime

-- | this game start time
[sgstart] :: SessionUI -> POSIXTime

-- | clips from start of session to current game start
[sallTime] :: SessionUI -> Time

-- | this game current frame count
[snframes] :: SessionUI -> Int

-- | frame count from start of session to current game start
[sallNframes] :: SessionUI -> Int

-- | current random generator for UI
[srandomUI] :: SessionUI -> SMGen
data ReqDelay
ReqDelayNot :: ReqDelay
ReqDelayHandled :: ReqDelay
ReqDelayAlarm :: ReqDelay
emptySessionUI :: UIOptions -> SessionUI

-- | Visualize atomic updates sent to the client. This is done in the
--   global state after the command is executed and after the client state
--   is modified by the command. Doesn't modify client state (except a few
--   fields), but only client session (e.g., by displaying messages). This
--   is enforced by types.
watchRespUpdAtomicUI :: MonadClientUI m => UpdAtomic -> m ()

-- | Display special effects (text, animation) sent to the client. Don't
--   modify client state (except a few fields), but only client session
--   (e.g., by displaying messages). This is enforced by types.
watchRespSfxAtomicUI :: MonadClientUI m => SfxAtomic -> m ()

-- | Operations for all UI content types, gathered together.
data CCUI
CCUI :: InputContent -> ScreenContent -> CCUI
[coinput] :: CCUI -> InputContent
[coscreen] :: CCUI -> ScreenContent

-- | Options that affect the UI of the client, specified in the config
--   file. More documentation is in the default config file.
data UIOptions

-- | Modify client options with UI options.
applyUIOptions :: COps -> UIOptions -> ClientOptions -> ClientOptions
uOverrideCmdline :: UIOptions -> [String]

-- | Read and parse UI config file.
mkUIOptions :: RuleContent -> ClientOptions -> IO UIOptions

-- | Connection channel between a frontend and a client. Frontend acts as a
--   server, serving keys, etc., when given frames to display.
data ChanFrontend

-- | Initialize the frontend chosen by the player via client options.
chanFrontend :: MonadClientUI m => ScreenContent -> ClientOptions -> m ChanFrontend

-- | Try to read saved client game state from the file system.
tryRestore :: MonadClientUI m => m (Maybe (StateClient, Maybe SessionUI))
clientPrintUI :: MonadClientUI m => Text -> m ()
pushReportFrame :: MonadClientUI m => m ()

-- | Add a message to the current report.
msgAdd :: (MonadClientUI m, MsgShared a) => a -> Text -> m ()
data MsgClassShow
MsgPromptGeneric :: MsgClassShow
MsgPromptFocus :: MsgClassShow
MsgPromptMention :: MsgClassShow
MsgPromptModify :: MsgClassShow
MsgPromptActors :: MsgClassShow
MsgPromptItems :: MsgClassShow
MsgPromptAction :: MsgClassShow
MsgActionAlert :: MsgClassShow
MsgSpottedThreat :: MsgClassShow
stepQueryUIwithLeader :: (MonadClient m, MonadClientUI m) => m (Maybe RequestUI)

-- | Let the human player issue commands until any command takes time.
stepQueryUI :: (MonadClient m, MonadClientUI m) => m (Maybe ReqUI)


-- | Actor preferences for targets and actions, based on actor aspects.
module Game.LambdaHack.Client.Preferences

-- | Compute the whole <a>Benefit</a> structure, containing various facets
--   of AI item preference, for an item with the given effects and aspects.
totalUsefulness :: COps -> FactionId -> FactionDict -> ItemFull -> Benefit

-- | How much AI benefits from applying the effect. The first component is
--   benefit when applied to self, the second is benefit (preferably
--   negative) when applied to enemy (via melee). This represents benefit
--   from using the effect every <tt>avgItemDelay</tt> turns, so if the
--   item is not durable, the value is adjusted down elsewhere. The benefit
--   includes the drawback of having to use the actor's turn, except when
--   there is battle and item is a weapon and so there is usually nothing
--   better to do than to melee, or when the actor is stuck or idle or
--   laying in wait or luring an enemy from a safe distance. So there is
--   less than <tt>averageTurnValue</tt> included in each benefit, so in
--   case when turn is not spent, e.g, periodic activation or conditions,
--   the difference in value is only slight.
effectToBenefit :: COps -> FactionId -> FactionDict -> Effect -> (Double, Double)
averageTurnValue :: Double
avgItemDelay :: Double
avgItemLife :: Double
durabilityMult :: Double
organBenefit :: Double -> GroupName ItemKind -> COps -> FactionId -> FactionDict -> (Double, Int)
recBenefit :: GroupName ItemKind -> COps -> FactionId -> FactionDict -> (Double, Int)
fakeItem :: ContentId ItemKind -> ItemKind -> KindMean -> ItemFull
aspectToBenefit :: Aspect -> Double
capStat :: Double -> Double
aspectRecordToBenefit :: AspectRecord -> [Double]


-- | Handle atomic commands received by the client.
module Game.LambdaHack.Client.HandleAtomicM

-- | Client monad for saving a game.
class MonadClient m => MonadClientSetup m
saveClient :: MonadClientSetup m => m ()

-- | Effect of atomic actions on client state. It is calculated with the
--   global state from after the command is executed (except where the
--   supplied <tt>oldState</tt> is used).
cmdAtomicSemCli :: MonadClientSetup m => State -> UpdAtomic -> m ()
updateInMeleeDueToActor :: MonadClient m => Actor -> m ()
updateInMeleeDueToItem :: MonadClient m => ActorId -> CStore -> m ()
updateInMeleeInDungeon :: MonadClient m => m ()
wipeBfsIfItemAffectsSkills :: MonadClient m => CStore -> ActorId -> m ()
tileChangeAffectsBfs :: COps -> ContentId TileKind -> ContentId TileKind -> Bool
createActor :: MonadClient m => ActorId -> Actor -> [(ItemId, Item)] -> m ()
destroyActor :: MonadClient m => ActorId -> Actor -> Bool -> m ()
addItemToDiscoBenefit :: MonadClient m => ItemId -> m ()
perception :: MonadClient m => LevelId -> Perception -> Perception -> m ()
discoverKind :: MonadClient m => ItemKindIx -> m ()
discoverKindAndAspect :: MonadClient m => ItemKindIx -> m ()
coverKind :: ItemKindIx -> m ()
coverAspectAndKind :: ItemKindIx -> m ()
discoverAspect :: MonadClient m => ItemId -> m ()
coverAspect :: ItemId -> m ()
killExit :: MonadClient m => m ()


-- | Semantics of responses sent by the server to clients.
module Game.LambdaHack.Client.HandleResponseM

-- | Monad for executing atomic game state transformations on a client.
class MonadClient m => MonadClientAtomic m

-- | Execute an atomic update that changes the client's <a>State</a>.
execUpdAtomic :: MonadClientAtomic m => UpdAtomic -> m ()

-- | Put state that is intended to be the result of performing an atomic
--   update by the server on its copy of the client's <a>State</a>.
execPutState :: MonadClientAtomic m => State -> m ()

-- | Client monad in which one can send requests to the client.
class MonadClient m => MonadClientWriteRequest m
sendRequestAI :: MonadClientWriteRequest m => RequestAI -> m ()
sendRequestUI :: MonadClientWriteRequest m => RequestUI -> m ()
clientHasUI :: MonadClientWriteRequest m => m Bool

-- | Handle server responses.
--   
--   Note that for clients communicating with the server over the net,
--   <tt>RespUpdAtomicNoState</tt> should be used, because executing a
--   single command is cheaper than sending the whole state over the net.
--   However, for the standalone exe mode, with clients in the same process
--   as the server, a pointer to the state set with <tt>execPutState</tt>
--   is cheaper.
handleResponse :: (MonadClientSetup m, MonadClientUI m, MonadClientAtomic m, MonadClientWriteRequest m) => Response -> m ()


-- | The main loop of the client, processing human and computer player
--   moves turn by turn.
module Game.LambdaHack.Client.LoopM

-- | Client monad in which one can receive responses from the server.
class MonadClient m => MonadClientReadResponse m
receiveResponse :: MonadClientReadResponse m => m Response

-- | The main game loop for an AI or UI client. It receives responses from
--   the server, changes internal client state accordingly, analyzes
--   ensuing human or AI commands and sends resulting requests to the
--   server. Depending on whether it's an AI or UI client, it sends AI or
--   human player requests.
--   
--   The loop is started in client state that is empty except for the
--   <tt>sside</tt> and <tt>seps</tt> fields, see <a>emptyStateClient</a>.
loopCli :: (MonadClientSetup m, MonadClientUI m, MonadClientAtomic m, MonadClientReadResponse m, MonadClientWriteRequest m) => CCUI -> UIOptions -> ClientOptions -> Bool -> m ()
initAI :: MonadClient m => m ()
initUI :: (MonadClient m, MonadClientUI m) => CCUI -> m ()
loopAI :: (MonadClientSetup m, MonadClientUI m, MonadClientAtomic m, MonadClientReadResponse m, MonadClientWriteRequest m) => m ()

-- | Alarm after this many seconds without server querying us for a
--   command.
longestDelay :: POSIXTime

-- | The argument is the time of last UI query from the server. After
--   <tt>longestDelay</tt> seconds past this date, the client considers
--   itself ignored and displays a warning and, at a keypress, gives direct
--   control to the player, no longer waiting for the server to prompt it
--   to do so.
loopUI :: (MonadClientSetup m, MonadClientUI m, MonadClientAtomic m, MonadClientReadResponse m, MonadClientWriteRequest m) => POSIXTime -> m ()


-- | Semantics of responses that are sent from server to clients, in terms
--   of client state transformations, and semantics of human commands and
--   AI moves, in terms of requests to be sent from the client to the
--   server.
--   
--   See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Client-server-architecture</a>.
module Game.LambdaHack.Client

-- | The main game loop for an AI or UI client. It receives responses from
--   the server, changes internal client state accordingly, analyzes
--   ensuing human or AI commands and sends resulting requests to the
--   server. Depending on whether it's an AI or UI client, it sends AI or
--   human player requests.
--   
--   The loop is started in client state that is empty except for the
--   <tt>sside</tt> and <tt>seps</tt> fields, see <a>emptyStateClient</a>.
loopCli :: (MonadClientSetup m, MonadClientUI m, MonadClientAtomic m, MonadClientReadResponse m, MonadClientWriteRequest m) => CCUI -> UIOptions -> ClientOptions -> Bool -> m ()

-- | Requests sent by AI clients to the server. If faction leader is to be
--   changed, it's included as the second component.
type RequestAI = (ReqAI, Maybe ActorId)

-- | Possible forms of requests sent by AI clients.
data ReqAI
ReqAINop :: ReqAI
ReqAITimed :: RequestTimed -> ReqAI

-- | Requests sent by UI clients to the server. If faction leader is to be
--   changed, it's included as the second component.
type RequestUI = (ReqUI, Maybe ActorId)

-- | Possible forms of requests sent by UI clients.
data ReqUI
ReqUINop :: ReqUI
ReqUITimed :: RequestTimed -> ReqUI
ReqUIGameRestart :: GroupName ModeKind -> Challenge -> ReqUI
ReqUIGameDropAndExit :: ReqUI
ReqUIGameSaveAndExit :: ReqUI
ReqUIGameSave :: ReqUI
ReqUIDoctrine :: Doctrine -> ReqUI
ReqUIAutomate :: ReqUI

-- | Requests that take game time.
data RequestTimed
ReqMove :: Vector -> RequestTimed
ReqMelee :: ActorId -> ItemId -> CStore -> RequestTimed
ReqDisplace :: ActorId -> RequestTimed
ReqAlter :: Point -> RequestTimed
ReqWait :: RequestTimed
ReqWait10 :: RequestTimed
ReqYell :: RequestTimed
ReqMoveItems :: [(ItemId, Int, CStore, CStore)] -> RequestTimed
ReqProject :: Point -> Int -> ItemId -> CStore -> RequestTimed
ReqApply :: ItemId -> CStore -> RequestTimed

-- | Abstract syntax of responses sent by server to an AI or UI client (or
--   a universal client that can handle both roles, which is why this type
--   is not separated into distinct AI and UI types). A response tells a
--   client how to update game state or what information to send to the
--   server.
data Response

-- | change <tt>State</tt> by performing this atomic update
RespUpdAtomicNoState :: UpdAtomic -> Response

-- | put the given <tt>State</tt>, which results from performing the atomic
--   update
RespUpdAtomic :: State -> UpdAtomic -> Response

-- | compute an AI move for the actor and send (the semantics of) it
RespQueryAI :: ActorId -> Response

-- | perform special effects (animations, messages, etc.)
RespSfxAtomic :: SfxAtomic -> Response

-- | check if the UI client wants to regain control
RespQueryUIunderAI :: Response

-- | prompt the human player for a command and send (the semantics of) it
RespQueryUI :: Response

-- | Operations for all UI content types, gathered together.
data CCUI

-- | Options that affect the UI of the client, specified in the config
--   file. More documentation is in the default config file.
data UIOptions

-- | Modify client options with UI options.
applyUIOptions :: COps -> UIOptions -> ClientOptions -> ClientOptions
uOverrideCmdline :: UIOptions -> [String]

-- | Read and parse UI config file.
mkUIOptions :: RuleContent -> ClientOptions -> IO UIOptions


-- | Temporary pseudo-organ (condition) definitions.
module Content.ItemKindTemporary
pattern S_IMMOBILE :: GroupName ItemKind
pattern S_PACIFIED :: GroupName ItemKind
pattern S_IRREPLACEABLE :: GroupName ItemKind
pattern S_RETAINING :: GroupName ItemKind
pattern S_IMPATIENT :: GroupName ItemKind
pattern S_DISPOSSESSED :: GroupName ItemKind
pattern S_WITHHOLDING :: GroupName ItemKind
pattern S_PARSIMONIOUS :: GroupName ItemKind
pattern S_MORE_MOBILE :: GroupName ItemKind
pattern S_MORE_COMBATIVE :: GroupName ItemKind
pattern S_MORE_DISPLACING :: GroupName ItemKind
pattern S_MORE_MODIFYING :: GroupName ItemKind
pattern S_MORE_PATIENT :: GroupName ItemKind
pattern S_MORE_TIDY :: GroupName ItemKind
pattern S_MORE_PROJECTING :: GroupName ItemKind
pattern S_MORE_PRACTICAL :: GroupName ItemKind
pattern S_STRENGTHENED :: GroupName ItemKind
pattern S_WEAKENED :: GroupName ItemKind
pattern S_PROTECTED_FROM_MELEE :: GroupName ItemKind
pattern S_PROTECTED_FROM_RANGED :: GroupName ItemKind
pattern S_DEFENSELESS :: GroupName ItemKind
pattern S_RESOLUTE :: GroupName ItemKind
pattern S_HASTED :: GroupName ItemKind
pattern S_SLOWED :: GroupName ItemKind
pattern S_FAR_SIGHTED :: GroupName ItemKind
pattern S_BLIND :: GroupName ItemKind
pattern S_KEEN_SMELLING :: GroupName ItemKind
pattern S_FOUL_SMELLING :: GroupName ItemKind
pattern S_ROSE_SMELLING :: GroupName ItemKind
pattern S_RANGED_DEFLECTING :: GroupName ItemKind
pattern S_MELEE_DEFLECTING :: GroupName ItemKind
pattern S_SHINY_EYED :: GroupName ItemKind
pattern S_DEAFENED :: GroupName ItemKind
pattern S_DEAF :: GroupName ItemKind
pattern S_DRUNK :: GroupName ItemKind
pattern S_FRENZIED :: GroupName ItemKind
pattern S_REGENERATING :: GroupName ItemKind
pattern S_POISONED :: GroupName ItemKind
pattern S_SLOW_RESISTANT :: GroupName ItemKind
pattern S_POISON_RESISTANT :: GroupName ItemKind
temporariesGNSingleton :: [GroupName ItemKind]
noStatGN :: [GroupName ItemKind]
bonusStatGN :: [GroupName ItemKind]
temporaries :: [ItemKind]


-- | Blast definitions.
module Content.ItemKindBlast
pattern S_FIRECRACKER :: GroupName ItemKind
pattern S_VIOLENT_FRAGMENTATION :: GroupName ItemKind
pattern S_FRAGMENTATION :: GroupName ItemKind
pattern S_FOCUSED_FRAGMENTATION :: GroupName ItemKind
pattern S_VIOLENT_CONCUSSION :: GroupName ItemKind
pattern S_CONCUSSION :: GroupName ItemKind
pattern S_FOCUSED_CONCUSSION :: GroupName ItemKind
pattern S_VIOLENT_FLASH :: GroupName ItemKind
pattern S_FOCUSED_FLASH :: GroupName ItemKind
pattern S_GLASS_HAIL :: GroupName ItemKind
pattern S_FOCUSED_GLASS_HAIL :: GroupName ItemKind
pattern S_PHEROMONE :: GroupName ItemKind
pattern S_CALMING_MIST :: GroupName ItemKind
pattern S_DISTRESSING_ODOR :: GroupName ItemKind
pattern S_HEALING_MIST :: GroupName ItemKind
pattern S_HEALING_MIST_2 :: GroupName ItemKind
pattern S_WOUNDING_MIST :: GroupName ItemKind
pattern S_DISTORTION :: GroupName ItemKind
pattern S_SMOKE :: GroupName ItemKind
pattern S_BOILING_WATER :: GroupName ItemKind
pattern S_GLUE :: GroupName ItemKind
pattern S_WASTE :: GroupName ItemKind
pattern S_ANTI_SLOW_MIST :: GroupName ItemKind
pattern S_ANTIDOTE_MIST :: GroupName ItemKind
pattern S_SLEEP_MIST :: GroupName ItemKind
pattern S_DENSE_SHOWER :: GroupName ItemKind
pattern S_SPARSE_SHOWER :: GroupName ItemKind
pattern S_MELEE_PROTECTIVE_BALM :: GroupName ItemKind
pattern S_RANGE_PROTECTIVE_BALM :: GroupName ItemKind
pattern S_DEFENSELESSNESS_RUNOUT :: GroupName ItemKind
pattern S_RESOLUTION_DUST :: GroupName ItemKind
pattern S_HASTE_SPRAY :: GroupName ItemKind
pattern S_VIOLENT_SLOWNESS_MIST :: GroupName ItemKind
pattern S_SLOWNESS_MIST :: GroupName ItemKind
pattern S_FOCUSED_SLOWNESS_MIST :: GroupName ItemKind
pattern S_EYE_DROP :: GroupName ItemKind
pattern S_IRON_FILING :: GroupName ItemKind
pattern S_SMELLY_DROPLET :: GroupName ItemKind
pattern S_EYE_SHINE :: GroupName ItemKind
pattern S_WHISKEY_SPRAY :: GroupName ItemKind
pattern S_YOUTH_SPRINKLE :: GroupName ItemKind
pattern S_POISON_CLOUD :: GroupName ItemKind
pattern S_PING_PLASH :: GroupName ItemKind
pattern S_VIOLENT_BURNING_OIL_2 :: GroupName ItemKind
pattern S_VIOLENT_BURNING_OIL_3 :: GroupName ItemKind
pattern S_VIOLENT_BURNING_OIL_4 :: GroupName ItemKind
pattern S_BURNING_OIL_2 :: GroupName ItemKind
pattern S_BURNING_OIL_3 :: GroupName ItemKind
pattern S_BURNING_OIL_4 :: GroupName ItemKind
pattern S_FOCUSED_BURNING_OIL_2 :: GroupName ItemKind
pattern S_FOCUSED_BURNING_OIL_3 :: GroupName ItemKind
pattern S_FOCUSED_BURNING_OIL_4 :: GroupName ItemKind
blastNoStatOf :: GroupName ItemKind -> GroupName ItemKind
blastBonusStatOf :: GroupName ItemKind -> GroupName ItemKind
pattern ARMOR_MISC :: GroupName ItemKind
blastsGNSingleton :: [GroupName ItemKind]
blastsGN :: [GroupName ItemKind]
blasts :: [ItemKind]


-- | Operations on the <a>Area</a> type that involve random numbers.
module Game.LambdaHack.Server.DungeonGen.AreaRnd
mkFixed :: (X, Y) -> Area -> Point -> Area

-- | Pick a random point within an area.
pointInArea :: Area -> Rnd Point

-- | Find a suitable position in the area, based on random points and a
--   preference predicate and fallback acceptability predicate.
findPointInArea :: Area -> (Point -> Maybe Point) -> Int -> (Point -> Maybe Point) -> Rnd (Maybe Point)

-- | Create a void room, i.e., a single point area within the designated
--   area.
mkVoidRoom :: Area -> Rnd Area

-- | Create a random room according to given parameters.
mkRoom :: (X, Y) -> (X, Y) -> Area -> Rnd Area

-- | Pick a subset of connections between adjacent areas within a grid
--   until there is only one connected component in the graph of all areas.
connectGrid :: EnumSet Point -> (X, Y) -> Rnd [(Point, Point)]

-- | Pick a single random connection between adjacent areas within a grid.
randomConnection :: (X, Y) -> Rnd (Point, Point)

-- | The choice of horizontal and vertical orientation.
data HV
Horiz :: HV
Vert :: HV

-- | The coordinates of consecutive fields of a corridor.
type Corridor = (Point, Point, Point, Point)

-- | Try to connect two interiors of places with a corridor. Choose
--   entrances some steps away from the edges, if the place is big enough.
--   Note that with <tt>pfence == FNone</tt>, the inner area considered is
--   the strict interior of the place, without the outermost tiles.
--   
--   The corridor connects (touches) the inner areas and the turning point
--   of the corridor (if any) is outside of the outer areas and inside the
--   grid areas.
connectPlaces :: (Area, Fence, Area) -> (Area, Fence, Area) -> Rnd (Maybe Corridor)
data SpecialArea
SpecialArea :: Area -> SpecialArea
SpecialFixed :: Point -> Freqs PlaceKind -> Area -> SpecialArea
SpecialMerged :: SpecialArea -> Point -> SpecialArea

-- | Divide uniformly a larger area into the given number of smaller areas
--   overlapping at the edges.
--   
--   The list of fixed centers (some important points inside) of
--   (non-overlapping) areas is given. Incorporate those, with as little
--   disruption, as possible. Assume each of four boundaries of the cave
--   are covered by a fixed centre.
grid :: EnumMap Point (Freqs PlaceKind) -> [Point] -> Area -> (X, Y) -> ((X, Y), EnumMap Point SpecialArea)
connectGrid' :: EnumSet Point -> (X, Y) -> EnumSet Point -> EnumSet Point -> [(Point, Point)] -> Rnd [(Point, Point)]

-- | Sort the sequence of two points, in the derived lexicographic order.
sortPoint :: (Point, Point) -> (Point, Point)

-- | Create a corridor, either horizontal or vertical, with a possible
--   intermediate part that is in the opposite direction. There might not
--   always exist a good intermediate point if the places are allowed to be
--   close together and then we let the intermediate part degenerate.
mkCorridor :: HV -> Point -> Bool -> Point -> Bool -> Area -> Rnd Corridor
borderPlace :: Area -> Fence -> (Area, Area, Bool)
instance GHC.Classes.Eq Game.LambdaHack.Server.DungeonGen.AreaRnd.HV
instance GHC.Show.Show Game.LambdaHack.Server.DungeonGen.AreaRnd.SpecialArea


-- | Generation of places from place kinds.
module Game.LambdaHack.Server.DungeonGen.Place

-- | The parameters of a place. All are immutable and rolled and fixed at
--   the time when a place is generated.
data Place
Place :: ContentId PlaceKind -> Area -> TileMapEM -> TileMapEM -> Place
[qkind] :: Place -> ContentId PlaceKind
[qarea] :: Place -> Area
[qmap] :: Place -> TileMapEM
[qfence] :: Place -> TileMapEM

-- | The map of tile kinds in a place (and generally anywhere in a cave).
--   The map is sparse. The default tile that eventually fills the empty
--   spaces is specified in the cave kind specification with
--   <tt>cdefTile</tt>.
type TileMapEM = EnumMap Point (ContentId TileKind)

-- | Given a few parameters, roll and construct a <a>Place</a>
--   datastructure and fill a cave section acccording to it.
buildPlace :: COps -> CaveKind -> Bool -> ContentId TileKind -> ContentId TileKind -> AbsDepth -> AbsDepth -> Word32 -> Area -> Maybe Area -> Freqs PlaceKind -> Rnd Place
isChancePos :: Int -> Int -> Word32 -> Point -> Bool

-- | Construct a fence around an area, with the given tile group.
buildFenceRnd :: COps -> GroupName TileKind -> GroupName TileKind -> GroupName TileKind -> GroupName TileKind -> Area -> Rnd TileMapEM

-- | For <tt>CAlternate</tt> tiling, require the place be comprised of an
--   even number of whole corners, with exactly one square overlap between
--   consecutive coners and no trimming. For other tiling methods, check
--   that the area is large enough for tiling the corner twice in each
--   direction, with a possible one row/column overlap.
placeCheck :: Area -> PlaceKind -> Bool

-- | Calculate interior room area according to fence type, based on the
--   total area for the room and it's fence. This is used for checking if
--   the room fits in the area, for digging up the place and the fence and
--   for deciding if the room is dark or lit later in the dungeon
--   generation process.
interiorArea :: PlaceKind -> Area -> Maybe Area
pover :: COps -> EnumMap Char (GroupName TileKind) -> Rnd (EnumMap Char (Maybe (Int, Int, ContentId TileKind), ContentId TileKind))

-- | Construct a fence around a place.
buildFence :: COps -> CaveKind -> Bool -> ContentId TileKind -> ContentId TileKind -> Bool -> Fence -> Area -> Rnd TileMapEM

-- | Construct a fence around an area, with the given tile kind. Corners
--   have a different kind, e.g., to avoid putting doors there.
buildFenceMap :: ContentId TileKind -> ContentId TileKind -> Area -> TileMapEM

-- | Create a place by tiling patterns.
tilePlace :: Area -> PlaceKind -> Rnd (EnumMap Point Char)
instance GHC.Show.Show Game.LambdaHack.Server.DungeonGen.Place.Place


-- | Generation of caves (not yet inhabited dungeon levels) from cave
--   kinds.
module Game.LambdaHack.Server.DungeonGen.Cave

-- | The type of caves (not yet inhabited dungeon levels).
data Cave
Cave :: ContentId CaveKind -> Area -> TileMapEM -> EnumMap Point Place -> EnumMap Point PlaceEntry -> Bool -> Cave

-- | the kind of the cave
[dkind] :: Cave -> ContentId CaveKind

-- | map area of the cave
[darea] :: Cave -> Area

-- | tile kinds in the cave
[dmap] :: Cave -> TileMapEM

-- | stair places indexed by their center
[dstairs] :: Cave -> EnumMap Point Place

-- | room entrances in the cave
[dentry] :: Cave -> EnumMap Point PlaceEntry

-- | whether the cave is dark
[dnight] :: Cave -> Bool

-- | Generate a cave using an algorithm inspired by the original Rogue, as
--   follows (in gross simplification):
--   
--   <ul>
--   <li>The available area is divided into a grid, e.g, 3 by 3, where each
--   of the 9 grid cells has approximately the same size.</li>
--   <li>In some of the 9 grid cells a room is placed at a random position
--   and with a random size, but larger than the minimum size, e.g, 2 by 2
--   floor tiles.</li>
--   <li>Rooms that are on horizontally or vertically adjacent grid cells
--   may be connected by a corridor. Corridors consist of 3 segments of
--   straight lines (either "horizontal, vertical, horizontal" or
--   "vertical, horizontal, vertical"). They end in openings in the walls
--   of the room they connect. It is possible that one or two of the 3
--   segments have length 0, such that the resulting corridor is L-shaped
--   or even a single straight line.</li>
--   <li>Corridors are generated randomly in such a way that at least every
--   room on the grid is connected, and a few more might be. It is not
--   sufficient to always connect all adjacent rooms, because not each cell
--   holds a room.</li>
--   </ul>
buildCave :: COps -> AbsDepth -> AbsDepth -> Area -> Word32 -> ContentId CaveKind -> (X, Y) -> EnumMap Point SpecialArea -> [Point] -> Rnd Cave
pickOpening :: COps -> CaveKind -> TileMapEM -> ContentId TileKind -> Word32 -> EnumMap Point (ContentId TileKind) -> (Point, (ContentId TileKind, ContentId TileKind, ContentId PlaceKind)) -> Rnd (EnumMap Point (ContentId TileKind))
instance GHC.Show.Show Game.LambdaHack.Server.DungeonGen.Cave.Cave


-- | DFOV (Digital Field of View) implemented according to specification at
--   <a>http://roguebasin.roguelikedevelopment.org/index.php?title=Digital_field_of_view_implementation</a>.
--   This fast version of the algorithm, based on PFOV, has AFAIK never
--   been described nor implemented before.
--   
--   The map is processed in depth-first-search manner, that is, as soon as
--   we detect on obstacle we move away from the viewer up to the FOV
--   radius and then restart on the other side of the obstacle. This has
--   better cache behaviour than breadth-firsts-search, where we would
--   process all tiles equally distant from the viewer in the same round,
--   because then we'd need to keep the many convex hulls and edges, not
--   just a single set, and we'd potentially traverse all of them each
--   round.
module Game.LambdaHack.Server.FovDigital

-- | Calculates the list of tiles visible from (0, 0) within the given
--   sight range.
scan :: Distance -> (PointI -> Bool) -> (Bump -> PointI) -> [PointI]

-- | Rotated and translated coordinates of 2D points, so that the points
--   fit in a single quadrant area (e, g., quadrant I for Permissive FOV,
--   hence both coordinates positive; adjacent diagonal halves of quadrant
--   I and II for Digital FOV, hence y positive). The special coordinates
--   are written using the standard mathematical coordinate setup, where
--   quadrant I, with x and y positive, is on the upper right.
data Bump
B :: Int -> Int -> Bump
[bx] :: Bump -> Int
[by] :: Bump -> Int

-- | Distance from the (0, 0) point where FOV originates.
type Distance = Int

-- | Progress along an arc with a constant distance from (0, 0).
type Progress = Int

-- | Two strict orderings of lines with a common point.
data LineOrdering

-- | Straight line between points.
data Line
Line :: Bump -> Bump -> Line

-- | Convex hull represented as a non-empty list of points.
data ConvexHull
ConvexHull :: Bump -> CHull -> ConvexHull
data CHull
CHNil :: CHull
CHCons :: Bump -> CHull -> CHull

-- | An edge (comprising of a line and a convex hull) of the area to be
--   scanned.
type Edge = (Line, ConvexHull)

-- | The contiguous area left to be scanned, delimited by edges.
type EdgeInterval = (Edge, Edge)

-- | Specialized implementation for speed in the inner loop. Not partial.
steepestInHull :: LineOrdering -> Bump -> ConvexHull -> Bump

-- | Standard <tt>foldl'</tt> over <tt>CHull</tt>.
foldlCHull' :: (a -> Bump -> a) -> a -> CHull -> a

-- | Extends a convex hull of bumps with a new bump. The new bump makes
--   some old bumps unnecessary, e.g. those that are joined with the new
--   steep bump with lines that are not shallower than any newer lines in
--   the hull. Removing such unnecessary bumps slightly speeds up
--   computation of <a>steepestInHull</a>.
--   
--   Recursion in <tt>addToHullGo</tt> seems spurious, but it's called each
--   time with potentially different comparison predicate, so it's
--   necessary.
addToHull :: LineOrdering -> Bump -> ConvexHull -> ConvexHull
addToHullGo :: LineOrdering -> Bump -> CHull -> CHull

-- | Create a line from two points.
--   
--   Debug: check if well-defined.
createLine :: Bump -> Bump -> Line

-- | Strictly compare steepness of lines <tt>(b1, bf)</tt> and <tt>(b2,
--   bf)</tt>, according to the <tt>LineOrdering</tt> given. This is
--   related to comparing the slope (gradient, angle) of two lines, but
--   simplified wrt signs to work fast in this particular setup.
--   
--   Debug: Verify that the results of 2 independent checks are equal.
steepness :: LineOrdering -> Bump -> Bump -> Bump -> Bool

-- | A pair <tt>(a, b)</tt> such that <tt>a</tt> divided by <tt>b</tt> is
--   the X coordinate of the intersection of a given line and the
--   horizontal line at distance <tt>d</tt> above the X axis.
--   
--   Derivation of the formula: The intersection point <tt>(xt, yt)</tt>
--   satisfies the following equalities:
--   
--   <pre>
--   yt = d
--   (yt - y) (xf - x) = (xt - x) (yf - y)
--   </pre>
--   
--   hence
--   
--   <pre>
--   (yt - y) (xf - x) = (xt - x) (yf - y)
--   (d - y) (xf - x) = (xt - x) (yf - y)
--   (d - y) (xf - x) + x (yf - y) = xt (yf - y)
--   xt = ((d - y) (xf - x) + x (yf - y)) / (yf - y)
--   </pre>
--   
--   General remarks: The FOV agrees with physical properties of tiles as
--   diamonds and visibility from any point to any point. A diamond is
--   denoted by the left corner of its encompassing tile. Hero is at (0,
--   0). Order of processing in the first quadrant rotated by 45 degrees is
--   
--   <pre>
--   45678
--    123
--     @
--   </pre>
--   
--   so the first processed diamond is at (-1, 1). The order is similar as
--   for the restrictive shadow casting algorithm and reversed wrt PFOV.
--   The fast moving line when scanning is called the shallow line, and
--   it's the one that delimits the view from the left, while the steep
--   line is on the right, opposite to PFOV. We start scanning from the
--   left.
--   
--   The <a>PointI</a> (<a>Enum</a> representation of <tt>Point</tt>)
--   coordinates are cartesian. The <a>Bump</a> coordinates are cartesian,
--   translated so that the hero is at (0, 0) and rotated so that he always
--   looks at the first (rotated 45 degrees) quadrant. The
--   (<a>Progress</a>, <a>Distance</a>) cordinates coincide with the
--   <tt>Bump</tt> coordinates, unlike in PFOV.
--   
--   Debug: check that the line fits in the upper half-plane.
intersect :: Line -> Distance -> (Int, Int)

-- | Debug functions for DFOV:
--   
--   Debug: calculate steepness for DFOV in another way and compare
--   results.
_debugSteeper :: LineOrdering -> Bump -> Bump -> Bump -> Bool

-- | Debug: check if a view border line for DFOV is legal.
_debugLine :: Line -> (Bool, String)
instance GHC.Show.Show Game.LambdaHack.Server.FovDigital.Bump
instance GHC.Show.Show Game.LambdaHack.Server.FovDigital.Line
instance GHC.Show.Show Game.LambdaHack.Server.FovDigital.CHull
instance GHC.Show.Show Game.LambdaHack.Server.FovDigital.ConvexHull


-- | Field Of View scanning.
--   
--   See <a>https://github.com/LambdaHack/LambdaHack/wiki/Fov-and-los</a>
--   for discussion.
module Game.LambdaHack.Server.Fov
data FovValid a
FovValid :: a -> FovValid a
FovInvalid :: FovValid a

-- | Main perception validity map, for all factions.
--   
--   The inner type is not a set, due to an unbenchmarked theory that a
--   constant shape map is faster.
type PerValidFid = EnumMap FactionId (EnumMap LevelId Bool)

-- | Visually reachable positions (light passes through them to the actor).
--   They need to be intersected with lucid positions to obtain visible
--   positions.
newtype PerReachable
PerReachable :: EnumSet Point -> PerReachable
[preachable] :: PerReachable -> EnumSet Point
data CacheBeforeLucid
CacheBeforeLucid :: PerReachable -> PerVisible -> PerSmelled -> CacheBeforeLucid
[creachable] :: CacheBeforeLucid -> PerReachable
[cnocto] :: CacheBeforeLucid -> PerVisible
[csmell] :: CacheBeforeLucid -> PerSmelled
type PerActor = EnumMap ActorId (FovValid CacheBeforeLucid)
data PerceptionCache
PerceptionCache :: FovValid CacheBeforeLucid -> PerActor -> PerceptionCache
[ptotal] :: PerceptionCache -> FovValid CacheBeforeLucid
[perActor] :: PerceptionCache -> PerActor

-- | Server cache of perceptions of a single faction, indexed by level
--   identifier.
type PerCacheLid = EnumMap LevelId PerceptionCache

-- | Server cache of perceptions, indexed by faction identifier.
type PerCacheFid = EnumMap FactionId PerCacheLid

-- | Map from level positions that currently hold item or actor(s) with
--   shine to the maximum of radiuses of the shining lights.
--   
--   Note that floor and (many projectile) actors light on a single tile
--   should be additive for <tt>FovShine</tt> to be incrementally updated.
--   
--   <tt>FovShine</tt> should not even be kept in <tt>StateServer</tt>,
--   because it's cheap to compute, compared to <tt>FovLucid</tt> and
--   invalidated almost as often (not invalidated only by
--   <tt>UpdAlterTile</tt>).
newtype FovShine
FovShine :: EnumMap Point Int -> FovShine
[fovShine] :: FovShine -> EnumMap Point Int

-- | Level positions with either ambient light or shining items or actors.
newtype FovLucid
FovLucid :: EnumSet Point -> FovLucid
[fovLucid] :: FovLucid -> EnumSet Point
type FovLucidLid = EnumMap LevelId (FovValid FovLucid)

-- | Level positions that pass through light and vision.
newtype FovClear
FovClear :: Array Bool -> FovClear
[fovClear] :: FovClear -> Array Bool
type FovClearLid = EnumMap LevelId FovClear

-- | Level positions with tiles that have ambient light.
newtype FovLit
FovLit :: EnumSet Point -> FovLit
[fovLit] :: FovLit -> EnumSet Point
type FovLitLid = EnumMap LevelId FovLit

-- | Compute positions visible (reachable and seen) by the party. A
--   position is lucid, if it's lit by an ambient light or by a weak,
--   portable light source, e.g,, carried by an actor. A reachable and
--   lucid position is visible. Additionally, positions directly adjacent
--   to an actor are assumed to be visible to him (through sound, touch,
--   noctovision, whatever).
perceptionFromPTotal :: FactionId -> LevelId -> FovLucid -> CacheBeforeLucid -> State -> Perception
perActorFromLevel :: PerActor -> (ActorId -> Actor) -> ActorMaxSkills -> FovClear -> PerActor
boundSightByCalm :: Int -> Int64 -> Int
totalFromPerActor :: PerActor -> CacheBeforeLucid

-- | Update lights on the level. This is needed every (even enemy) actor
--   move to show thrown torches. We need to update lights even if cmd
--   doesn't change any perception, so that for next cmd that does, but
--   doesn't change lights, and operates on the same level, the lights are
--   up to date. We could make lights lazy to ensure no computation is
--   wasted, but it's rare that cmd changed them, but not the perception
--   (e.g., earthquake in an uninhabited corner of the active arena, but
--   the we'd probably want some feedback, at least sound).
lucidFromLevel :: FovClearLid -> FovLitLid -> State -> LevelId -> Level -> FovLucid

-- | Calculate the perception and its caches for the whole dungeon.
perFidInDungeon :: State -> (FovLitLid, FovClearLid, FovLucidLid, PerValidFid, PerCacheFid, PerFid)
perceptionFromPTotalNoStash :: FovLucid -> CacheBeforeLucid -> Perception

-- | Compute positions reachable by the actor. Reachable are all fields on
--   a visually unblocked path from the actor position. Also compute
--   positions seen by noctovision and perceived by smell.
cacheBeforeLucidFromActor :: FovClear -> Actor -> Skills -> CacheBeforeLucid
shineFromLevel :: State -> LevelId -> Level -> FovShine
floorLightSources :: DiscoveryAspect -> Level -> [(Point, Int)]

-- | Compute all dynamically lit positions on a level, whether lit by
--   actors or shining floor items. Note that an actor can be blind, in
--   which case he doesn't see his own light (but others, from his or other
--   factions, possibly do).
lucidFromItems :: FovClear -> [(Point, Int)] -> [FovLucid]
litFromLevel :: COps -> Level -> FovLit
litInDungeon :: State -> FovLitLid
clearFromLevel :: COps -> Level -> FovClear
clearInDungeon :: State -> FovClearLid
lucidInDungeon :: FovClearLid -> FovLitLid -> State -> FovLucidLid

-- | Calculate perception of a faction.
perLidFromFaction :: FovLucidLid -> FovClearLid -> FactionId -> State -> (PerLid, PerCacheLid)
perceptionCacheFromLevel :: FovClearLid -> FactionId -> LevelId -> State -> PerceptionCache
type Matrix = (Int, Int, Int, Int)

-- | Perform a full scan for a given position. Returns the positions that
--   are currently in the field of view. The actor's own position is
--   considred in his field of view.
fullscan :: Int -> Point -> FovClear -> EnumSet Point
instance GHC.Classes.Eq a => GHC.Classes.Eq (Game.LambdaHack.Server.Fov.FovValid a)
instance GHC.Show.Show a => GHC.Show.Show (Game.LambdaHack.Server.Fov.FovValid a)
instance GHC.Classes.Eq Game.LambdaHack.Server.Fov.PerReachable
instance GHC.Show.Show Game.LambdaHack.Server.Fov.PerReachable
instance GHC.Classes.Eq Game.LambdaHack.Server.Fov.CacheBeforeLucid
instance GHC.Show.Show Game.LambdaHack.Server.Fov.CacheBeforeLucid
instance GHC.Classes.Eq Game.LambdaHack.Server.Fov.PerceptionCache
instance GHC.Show.Show Game.LambdaHack.Server.Fov.PerceptionCache
instance GHC.Classes.Eq Game.LambdaHack.Server.Fov.FovShine
instance GHC.Show.Show Game.LambdaHack.Server.Fov.FovShine
instance GHC.Classes.Eq Game.LambdaHack.Server.Fov.FovLucid
instance GHC.Show.Show Game.LambdaHack.Server.Fov.FovLucid
instance GHC.Classes.Eq Game.LambdaHack.Server.Fov.FovClear
instance GHC.Show.Show Game.LambdaHack.Server.Fov.FovClear
instance GHC.Classes.Eq Game.LambdaHack.Server.Fov.FovLit
instance GHC.Show.Show Game.LambdaHack.Server.Fov.FovLit


-- | Creation of items on the server. Types and operations that don't
--   involve server state nor our custom monads.
module Game.LambdaHack.Server.ItemRev

-- | The essential item properties, used for the <tt>ItemRev</tt> hash
--   table from items to their ids, needed to assign ids to newly generated
--   items. All the other meaningful properties can be derived from them.
--   Note: item seed instead of <tt>AspectRecord</tt> is not enough,
--   becaused different seeds may result in the same <tt>AspectRecord</tt>
--   and we don't want such items to be distinct in UI and elsewhere.
data ItemKnown
ItemKnown :: ItemIdentity -> AspectRecord -> Maybe FactionId -> ItemKnown
data NewItem
NewItem :: GroupName ItemKind -> ItemKnown -> ItemFull -> ItemQuant -> NewItem
NoNewItem :: NewItem

-- | Reverse item map, for item creation, to keep items and item
--   identifiers in bijection.
type ItemRev = HashMap ItemKnown ItemId
type UniqueSet = EnumSet (ContentId ItemKind)

-- | Roll an item kind based on given <tt>Freqs</tt> and kind rarities
newItemKind :: COps -> UniqueSet -> Freqs ItemKind -> AbsDepth -> AbsDepth -> Int -> Frequency (GroupName ItemKind, ContentId ItemKind, ItemKind)

-- | Given item kind frequency, roll item kind, generate item aspects based
--   on level and put together the full item data set.
newItem :: COps -> Frequency (GroupName ItemKind, ContentId ItemKind, ItemKind) -> FlavourMap -> DiscoveryKindRev -> AbsDepth -> AbsDepth -> Rnd NewItem

-- | The reverse map to <tt>DiscoveryKind</tt>, needed for item creation.
--   This is total and never changes, hence implemented as vector. Morally,
--   it's indexed by <tt>ContentId ItemKind</tt> and elements are
--   <tt>ItemKindIx</tt>.
data DiscoveryKindRev
emptyDiscoveryKindRev :: DiscoveryKindRev
serverDiscos :: COps -> DiscoveryKindRev -> Rnd (DiscoveryKind, DiscoveryKindRev)

-- | Flavours assigned by the server to item kinds, in this particular
--   game. This is total and never changes, hence implemented as vector.
--   Morally, it's indexed by <tt>ContentId ItemKind</tt> and elements are
--   <tt>Flavour</tt>.
data FlavourMap
emptyFlavourMap :: FlavourMap

-- | Randomly chooses flavour for all item kinds for this game.
dungeonFlavourMap :: COps -> FlavourMap -> Rnd FlavourMap

-- | Assigns flavours to item kinds. Assures no flavor is repeated for the
--   same symbol, except for items with only one permitted flavour.
rollFlavourMap :: Vector Word16 -> Rnd (EnumMap (ContentId ItemKind) Flavour, EnumMap (ContentSymbol ItemKind) (EnumSet Flavour)) -> ContentId ItemKind -> ItemKind -> Rnd (EnumMap (ContentId ItemKind) Flavour, EnumMap (ContentSymbol ItemKind) (EnumSet Flavour))

-- | Build an item with the given kind and aspects.
buildItem :: COps -> AspectRecord -> FlavourMap -> DiscoveryKindRev -> ContentId ItemKind -> Item

-- | Keep in a vector the information that is retained from playthrough to
--   playthrough. The information being, e.g., <tt>ItemKindIx</tt> or
--   <tt>Flavour</tt>. The information is morally indexed by <tt>ContentId
--   ItemKind</tt> and its <tt>Enum</tt> instance fits in <tt>Word16</tt>.
keepMetaGameInformation :: ContentData ItemKind -> Vector Word16 -> Vector Word16
instance GHC.Generics.Generic Game.LambdaHack.Server.ItemRev.ItemKnown
instance GHC.Classes.Eq Game.LambdaHack.Server.ItemRev.ItemKnown
instance GHC.Show.Show Game.LambdaHack.Server.ItemRev.ItemKnown
instance Data.Binary.Class.Binary Game.LambdaHack.Server.ItemRev.DiscoveryKindRev
instance GHC.Show.Show Game.LambdaHack.Server.ItemRev.DiscoveryKindRev
instance Data.Binary.Class.Binary Game.LambdaHack.Server.ItemRev.FlavourMap
instance GHC.Show.Show Game.LambdaHack.Server.ItemRev.FlavourMap
instance Data.Binary.Class.Binary Game.LambdaHack.Server.ItemRev.ItemKnown
instance Data.Hashable.Class.Hashable Game.LambdaHack.Server.ItemRev.ItemKnown


-- | Server and client game state types and operations.
module Game.LambdaHack.Server.ServerOptions

-- | Options that affect the behaviour of the server (including game
--   rules).
data ServerOptions
ServerOptions :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe (GroupName ModeKind) -> Bool -> Bool -> Maybe SMGen -> Maybe SMGen -> Bool -> Challenge -> Bool -> String -> Bool -> Maybe Int -> Bool -> Bool -> ClientOptions -> ServerOptions
[sknowMap] :: ServerOptions -> Bool
[sknowEvents] :: ServerOptions -> Bool
[sknowItems] :: ServerOptions -> Bool
[sniff] :: ServerOptions -> Bool
[sallClear] :: ServerOptions -> Bool
[sboostRandomItem] :: ServerOptions -> Bool
[sgameMode] :: ServerOptions -> Maybe (GroupName ModeKind)
[sautomateAll] :: ServerOptions -> Bool
[skeepAutomated] :: ServerOptions -> Bool
[sdungeonRng] :: ServerOptions -> Maybe SMGen
[smainRng] :: ServerOptions -> Maybe SMGen
[snewGameSer] :: ServerOptions -> Bool
[scurChalSer] :: ServerOptions -> Challenge
[sdumpInitRngs] :: ServerOptions -> Bool
[ssavePrefixSer] :: ServerOptions -> String
[sdbgMsgSer] :: ServerOptions -> Bool
[sassertExplored] :: ServerOptions -> Maybe Int
[sshowItemSamples] :: ServerOptions -> Bool
[sstopAfterGameOver] :: ServerOptions -> Bool
[sclientOptions] :: ServerOptions -> ClientOptions
data RNGs
RNGs :: Maybe SMGen -> Maybe SMGen -> RNGs
[dungeonRandomGenerator] :: RNGs -> Maybe SMGen
[startingRandomGenerator] :: RNGs -> Maybe SMGen

-- | Default value of server options.
defServerOptions :: ServerOptions
instance GHC.Show.Show Game.LambdaHack.Server.ServerOptions.ServerOptions
instance GHC.Show.Show Game.LambdaHack.Server.ServerOptions.RNGs
instance Data.Binary.Class.Binary Game.LambdaHack.Server.ServerOptions.RNGs
instance Data.Binary.Class.Binary Game.LambdaHack.Server.ServerOptions.ServerOptions


-- | The dungeon generation routine. It creates empty dungeons, without
--   actors and without items, either lying on the floor or embedded inside
--   tiles.
module Game.LambdaHack.Server.DungeonGen

-- | Freshly generated and not yet populated dungeon.
data FreshDungeon
FreshDungeon :: Dungeon -> AbsDepth -> FreshDungeon

-- | maps for all levels
[freshDungeon] :: FreshDungeon -> Dungeon

-- | absolute dungeon depth
[freshTotalDepth] :: FreshDungeon -> AbsDepth

-- | Generate the dungeon for a new game.
dungeonGen :: COps -> ServerOptions -> Caves -> Rnd FreshDungeon
convertTileMaps :: COps -> Bool -> Rnd (ContentId TileKind) -> Maybe (Rnd (ContentId TileKind)) -> Area -> TileMapEM -> Rnd TileMap
buildTileMap :: COps -> Cave -> Rnd TileMap
anchorDown :: Y
buildLevel :: COps -> ServerOptions -> LevelId -> ContentId CaveKind -> CaveKind -> Int -> Int -> AbsDepth -> [(Point, Text)] -> Rnd (Level, [(Point, Text)])
snapToStairList :: Int -> [Point] -> Point -> Either Point Point
placeDownStairs :: Text -> Bool -> ServerOptions -> LevelId -> CaveKind -> Area -> [Point] -> [Point] -> Rnd (Maybe Point)
levelFromCave :: COps -> Cave -> AbsDepth -> TileMap -> ([Point], [Point]) -> [Point] -> Level


-- | Server and client game state types and operations.
module Game.LambdaHack.Server.State

-- | State with server-specific data, including a copy of each client's
--   basic game state, but not the server's basic state.
data StateServer
StateServer :: ActorTime -> ActorTime -> ActorPushedBy -> GearOfTeams -> GearOfTeams -> EnumMap TeamContinuity Int -> FactionAnalytics -> ActorAnalytics -> GenerationAnalytics -> EnumSet ActorId -> DiscoveryKindRev -> UniqueSet -> ItemRev -> FlavourMap -> ActorId -> ItemId -> EnumMap LevelId Int -> IntMap Int -> () -> EnumMap FactionId State -> EnumMap TeamContinuity DiscoveryKind -> PerFid -> PerValidFid -> PerCacheFid -> FovLucidLid -> FovClearLid -> FovLitLid -> EnumSet LevelId -> Bool -> SMGen -> RNGs -> Bool -> Bool -> Bool -> ServerOptions -> ServerOptions -> StateServer

-- | absolute times of actors next actions
[sactorTime] :: StateServer -> ActorTime

-- | and same for actors with trajectories
[strajTime] :: StateServer -> ActorTime

-- | culprits for actors with trajectories
[strajPushedBy] :: StateServer -> ActorPushedBy

-- | metagame persistent personal characteristics and favourite gear of
--   each numbered continued team member
[steamGear] :: StateServer -> GearOfTeams

-- | gear preferences to be taken into account in the current game
[steamGearCur] :: StateServer -> GearOfTeams

-- | stores next continued team character identity index number in this
--   game
[stcounter] :: StateServer -> EnumMap TeamContinuity Int

-- | various past events data for factions
[sfactionAn] :: StateServer -> FactionAnalytics

-- | various past events data for actors
[sactorAn] :: StateServer -> ActorAnalytics

-- | item creation statistics, by item lore
[sgenerationAn] :: StateServer -> GenerationAnalytics

-- | actors currently in time stasis, invulnerable to time warps until move
[sactorStasis] :: StateServer -> EnumSet ActorId

-- | reverse map, used for item creation
[sdiscoKindRev] :: StateServer -> DiscoveryKindRev

-- | already generated unique items
[suniqueSet] :: StateServer -> UniqueSet

-- | reverse id map, used for item creation
[sitemRev] :: StateServer -> ItemRev

-- | association of flavour to item kinds
[sflavour] :: StateServer -> FlavourMap

-- | stores next actor index
[sacounter] :: StateServer -> ActorId

-- | stores next item index
[sicounter] :: StateServer -> ItemId

-- | how many spawned so far on the level
[snumSpawned] :: StateServer -> EnumMap LevelId Int

-- | how many times such group spawned
[sbandSpawned] :: StateServer -> IntMap Int
[sundo] :: StateServer -> ()

-- | each faction state, as seen by clients
[sclientStates] :: StateServer -> EnumMap FactionId State

-- | discovery info for absent factions
[smetaBackup] :: StateServer -> EnumMap TeamContinuity DiscoveryKind

-- | perception of all factions
[sperFid] :: StateServer -> PerFid

-- | perception validity for all factions
[sperValidFid] :: StateServer -> PerValidFid

-- | perception cache of all factions
[sperCacheFid] :: StateServer -> PerCacheFid

-- | ambient or shining light positions
[sfovLucidLid] :: StateServer -> FovLucidLid

-- | clear tiles positions
[sfovClearLid] :: StateServer -> FovClearLid

-- | ambient light positions
[sfovLitLid] :: StateServer -> FovLitLid

-- | the set of active arenas
[sarenas] :: StateServer -> EnumSet LevelId

-- | whether active arenas valid
[svalidArenas] :: StateServer -> Bool

-- | current random generator
[srandom] :: StateServer -> SMGen

-- | initial random generators
[srngs] :: StateServer -> RNGs

-- | exit game loop after clip's end; usually no game save follows
[sbreakLoop] :: StateServer -> Bool

-- | exit game loop ASAP; usually with save
[sbreakASAP] :: StateServer -> Bool

-- | write savegame to file after loop exit
[swriteSave] :: StateServer -> Bool

-- | current commandline options
[soptions] :: StateServer -> ServerOptions

-- | options for the next game
[soptionsNxt] :: StateServer -> ServerOptions

-- | Position in time for each actor, grouped by level and by faction.
type ActorTime = EnumMap FactionId (EnumMap LevelId (EnumMap ActorId Time))

-- | Record who last propelled a given actor with trajectory.
type ActorPushedBy = EnumMap ActorId ActorId

-- | Initial, empty game server state.
emptyStateServer :: StateServer
updateActorTime :: FactionId -> LevelId -> ActorId -> Time -> ActorTime -> ActorTime
lookupActorTime :: FactionId -> LevelId -> ActorId -> ActorTime -> Maybe Time
ageActor :: FactionId -> LevelId -> ActorId -> Delta Time -> ActorTime -> ActorTime

-- | Per-team, per-actor metagame persistent favourite organs and gear.
type GearOfTeams = EnumMap TeamContinuity (IntMap [(GroupName ItemKind, ContentId ItemKind)])
instance GHC.Show.Show Game.LambdaHack.Server.State.StateServer
instance Data.Binary.Class.Binary Game.LambdaHack.Server.State.StateServer


-- | Basic server monads and related operations.
module Game.LambdaHack.Server.MonadServer
class MonadStateRead m => MonadServer m
getsServer :: MonadServer m => (StateServer -> a) -> m a
modifyServer :: MonadServer m => (StateServer -> StateServer) -> m ()
chanSaveServer :: MonadServer m => m (ChanSave (State, StateServer))
liftIO :: MonadServer m => IO a -> m a

-- | The monad for executing atomic game state transformations.
class MonadServer m => MonadServerAtomic m

-- | Execute an atomic command that changes the state on the server and on
--   all clients that can notice it.
execUpdAtomic :: MonadServerAtomic m => UpdAtomic -> m ()

-- | Execute an atomic command that changes the state on the server only.
execUpdAtomicSer :: MonadServerAtomic m => UpdAtomic -> m Bool

-- | Execute an atomic command that changes the state on the given single
--   client only.
execUpdAtomicFid :: MonadServerAtomic m => FactionId -> UpdAtomic -> m ()

-- | Execute an atomic command that changes the state on the given single
--   client only. Catch <a>AtomicFail</a> and indicate if it was in fact
--   raised.
execUpdAtomicFidCatch :: MonadServerAtomic m => FactionId -> UpdAtomic -> m Bool

-- | Execute an atomic command that only displays special effects.
execSfxAtomic :: MonadServerAtomic m => SfxAtomic -> m ()
execSendPer :: MonadServerAtomic m => FactionId -> LevelId -> Perception -> Perception -> Perception -> m ()
getServer :: MonadServer m => m StateServer
putServer :: MonadServer m => StateServer -> m ()
debugPossiblyPrint :: MonadServer m => Text -> m ()
debugPossiblyPrintAndExit :: MonadServer m => Text -> m ()
serverPrint :: MonadServer m => Text -> m ()
saveServer :: MonadServer m => m ()

-- | Dumps to stdout the RNG states from the start of the game.
dumpRngs :: MonadServer m => RNGs -> m ()

-- | Read the high scores dictionary. Return the empty table if no file.
restoreScore :: forall m. MonadServer m => COps -> m ScoreDict

-- | Generate a new score, register it and save.
registerScore :: MonadServer m => Status -> FactionId -> m ()

-- | Invoke pseudo-random computation with the generator kept in the state.
rndToAction :: MonadServer m => Rnd a -> m a

-- | Gets a random generator from the user-submitted options or, if not
--   present, generates one.
getSetGen :: MonadServer m => Maybe SMGen -> m SMGen


-- | Server operations for items.
module Game.LambdaHack.Server.ItemM
registerItem :: MonadServerAtomic m => Bool -> ItemFullKit -> ItemKnown -> Container -> m ItemId
moveStashIfNeeded :: MonadStateRead m => Container -> m [UpdAtomic]
randomResetTimeout :: MonadServerAtomic m => Int -> ItemId -> ItemFull -> [ItemTimer] -> Container -> m ()
embedItemOnPos :: MonadServerAtomic m => LevelId -> Point -> ContentId TileKind -> m ()
prepareItemKind :: MonadServerAtomic m => Int -> AbsDepth -> Freqs ItemKind -> m (Frequency (GroupName ItemKind, ContentId ItemKind, ItemKind))
rollItemAspect :: MonadServerAtomic m => Frequency (GroupName ItemKind, ContentId ItemKind, ItemKind) -> AbsDepth -> m NewItem
rollAndRegisterItem :: MonadServerAtomic m => Bool -> AbsDepth -> Frequency (GroupName ItemKind, ContentId ItemKind, ItemKind) -> Container -> Maybe Int -> m (Maybe (ItemId, ItemFullKit))
placeItemsInDungeon :: forall m. MonadServerAtomic m => EnumMap LevelId (EnumMap FactionId Point) -> m ()
embedItemsInDungeon :: MonadServerAtomic m => m ()

-- | Mapping over actor's items from a give store.
mapActorCStore_ :: MonadServer m => CStore -> (ItemId -> ItemQuant -> m ()) -> Actor -> m ()
onlyRegisterItem :: MonadServerAtomic m => ItemKnown -> m ItemId
computeRndTimeout :: Time -> ItemFull -> Rnd (Maybe ItemTimer)
createCaveItem :: MonadServerAtomic m => Point -> LevelId -> m ()
createEmbedItem :: MonadServerAtomic m => LevelId -> Point -> GroupName ItemKind -> m ()


-- | Handle atomic commands on the server, after they are executed to
--   change server <a>State</a> and before they are sent to clients.
module Game.LambdaHack.Server.HandleAtomicM

-- | Effect of atomic actions on server state is calculated with the global
--   state from after the command is executed (except where the supplied
--   <tt>oldState</tt> is used).
cmdAtomicSemSer :: MonadServer m => State -> UpdAtomic -> m ()
validateFloor :: MonadServer m => ItemId -> LevelId -> m ()
validateFloorBag :: MonadServer m => ItemBag -> LevelId -> m ()
levelOfStash :: MonadStateRead m => ActorId -> m LevelId
invalidateArenas :: MonadServer m => m ()
updateSclear :: MonadServer m => LevelId -> Point -> ContentId TileKind -> ContentId TileKind -> m Bool
updateSlit :: MonadServer m => LevelId -> Point -> ContentId TileKind -> ContentId TileKind -> m Bool
invalidateLucidLid :: MonadServer m => LevelId -> m ()
invalidateLucidAid :: MonadServer m => ActorId -> m ()
actorHasShine :: ActorMaxSkills -> ActorId -> Bool
itemAffectsShineRadius :: DiscoveryAspect -> ItemId -> Bool
itemAffectsPerRadius :: DiscoveryAspect -> ItemId -> Bool
addPerActor :: MonadServer m => ActorId -> Actor -> m ()
addPerActorAny :: MonadServer m => ActorId -> Actor -> m ()
deletePerActor :: MonadServer m => ActorMaxSkills -> ActorId -> Actor -> m ()
deletePerActorAny :: MonadServer m => ActorId -> Actor -> m ()
invalidatePerActor :: MonadServer m => ActorId -> m ()
reconsiderPerActor :: MonadServer m => ActorId -> m ()
invalidatePerLid :: MonadServer m => LevelId -> m ()


-- | Debug output for requests and responses.
module Game.LambdaHack.Server.DebugM
debugResponse :: MonadServer m => FactionId -> Response -> m ()
debugRequestAI :: MonadServer m => ActorId -> m ()
debugRequestUI :: MonadServer m => ActorId -> m ()
debugShow :: Show a => a -> Text
debugPretty :: MonadServer m => FactionId -> Text -> UpdAtomic -> m ()
debugPlain :: MonadServer m => FactionId -> Text -> UpdAtomic -> m ()
data DebugAid
DebugAid :: Text -> ActorId -> FactionId -> LevelId -> Int64 -> Maybe Time -> Maybe Time -> Time -> DebugAid
[label] :: DebugAid -> Text
[aid] :: DebugAid -> ActorId
[faction] :: DebugAid -> FactionId
[lid] :: DebugAid -> LevelId
[bHP] :: DebugAid -> Int64
[btime] :: DebugAid -> Maybe Time
[btrTime] :: DebugAid -> Maybe Time
[time] :: DebugAid -> Time
debugAid :: MonadServer m => ActorId -> Text -> m Text
instance GHC.Show.Show Game.LambdaHack.Server.DebugM.DebugAid


-- | The server definitions for the server-client communication protocol.
module Game.LambdaHack.Server.ProtocolM
type CliSerQueue = MVar

-- | Connection information for all factions, indexed by faction
--   identifier.
type ConnServerDict = EnumMap FactionId ChanServer

-- | Connection channel between the server and a single client.
data ChanServer
ChanServer :: CliSerQueue Response -> CliSerQueue RequestAI -> Maybe (CliSerQueue RequestUI) -> ChanServer
[responseS] :: ChanServer -> CliSerQueue Response
[requestAIS] :: ChanServer -> CliSerQueue RequestAI
[requestUIS] :: ChanServer -> Maybe (CliSerQueue RequestUI)

-- | The server monad with the ability to communicate with clients.
class MonadServer m => MonadServerComm m
getsDict :: MonadServerComm m => (ConnServerDict -> a) -> m a
putDict :: MonadServerComm m => ConnServerDict -> m ()
liftIO :: MonadServerComm m => IO a -> m a

-- | If the <tt>AtomicFail</tt> conditions hold, send a command to client,
--   otherwise do nothing.
sendUpdate :: (MonadServerAtomic m, MonadServerComm m) => FactionId -> UpdAtomic -> m ()

-- | Send a command to client, crashing if the <tt>AtomicFail</tt>
--   conditions don't hold when executed on the client's state.
sendUpdateCheck :: (MonadServerAtomic m, MonadServerComm m) => FactionId -> UpdAtomic -> m ()
sendUpdNoState :: MonadServerComm m => FactionId -> UpdAtomic -> m ()
sendSfx :: MonadServerComm m => FactionId -> SfxAtomic -> m ()
sendQueryAI :: MonadServerComm m => FactionId -> ActorId -> m RequestAI
sendQueryUI :: (MonadServerAtomic m, MonadServerComm m) => Response -> FactionId -> ActorId -> m RequestUI
killAllClients :: (MonadServerAtomic m, MonadServerComm m) => m ()
childrenServer :: MVar [Async ()]

-- | Update connections to the new definition of factions. Connect to
--   clients in old or newly spawned threads that read and write directly
--   to the channels.
updateConn :: (MonadServerAtomic m, MonadServerComm m) => (FactionId -> ChanServer -> IO ()) -> m ()
tryRestore :: MonadServerComm m => m (Maybe (State, StateServer))
writeQueue :: MonadServerComm m => Response -> CliSerQueue Response -> m ()
readQueueAI :: MonadServerComm m => CliSerQueue RequestAI -> m RequestAI
readQueueUI :: MonadServerComm m => CliSerQueue RequestUI -> m RequestUI
newQueue :: IO (CliSerQueue a)


-- | Server operations common to many modules.
module Game.LambdaHack.Server.CommonM
revealAll :: MonadServerAtomic m => FactionId -> m ()

-- | Generate the atomic updates that jointly perform a given item move.
generalMoveItem :: MonadStateRead m => Bool -> ItemId -> Int -> Container -> Container -> m [UpdAtomic]
deduceQuits :: MonadServerAtomic m => FactionId -> Status -> m ()

-- | Save game on server and all clients.
writeSaveAll :: MonadServerAtomic m => Bool -> Bool -> m ()
verifyCaches :: MonadServer m => m ()
deduceKilled :: MonadServerAtomic m => ActorId -> m ()
electLeader :: MonadServerAtomic m => FactionId -> LevelId -> ActorId -> m ()
setFreshLeader :: MonadServerAtomic m => FactionId -> ActorId -> m ()
updatePer :: MonadServerAtomic m => FactionId -> LevelId -> m ()
projectFail :: MonadServerAtomic m => ActorId -> ActorId -> Point -> Point -> Int -> Bool -> ItemId -> CStore -> Bool -> m (Maybe ReqFailure)
addActorFromGroup :: MonadServerAtomic m => GroupName ItemKind -> FactionId -> Point -> LevelId -> Time -> m (Maybe ActorId)
registerActor :: MonadServerAtomic m => Bool -> ItemKnown -> ItemFullKit -> FactionId -> Point -> LevelId -> Time -> m ActorId
discoverIfMinorEffects :: MonadServerAtomic m => Container -> ItemId -> ContentId ItemKind -> m ()
pickWeaponServer :: MonadServer m => ActorId -> ActorId -> m (Maybe (ItemId, CStore))
currentSkillsServer :: MonadServer m => ActorId -> m Skills
allGroupItems :: MonadServerAtomic m => CStore -> GroupName ItemKind -> ActorId -> m [(ItemId, ItemQuant)]
addCondition :: MonadServerAtomic m => Bool -> GroupName ItemKind -> ActorId -> m ()
removeConditionSingle :: MonadServerAtomic m => GroupName ItemKind -> ActorId -> m Int
addSleep :: MonadServerAtomic m => ActorId -> m ()
removeSleepSingle :: MonadServerAtomic m => ActorId -> m ()
addKillToAnalytics :: MonadServerAtomic m => ActorId -> KillHow -> FactionId -> ItemId -> m ()
revealItems :: MonadServerAtomic m => FactionId -> m ()
revealPerceptionLid :: MonadServerAtomic m => FactionId -> (LevelId, Level) -> m ()
containerMoveItem :: MonadStateRead m => Bool -> ItemId -> Int -> Container -> Container -> m [UpdAtomic]
quitF :: MonadServerAtomic m => Status -> FactionId -> m ()

-- | Tell whether a faction that we know is still in game, keeps arena.
--   Keeping arena means, if the faction is still in game, it always has a
--   leader in the dungeon somewhere. So, leaderless factions and spawner
--   factions do not keep an arena, even though the latter usually has a
--   leader for most of the game.
keepArenaFact :: Faction -> Bool
anyActorsAlive :: MonadServer m => FactionId -> ActorId -> m Bool
updatePerFromNew :: MonadServerAtomic m => FactionId -> LevelId -> Perception -> m ()
recomputeCachePer :: MonadServer m => FactionId -> LevelId -> m Perception
projectBla :: MonadServerAtomic m => ActorId -> ActorId -> Point -> [Point] -> ItemId -> CStore -> Bool -> m ()
addProjectile :: MonadServerAtomic m => ActorId -> Point -> [Point] -> ItemId -> ItemQuant -> LevelId -> FactionId -> Time -> m ()
addNonProjectile :: MonadServerAtomic m => Bool -> ItemId -> ItemFullKit -> FactionId -> Point -> LevelId -> Time -> m ActorId
addActorIid :: MonadServerAtomic m => ItemId -> ItemFull -> Bool -> FactionId -> Point -> LevelId -> (Actor -> Actor) -> m ActorId
getCacheLucid :: MonadServer m => LevelId -> m FovLucid
getCacheTotal :: MonadServer m => FactionId -> LevelId -> m CacheBeforeLucid


-- | Operations for starting and restarting the game.
module Game.LambdaHack.Server.StartM
initPer :: MonadServer m => m ()
reinitGame :: MonadServerAtomic m => FactionDict -> m ()
gameReset :: MonadServer m => ServerOptions -> Maybe (GroupName ModeKind) -> Maybe SMGen -> m State

-- | Apply options that don't need a new game.
applyDebug :: MonadServer m => m ()
sampleTrunks :: MonadServerAtomic m => Dungeon -> m GenerationAnalytics
sampleItems :: MonadServerAtomic m => Dungeon -> m GenerationAnalytics
mapFromFuns :: Ord b => [a] -> [a -> b] -> Map b a
resetFactions :: ContentData FactionKind -> AbsDepth -> ModeKind -> Bool -> Rnd FactionDict
populateDungeon :: forall m. MonadServerAtomic m => m ()

-- | Find starting postions for all factions. Try to make them distant from
--   each other. Place as many of the factions, as possible, over stairs.
--   Place the first faction(s) over escape(s) (we assume they are
--   guardians of the escapes). This implies the inital factions (if any)
--   start far from escapes.
findEntryPoss :: COps -> Level -> Int -> Rnd [Point]


-- | Server operations performed periodically in the game loop and related
--   operations.
module Game.LambdaHack.Server.PeriodicM

-- | Spawn, possibly, a monster according to the level's actor groups. We
--   assume heroes are never spawned.
spawnMonster :: MonadServerAtomic m => m ()
addManyActors :: MonadServerAtomic m => Bool -> Int -> Freqs ItemKind -> LevelId -> Time -> Maybe Point -> Int -> m Bool

-- | Advance the move time for the given actor.
advanceTime :: MonadServerAtomic m => ActorId -> Int -> Bool -> m ()

-- | Advance the trajectory following time for the given actor.
advanceTimeTraj :: MonadServerAtomic m => ActorId -> m ()

-- | Add communication overhead time delta to all non-projectile, non-dying
--   faction's actors, except the leader. Effectively, this limits moves of
--   a faction on a level to 10, regardless of the number of actors and
--   their speeds. To avoid animals suddenly acting extremely sluggish
--   whenever monster's leader visits a distant arena that has a crowd of
--   animals, overhead applies only to actors on the same level. Since the
--   number of active levels is limited, this bounds the total moves per
--   turn of each faction as well.
--   
--   Leader is immune from overhead and so he is faster than other faction
--   members and of equal speed to leaders of other factions (of equal base
--   speed) regardless how numerous the faction is. Thanks to this, there
--   is no problem with leader of a numerous faction having very long UI
--   turns, introducing UI lag.
overheadActorTime :: MonadServerAtomic m => FactionId -> LevelId -> m ()

-- | Swap the relative move times of two actors (e.g., when switching a UI
--   leader). Notice that their trajectory move times are not swapped.
swapTime :: MonadServerAtomic m => ActorId -> ActorId -> m ()
updateCalm :: MonadServerAtomic m => ActorId -> Int64 -> m ()
leadLevelSwitch :: MonadServerAtomic m => m ()

-- | Continue or exit or restart the game.
endOrLoop :: (MonadServerAtomic m, MonadServerComm m) => m () -> (Maybe (GroupName ModeKind) -> m ()) -> m ()
addAnyActor :: MonadServerAtomic m => Bool -> Int -> Freqs ItemKind -> LevelId -> Time -> Maybe Point -> m (Maybe (ActorId, Point))
rollSpawnPos :: COps -> EnumSet Point -> Bool -> Bool -> LevelId -> Level -> FactionId -> State -> Rnd (Maybe Point)
gameExit :: (MonadServerAtomic m, MonadServerComm m) => m ()


-- | Handle effects. They are most often caused by requests sent by clients
--   but sometimes also caused by projectiles or periodically activated
--   items.
module Game.LambdaHack.Server.HandleEffectM
data UseResult
UseDud :: UseResult
UseId :: UseResult
UseUp :: UseResult
data EffToUse
EffBare :: EffToUse
EffBareAndOnCombine :: EffToUse
EffOnCombine :: EffToUse
data EffApplyFlags
EffApplyFlags :: EffToUse -> Bool -> Bool -> Bool -> ActivationFlag -> Bool -> EffApplyFlags
[effToUse] :: EffApplyFlags -> EffToUse
[effVoluntary] :: EffApplyFlags -> Bool
[effUseAllCopies] :: EffApplyFlags -> Bool
[effKineticPerformed] :: EffApplyFlags -> Bool
[effActivation] :: EffApplyFlags -> ActivationFlag
[effMayDestroy] :: EffApplyFlags -> Bool
applyItem :: MonadServerAtomic m => ActorId -> ItemId -> CStore -> m ()
cutCalm :: MonadServerAtomic m => ActorId -> m ()
kineticEffectAndDestroy :: MonadServerAtomic m => EffApplyFlags -> ActorId -> ActorId -> ActorId -> ItemId -> Container -> m UseResult
effectAndDestroyAndAddKill :: MonadServerAtomic m => EffApplyFlags -> ActorId -> ActorId -> ActorId -> ItemId -> Container -> ItemFull -> m UseResult
itemEffectEmbedded :: MonadServerAtomic m => EffToUse -> Bool -> ActorId -> LevelId -> Point -> ItemId -> m UseResult
highestImpression :: MonadServerAtomic m => Actor -> m (Maybe (FactionId, Int))
dominateFidSfx :: MonadServerAtomic m => ActorId -> ActorId -> ItemId -> FactionId -> m Bool

-- | Drop all actor's equipped items.
dropAllEquippedItems :: MonadServerAtomic m => ActorId -> Actor -> m ()
pickDroppable :: MonadStateRead m => Bool -> ActorId -> Actor -> m Container
consumeItems :: MonadServerAtomic m => ActorId -> EnumMap CStore ItemBag -> [(CStore, (ItemId, ItemFull))] -> m ()

-- | Drop a single actor's item (though possibly multiple copies). Note
--   that if there are multiple copies, at most one explodes to avoid
--   excessive carnage and UI clutter (let's say, the multiple explosions
--   interfere with each other or perhaps larger quantities of explosives
--   tend to be packaged more safely). Note also that <tt>OnSmash</tt>
--   effects are activated even if item discharged.
dropCStoreItem :: MonadServerAtomic m => Bool -> Bool -> CStore -> ActorId -> Actor -> Int -> ItemId -> ItemQuant -> m UseResult
applyKineticDamage :: MonadServerAtomic m => ActorId -> ActorId -> ItemId -> m Bool
refillHP :: MonadServerAtomic m => ActorId -> ActorId -> Int64 -> m ()
effectAndDestroy :: MonadServerAtomic m => EffApplyFlags -> ActorId -> ActorId -> ItemId -> Container -> ItemFull -> m UseResult
imperishableKit :: ActivationFlag -> ItemFull -> Bool

-- | The source actor affects the target actor, with a given item. If any
--   of the effects fires up, the item gets identified. Even using raw
--   damage (beating the enemy with the magic wand, for example) identifies
--   the item. This means a costly <tt>UpdDiscover</tt> is processed for
--   each random timeout weapon hit and for most projectiles, but at least
--   not for most explosion particles nor plain organs. And if not needed,
--   the <tt>UpdDiscover</tt> are eventually not sent to clients. So, enemy
--   missiles that hit us are no longer mysterious until picked up, which
--   is for the better, because the client knows their charging status and
--   so can generate accurate messages in the case when not recharged. This
--   also means that thrown consumables in flasks sturdy enough to cause
--   damage are always identified at hit, even if no effect activated. So
--   throwing them at foes is a better identification method than applying.
--   
--   Note that if we activate a durable non-passive item, e.g., a spiked
--   shield, from the ground, it will get identified, which is perfectly
--   fine, until we want to add sticky armor that can't be easily taken off
--   (and, e.g., has some maluses).
itemEffectDisco :: MonadServerAtomic m => EffApplyFlags -> ActorId -> ActorId -> ItemId -> ContentId ItemKind -> ItemKind -> Container -> [Effect] -> m UseResult

-- | Source actor affects target actor, with a given effect and it
--   strength. Both actors are on the current level and can be the same
--   actor. The item may or may not still be in the container.
effectSem :: MonadServerAtomic m => EffApplyFlags -> ActorId -> ActorId -> ItemId -> Container -> Effect -> m UseResult
effectBurn :: MonadServerAtomic m => Dice -> ActorId -> ActorId -> ItemId -> m UseResult
effectExplode :: MonadServerAtomic m => m () -> GroupName ItemKind -> ActorId -> ActorId -> Container -> m UseResult
effectRefillHP :: MonadServerAtomic m => Int -> ActorId -> ActorId -> ItemId -> m UseResult
effectRefillCalm :: MonadServerAtomic m => m () -> Int -> ActorId -> ActorId -> m UseResult
effectDominate :: MonadServerAtomic m => ActorId -> ActorId -> ItemId -> m UseResult
dominateFid :: MonadServerAtomic m => FactionId -> ActorId -> ActorId -> m ()
effectImpress :: MonadServerAtomic m => (Effect -> m UseResult) -> m () -> ActorId -> ActorId -> m UseResult
effectPutToSleep :: MonadServerAtomic m => m () -> ActorId -> m UseResult
effectYell :: MonadServerAtomic m => m () -> ActorId -> m UseResult
effectSummon :: MonadServerAtomic m => GroupName ItemKind -> Dice -> ItemId -> ActorId -> ActorId -> ActivationFlag -> m UseResult
effectAscend :: MonadServerAtomic m => (Effect -> m UseResult) -> m () -> Bool -> ActorId -> ActorId -> Container -> m UseResult
findStairExit :: MonadStateRead m => FactionId -> Bool -> LevelId -> Point -> m Point
switchLevels1 :: MonadServerAtomic m => (ActorId, Actor) -> m (Maybe ActorId)
switchLevels2 :: MonadServerAtomic m => LevelId -> Point -> (ActorId, Actor) -> Maybe Time -> Maybe Time -> Maybe ActorId -> m ()

-- | The faction leaves the dungeon.
effectEscape :: MonadServerAtomic m => m () -> ActorId -> ActorId -> m UseResult

-- | Advance target actor time by this many time clips. Not by actor moves,
--   to hurt fast actors more.
effectParalyze :: MonadServerAtomic m => m () -> Dice -> ActorId -> ActorId -> m UseResult
paralyze :: MonadServerAtomic m => m () -> Dice -> ActorId -> ActorId -> m UseResult

-- | Advance target actor time by this many time clips. Not by actor moves,
--   to hurt fast actors more. Due to water, so resistable.
effectParalyzeInWater :: MonadServerAtomic m => m () -> Dice -> ActorId -> ActorId -> m UseResult

-- | Give target actor the given number of tenths of extra move. Don't give
--   an absolute amount of time units, to benefit slow actors more.
effectInsertMove :: MonadServerAtomic m => m () -> Dice -> ActorId -> ActorId -> m UseResult

-- | Teleport the target actor. Note that projectiles can be teleported,
--   too, for extra fun.
effectTeleport :: MonadServerAtomic m => m () -> Dice -> ActorId -> ActorId -> m UseResult
effectCreateItem :: MonadServerAtomic m => Maybe FactionId -> Maybe Int -> ActorId -> ActorId -> Maybe ItemId -> CStore -> GroupName ItemKind -> TimerDice -> m UseResult

-- | Make the target actor destroy items in a store from the given group.
--   The item that caused the effect itself is *not* immune, because often
--   the item needs to destroy itself, e.g., to model wear and tear. In
--   such a case, the item may need to be identified, in a container, when
--   it no longer exists, at least in the container. This is OK. Durable
--   items are not immune, unlike the tools in <tt>ConsumeItems</tt>.
effectDestroyItem :: MonadServerAtomic m => m () -> Int -> Int -> CStore -> ActorId -> GroupName ItemKind -> m UseResult

-- | Make the target actor drop items in a store from the given group. The
--   item that caused the effect itself is immune (any copies).
effectDropItem :: MonadServerAtomic m => m () -> ItemId -> Int -> Int -> CStore -> GroupName ItemKind -> ActorId -> m UseResult

-- | Make the target actor destroy the given items, if all present, or none
--   at all, if any is missing. To be used in crafting. The item that
--   caused the effect itself is not considered (any copies).
effectConsumeItems :: MonadServerAtomic m => m () -> ItemId -> ActorId -> [(Int, GroupName ItemKind)] -> [(Int, GroupName ItemKind)] -> m UseResult
effectRecharge :: forall m. MonadServerAtomic m => Bool -> m () -> ItemId -> Int -> Dice -> ActorId -> m UseResult
effectPolyItem :: MonadServerAtomic m => m () -> ItemId -> ActorId -> m UseResult
effectRerollItem :: forall m. MonadServerAtomic m => m () -> ItemId -> ActorId -> m UseResult
effectDupItem :: MonadServerAtomic m => m () -> ItemId -> ActorId -> m UseResult
effectIdentify :: MonadServerAtomic m => m () -> ItemId -> ActorId -> m UseResult
identifyIid :: MonadServerAtomic m => ItemId -> Container -> ContentId ItemKind -> ItemKind -> m ()
effectDetect :: MonadServerAtomic m => m () -> DetectKind -> Int -> ActorId -> Container -> m UseResult
effectDetectX :: MonadServerAtomic m => DetectKind -> (Point -> Bool) -> ([Point] -> m Bool) -> m () -> Int -> ActorId -> m UseResult

-- | Send the target actor flying like a projectile. If the actors are
--   adjacent, the vector is directed outwards, if no, inwards, if it's the
--   same actor, boldpos is used, if it can't, a random outward vector of
--   length 10 is picked.
effectSendFlying :: MonadServerAtomic m => m () -> ThrowMod -> ActorId -> ActorId -> Container -> Maybe Bool -> m UseResult
sendFlyingVector :: MonadServerAtomic m => ActorId -> ActorId -> Container -> Maybe Bool -> m Vector
effectApplyPerfume :: MonadServerAtomic m => m () -> ActorId -> m UseResult
effectAtMostOneOf :: MonadServerAtomic m => (Effect -> m UseResult) -> [Effect] -> m UseResult
effectOneOf :: MonadServerAtomic m => (Effect -> m UseResult) -> [Effect] -> m UseResult
effectAndEffect :: forall m. MonadServerAtomic m => (Effect -> m UseResult) -> ActorId -> Effect -> Effect -> m UseResult
effectAndEffectSem :: forall m. MonadServerAtomic m => (Effect -> m UseResult) -> Effect -> Effect -> m UseResult
effectOrEffect :: forall m. MonadServerAtomic m => (Effect -> m UseResult) -> FactionId -> Effect -> Effect -> m UseResult
effectSeqEffect :: forall m. MonadServerAtomic m => (Effect -> m UseResult) -> [Effect] -> m UseResult
effectWhen :: forall m. MonadServerAtomic m => (Effect -> m UseResult) -> ActorId -> Condition -> Effect -> ActivationFlag -> m UseResult
effectUnless :: forall m. MonadServerAtomic m => (Effect -> m UseResult) -> ActorId -> Condition -> Effect -> ActivationFlag -> m UseResult
effectIfThenElse :: forall m. MonadServerAtomic m => (Effect -> m UseResult) -> ActorId -> Condition -> Effect -> Effect -> ActivationFlag -> m UseResult
effectVerbNoLonger :: MonadServerAtomic m => Bool -> m () -> ActorId -> m UseResult
effectVerbMsg :: MonadServerAtomic m => m () -> ActorId -> m UseResult
effectVerbMsgFail :: MonadServerAtomic m => m () -> ActorId -> m UseResult
instance GHC.Classes.Ord Game.LambdaHack.Server.HandleEffectM.UseResult
instance GHC.Classes.Eq Game.LambdaHack.Server.HandleEffectM.UseResult
instance GHC.Classes.Eq Game.LambdaHack.Server.HandleEffectM.EffToUse


-- | Semantics of requests . A couple of them do not take time, the rest
--   does. Note that since the results are atomic commands, which are
--   executed only later (on the server and some of the clients), all
--   condition are checkd by the semantic functions in the context of the
--   state before the server command. Even if one or more atomic actions
--   are already issued by the point an expression is evaluated, they do
--   not influence the outcome of the evaluation.
module Game.LambdaHack.Server.HandleRequestM

-- | The semantics of server commands. AI always takes time and so doesn't
--   loop.
handleRequestAI :: MonadServerAtomic m => ReqAI -> m (Maybe RequestTimed)

-- | The semantics of server commands. Only the first two cases affect
--   time.
handleRequestUI :: MonadServerAtomic m => FactionId -> ActorId -> ReqUI -> m (Maybe RequestTimed)
handleRequestTimed :: MonadServerAtomic m => FactionId -> ActorId -> RequestTimed -> m Bool
switchLeader :: MonadServerAtomic m => FactionId -> ActorId -> m ()
reqMoveGeneric :: MonadServerAtomic m => Bool -> Bool -> ActorId -> Vector -> m ()
reqDisplaceGeneric :: MonadServerAtomic m => Bool -> ActorId -> ActorId -> m ()
reqAlterFail :: forall m. MonadServerAtomic m => Bool -> EffToUse -> Bool -> ActorId -> Point -> m (Maybe ReqFailure)
reqGameDropAndExit :: MonadServerAtomic m => ActorId -> m ()
reqGameSaveAndExit :: MonadServerAtomic m => ActorId -> m ()
execFailure :: MonadServerAtomic m => ActorId -> RequestTimed -> ReqFailure -> m ()
checkWaiting :: RequestTimed -> Maybe Bool

-- | This is a shorthand. Instead of setting <tt>bwatch</tt> in
--   <tt>ReqWait</tt> and unsetting in all other requests, we call this
--   once after executing a request. In game state, we collect the number
--   of server requests pertaining to the actor (the number of actor's
--   "moves"), through which the actor was waiting.
processWatchfulness :: MonadServerAtomic m => Maybe Bool -> ActorId -> m ()
affectStash :: MonadServerAtomic m => Actor -> m ()

-- | Clear deltas for Calm and HP for proper UI display and AI hints.
managePerRequest :: MonadServerAtomic m => ActorId -> m ()
handleRequestTimedCases :: MonadServerAtomic m => ActorId -> RequestTimed -> m ()

-- | Add a smell trace for the actor to the level. If smell already there
--   and the actor can smell, remove smell. Projectiles are ignored. As
--   long as an actor can smell, he doesn't leave any smell ever. Smell
--   trace is never left in water tiles.
affectSmell :: MonadServerAtomic m => ActorId -> m ()

-- | Actor moves or attacks or alters by bumping. Note that client may not
--   be able to see an invisible monster so it's the server that determines
--   if melee took place, etc. Also, only the server is authorized to check
--   if a move is legal and it needs full context for that, e.g., the
--   initial actor position to check if melee attack does not try to reach
--   to a distant tile.
reqMove :: MonadServerAtomic m => ActorId -> Vector -> m ()

-- | Resolves the result of an actor moving into another. Actors on
--   unwalkable positions can be attacked without any restrictions. For
--   instance, an actor embedded in a wall can be attacked from an adjacent
--   position. This function is analogous to projectGroupItem, but for
--   melee and not using up the weapon. No problem if there are many
--   projectiles at the spot. We just attack the one specified.
reqMelee :: MonadServerAtomic m => ActorId -> ActorId -> ItemId -> CStore -> m ()
reqMeleeChecked :: forall m. MonadServerAtomic m => Bool -> ActorId -> ActorId -> ItemId -> CStore -> m ()

-- | Actor tries to swap positions with another.
reqDisplace :: MonadServerAtomic m => ActorId -> ActorId -> m ()

-- | Search and/or alter the tile.
reqAlter :: MonadServerAtomic m => ActorId -> Point -> m ()

-- | Do nothing. Wait skill 1 required. Bracing requires 2, sleep 3,
--   lurking 4.
--   
--   Something is sometimes done in <a>processWatchfulness</a>.
reqWait :: MonadServerAtomic m => ActorId -> m ()

-- | Do nothing.
--   
--   Something is sometimes done in <a>processWatchfulness</a>.
reqWait10 :: MonadServerAtomic m => ActorId -> m ()

-- | Yell<i>yawn</i>stretch/taunt. Wakes up (gradually) from sleep. Causes
--   noise heard by enemies on the level even if out of their hearing
--   range.
--   
--   Governed by the waiting skill (because everyone is supposed to have
--   it). unlike <tt>ReqWait</tt>, induces overhead.
--   
--   This is similar to the effect <tt>Yell</tt>, but always voluntary.
reqYell :: MonadServerAtomic m => ActorId -> m ()
reqMoveItems :: MonadServerAtomic m => ActorId -> [(ItemId, Int, CStore, CStore)] -> m ()
reqMoveItem :: MonadServerAtomic m => Bool -> ActorId -> Bool -> (ItemId, Int, CStore, CStore) -> m ()
reqProject :: MonadServerAtomic m => ActorId -> Point -> Int -> ItemId -> CStore -> m ()
reqApply :: MonadServerAtomic m => ActorId -> ItemId -> CStore -> m ()
reqGameRestart :: MonadServerAtomic m => ActorId -> GroupName ModeKind -> Challenge -> m ()
reqGameSave :: MonadServer m => m ()
reqDoctrine :: MonadServerAtomic m => FactionId -> Doctrine -> m ()
reqAutomate :: MonadServerAtomic m => FactionId -> m ()


-- | The main loop of the server, processing human and computer player
--   moves turn by turn.
module Game.LambdaHack.Server.LoopM

-- | Start a game session, including the clients, and then loop,
--   communicating with the clients.
--   
--   The loop is started in server state that is empty, see
--   <a>emptyStateServer</a>.
loopSer :: (MonadServerAtomic m, MonadServerComm m) => ServerOptions -> (Bool -> FactionId -> ChanServer -> IO ()) -> m ()
factionArena :: MonadStateRead m => Faction -> m (Maybe LevelId)
arenasForLoop :: MonadStateRead m => m (EnumSet LevelId)
handleFidUpd :: forall m. (MonadServerAtomic m, MonadServerComm m) => (FactionId -> m ()) -> FactionId -> Faction -> m ()

-- | Handle a clip (the smallest fraction of a game turn for which a frame
--   may potentially be generated). Run the leader and other actors moves.
--   Eventually advance the time and repeat.
loopUpd :: forall m. (MonadServerAtomic m, MonadServerComm m) => m () -> m ()

-- | Handle the end of every clip. Do whatever has to be done every fixed
--   number of clips, e.g., monster generation. Advance time. Perform
--   periodic saves, if applicable.
--   
--   This is never run if UI requested save or exit or restart and it's
--   correct, because we know nobody moved and no time was or needs to be
--   advanced and arenas are not changed. After game was saved and exited,
--   on game resume the first clip is performed with empty arenas, so arena
--   time is not updated and nobody moves, nor anything happens, but arenas
--   are here correctly updated.
endClip :: forall m. MonadServerAtomic m => (FactionId -> m ()) -> m ()

-- | Check if the given actor is dominated and update his calm.
manageCalmAndDomination :: MonadServerAtomic m => ActorId -> Actor -> m ()

-- | Trigger periodic items for all actors on the given level.
applyPeriodicLevel :: MonadServerAtomic m => m ()
handleTrajectories :: MonadServerAtomic m => LevelId -> FactionId -> m ()
hTrajectories :: MonadServerAtomic m => ActorId -> m ()

-- | Manage trajectory of a projectile or a pushed other actor.
--   
--   Colliding with a wall or actor doesn't take time, because the
--   projectile does not move (the move is blocked). Not advancing time
--   forces dead projectiles to be destroyed ASAP. Otherwise, with some
--   timings, it can stay on the game map dead, blocking path of
--   human-controlled actors and alarming the hapless human.
advanceTrajectory :: MonadServerAtomic m => ActorId -> Actor -> m ()
handleActors :: (MonadServerAtomic m, MonadServerComm m) => LevelId -> FactionId -> m Bool
hActors :: forall m. (MonadServerAtomic m, MonadServerComm m) => [ActorId] -> m Bool
handleUIunderAI :: (MonadServerAtomic m, MonadServerComm m) => FactionId -> ActorId -> m ()
dieSer :: MonadServerAtomic m => ActorId -> Actor -> m ()
restartGame :: MonadServerAtomic m => m () -> m () -> Maybe (GroupName ModeKind) -> m ()


-- | Sending atomic commands to clients and executing them on the server.
--   
--   See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Client-server-architecture</a>.
module Game.LambdaHack.Server.BroadcastAtomic

-- | Send an atomic action to all clients that can see it.
handleAndBroadcast :: (MonadServerAtomic m, MonadServerComm m) => PosAtomic -> [UpdAtomic] -> CmdAtomic -> m ()
sendPer :: (MonadServerAtomic m, MonadServerComm m) => FactionId -> LevelId -> Perception -> Perception -> Perception -> m ()
handleCmdAtomicServer :: MonadServerAtomic m => UpdAtomic -> m (PosAtomic, [UpdAtomic], Bool)
cmdItemsFromIids :: [ItemId] -> State -> State -> [UpdAtomic]

-- | Messages for some unseen atomic commands.
hearUpdAtomic :: MonadStateRead m => UpdAtomic -> m (Bool, Maybe Point)

-- | Messages for some unseen sfx.
hearSfxAtomic :: MonadServer m => SfxAtomic -> m (Maybe (HearMsg, Bool, Point))
filterHear :: MonadStateRead m => Point -> [(ActorId, Actor)] -> m [ActorId]
atomicForget :: FactionId -> LevelId -> Perception -> State -> [UpdAtomic]
atomicRemember :: LevelId -> Perception -> State -> State -> [UpdAtomic]


-- | Parsing of commandline arguments.
module Game.LambdaHack.Server.Commandline

-- | Parser for server options from commandline arguments.
serverOptionsPI :: ParserInfo ServerOptions
serverOptionsP :: Parser ServerOptions


-- | Semantics of requests that are sent by clients to the server, in terms
--   of game state changes and responses to be sent to the clients.
--   
--   See
--   <a>https://github.com/LambdaHack/LambdaHack/wiki/Client-server-architecture</a>.
module Game.LambdaHack.Server

-- | Start a game session, including the clients, and then loop,
--   communicating with the clients.
--   
--   The loop is started in server state that is empty, see
--   <a>emptyStateServer</a>.
loopSer :: (MonadServerAtomic m, MonadServerComm m) => ServerOptions -> (Bool -> FactionId -> ChanServer -> IO ()) -> m ()

-- | Connection channel between the server and a single client.
data ChanServer
ChanServer :: CliSerQueue Response -> CliSerQueue RequestAI -> Maybe (CliSerQueue RequestUI) -> ChanServer
[responseS] :: ChanServer -> CliSerQueue Response
[requestAIS] :: ChanServer -> CliSerQueue RequestAI
[requestUIS] :: ChanServer -> Maybe (CliSerQueue RequestUI)

-- | Parser for server options from commandline arguments.
serverOptionsPI :: ParserInfo ServerOptions

-- | Options that affect the behaviour of the server (including game
--   rules).
data ServerOptions
ServerOptions :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe (GroupName ModeKind) -> Bool -> Bool -> Maybe SMGen -> Maybe SMGen -> Bool -> Challenge -> Bool -> String -> Bool -> Maybe Int -> Bool -> Bool -> ClientOptions -> ServerOptions
[sknowMap] :: ServerOptions -> Bool
[sknowEvents] :: ServerOptions -> Bool
[sknowItems] :: ServerOptions -> Bool
[sniff] :: ServerOptions -> Bool
[sallClear] :: ServerOptions -> Bool
[sboostRandomItem] :: ServerOptions -> Bool
[sgameMode] :: ServerOptions -> Maybe (GroupName ModeKind)
[sautomateAll] :: ServerOptions -> Bool
[skeepAutomated] :: ServerOptions -> Bool
[sdungeonRng] :: ServerOptions -> Maybe SMGen
[smainRng] :: ServerOptions -> Maybe SMGen
[snewGameSer] :: ServerOptions -> Bool
[scurChalSer] :: ServerOptions -> Challenge
[sdumpInitRngs] :: ServerOptions -> Bool
[ssavePrefixSer] :: ServerOptions -> String
[sdbgMsgSer] :: ServerOptions -> Bool
[sassertExplored] :: ServerOptions -> Maybe Int
[sshowItemSamples] :: ServerOptions -> Bool
[sstopAfterGameOver] :: ServerOptions -> Bool
[sclientOptions] :: ServerOptions -> ClientOptions


-- | The implementation of our custom game client monads. Just as any other
--   component of the library, this implementation can be substituted.
module Implementation.MonadClientImplementation

-- | Run the main client loop, with the given arguments and empty initial
--   states, in the <tt>IO</tt> monad.
executorCli :: CCUI -> UIOptions -> ClientOptions -> Bool -> COps -> FactionId -> ChanServer -> IO ()
data CliState
CliState :: State -> StateClient -> Maybe SessionUI -> ChanServer -> ChanSave (StateClient, Maybe SessionUI) -> CliState

-- | current global state
[cliState] :: CliState -> State

-- | current client state
[cliClient] :: CliState -> StateClient

-- | UI state, empty for AI clients
[cliSession] :: CliState -> Maybe SessionUI

-- | this client connection information
[cliDict] :: CliState -> ChanServer

-- | connection to the save thread
[cliToSave] :: CliState -> ChanSave (StateClient, Maybe SessionUI)

-- | Client state transformation monad.
newtype CliImplementation a
CliImplementation :: StateT CliState IO a -> CliImplementation a
[runCliImplementation] :: CliImplementation a -> StateT CliState IO a
instance GHC.Base.Applicative Implementation.MonadClientImplementation.CliImplementation
instance GHC.Base.Functor Implementation.MonadClientImplementation.CliImplementation
instance GHC.Base.Monad Implementation.MonadClientImplementation.CliImplementation
instance Game.LambdaHack.Common.MonadStateRead.MonadStateRead Implementation.MonadClientImplementation.CliImplementation
instance Game.LambdaHack.Atomic.MonadStateWrite.MonadStateWrite Implementation.MonadClientImplementation.CliImplementation
instance Game.LambdaHack.Client.MonadClient.MonadClientRead Implementation.MonadClientImplementation.CliImplementation
instance Game.LambdaHack.Client.MonadClient.MonadClient Implementation.MonadClientImplementation.CliImplementation
instance Game.LambdaHack.Client.HandleAtomicM.MonadClientSetup Implementation.MonadClientImplementation.CliImplementation
instance Game.LambdaHack.Client.UI.MonadClientUI.MonadClientUI Implementation.MonadClientImplementation.CliImplementation
instance Game.LambdaHack.Client.LoopM.MonadClientReadResponse Implementation.MonadClientImplementation.CliImplementation
instance Game.LambdaHack.Client.HandleResponseM.MonadClientWriteRequest Implementation.MonadClientImplementation.CliImplementation
instance Game.LambdaHack.Client.HandleResponseM.MonadClientAtomic Implementation.MonadClientImplementation.CliImplementation


-- | The implementation of our custom game server monads. Just as any other
--   component of the library, this implementation can be substituted.
module Implementation.MonadServerImplementation

-- | Run the main server loop, with the given arguments and empty initial
--   states, in the <tt>IO</tt> monad.
executorSer :: COps -> CCUI -> ServerOptions -> UIOptions -> IO ()
data SerState
SerState :: State -> StateServer -> ConnServerDict -> ChanSave (State, StateServer) -> SerState

-- | current global state
[serState] :: SerState -> State

-- | current server state
[serServer] :: SerState -> StateServer

-- | client-server connection information
[serDict] :: SerState -> ConnServerDict

-- | connection to the save thread
[serToSave] :: SerState -> ChanSave (State, StateServer)

-- | Server state transformation monad.
newtype SerImplementation a
SerImplementation :: StateT SerState IO a -> SerImplementation a
[runSerImplementation] :: SerImplementation a -> StateT SerState IO a
instance GHC.Base.Applicative Implementation.MonadServerImplementation.SerImplementation
instance GHC.Base.Functor Implementation.MonadServerImplementation.SerImplementation
instance GHC.Base.Monad Implementation.MonadServerImplementation.SerImplementation
instance Game.LambdaHack.Common.MonadStateRead.MonadStateRead Implementation.MonadServerImplementation.SerImplementation
instance Game.LambdaHack.Atomic.MonadStateWrite.MonadStateWrite Implementation.MonadServerImplementation.SerImplementation
instance Game.LambdaHack.Server.MonadServer.MonadServer Implementation.MonadServerImplementation.SerImplementation
instance Game.LambdaHack.Server.ProtocolM.MonadServerComm Implementation.MonadServerImplementation.SerImplementation
instance Game.LambdaHack.Server.MonadServer.MonadServerAtomic Implementation.MonadServerImplementation.SerImplementation


-- | Game rules and assorted game setup data.
module Content.RuleKind
standardRules :: RuleContent


-- | Actor organ definitions.
module Content.ItemKindOrgan
pattern S_FIST :: GroupName ItemKind
pattern S_FOOT :: GroupName ItemKind
pattern S_HOOKED_CLAW :: GroupName ItemKind
pattern S_SMALL_CLAW :: GroupName ItemKind
pattern S_SNOUT :: GroupName ItemKind
pattern S_SMALL_JAW :: GroupName ItemKind
pattern S_JAW :: GroupName ItemKind
pattern S_LARGE_JAW :: GroupName ItemKind
pattern S_ANTLER :: GroupName ItemKind
pattern S_HORN :: GroupName ItemKind
pattern S_RHINO_HORN :: GroupName ItemKind
pattern S_TENTACLE :: GroupName ItemKind
pattern S_TIP :: GroupName ItemKind
pattern S_LIP :: GroupName ItemKind
pattern S_THORN :: GroupName ItemKind
pattern S_BOILING_FISSURE :: GroupName ItemKind
pattern S_ARSENIC_FISSURE :: GroupName ItemKind
pattern S_SULFUR_FISSURE :: GroupName ItemKind
pattern S_BEE_STING :: GroupName ItemKind
pattern S_STING :: GroupName ItemKind
pattern S_VENOM_TOOTH :: GroupName ItemKind
pattern S_VENOM_FANG :: GroupName ItemKind
pattern S_SCREECHING_BEAK :: GroupName ItemKind
pattern S_LARGE_TAIL :: GroupName ItemKind
pattern S_HUGE_TAIL :: GroupName ItemKind
pattern S_ARMORED_SKIN :: GroupName ItemKind
pattern S_BARK :: GroupName ItemKind
pattern S_NOSTRIL :: GroupName ItemKind
pattern S_RATLLE :: GroupName ItemKind
pattern S_INSECT_MORTALITY :: GroupName ItemKind
pattern S_SAPIENT_BRAIN :: GroupName ItemKind
pattern S_ANIMAL_BRAIN :: GroupName ItemKind
pattern S_SCENT_GLAND :: GroupName ItemKind
pattern S_BOILING_VENT :: GroupName ItemKind
pattern S_ARSENIC_VENT :: GroupName ItemKind
pattern S_SULFUR_VENT :: GroupName ItemKind
pattern S_EYE_3 :: GroupName ItemKind
pattern S_EYE_6 :: GroupName ItemKind
pattern S_EYE_8 :: GroupName ItemKind
pattern S_VISION_6 :: GroupName ItemKind
pattern S_VISION_12 :: GroupName ItemKind
pattern S_VISION_16 :: GroupName ItemKind
pattern S_EAR_3 :: GroupName ItemKind
pattern S_EAR_6 :: GroupName ItemKind
pattern S_EAR_8 :: GroupName ItemKind
pattern S_SPEED_GLAND_5 :: GroupName ItemKind
pattern S_SPEED_GLAND_10 :: GroupName ItemKind
pattern SCAVENGER :: GroupName ItemKind
pattern S_TOOTH :: GroupName ItemKind
pattern S_LASH :: GroupName ItemKind
pattern S_RIGHT_TORSION :: GroupName ItemKind
pattern S_LEFT_TORSION :: GroupName ItemKind
pattern S_PUPIL :: GroupName ItemKind
organsGNSingleton :: [GroupName ItemKind]
organsGN :: [GroupName ItemKind]
organs :: [ItemKind]


-- | Actor (or rather actor body trunk) definitions.
module Content.ItemKindActor
pattern S_WOODEN_TORCH :: GroupName ItemKind
pattern S_SANDSTONE_ROCK :: GroupName ItemKind
pattern HERO :: GroupName ItemKind
pattern SCOUT_HERO :: GroupName ItemKind
pattern RANGER_HERO :: GroupName ItemKind
pattern ESCAPIST_HERO :: GroupName ItemKind
pattern AMBUSHER_HERO :: GroupName ItemKind
pattern BRAWLER_HERO :: GroupName ItemKind
pattern SOLDIER_HERO :: GroupName ItemKind
pattern CIVILIAN :: GroupName ItemKind
pattern MONSTER :: GroupName ItemKind
pattern MOBILE_MONSTER :: GroupName ItemKind
pattern SCOUT_MONSTER :: GroupName ItemKind
pattern ANIMAL :: GroupName ItemKind
pattern MOBILE_ANIMAL :: GroupName ItemKind
pattern IMMOBILE_ANIMAL :: GroupName ItemKind
pattern INSECT :: GroupName ItemKind
pattern GEOPHENOMENON :: GroupName ItemKind
pattern ADD_SIGHT :: GroupName ItemKind
pattern ARMOR_RANGED :: GroupName ItemKind
pattern ADD_NOCTO_1 :: GroupName ItemKind
pattern WEAK_ARROW :: GroupName ItemKind
pattern LIGHT_ATTENUATOR :: GroupName ItemKind
pattern FIREPROOF_CLOTH :: GroupName ItemKind
pattern RING_OF_OPPORTUNITY_SNIPER :: GroupName ItemKind
pattern ANY_ARROW :: GroupName ItemKind
pattern STARTING_ARMOR :: GroupName ItemKind
pattern STARTING_WEAPON :: GroupName ItemKind
pattern GEM :: GroupName ItemKind
actorsGN :: [GroupName ItemKind]
actorsGNSingleton :: [GroupName ItemKind]
actors :: [ItemKind]


-- | Definitions of items embedded in map tiles.
module Content.ItemKindEmbed
pattern SCRATCH_ON_WALL :: GroupName ItemKind
pattern OBSCENE_PICTOGRAM :: GroupName ItemKind
pattern SUBTLE_FRESCO :: GroupName ItemKind
pattern TREASURE_CACHE :: GroupName ItemKind
pattern TREASURE_CACHE_TRAP :: GroupName ItemKind
pattern SIGNAGE :: GroupName ItemKind
pattern SMALL_FIRE :: GroupName ItemKind
pattern BIG_FIRE :: GroupName ItemKind
pattern FROST :: GroupName ItemKind
pattern RUBBLE :: GroupName ItemKind
pattern DOORWAY_TRAP_UNKNOWN :: GroupName ItemKind
pattern DOORWAY_TRAP :: GroupName ItemKind
pattern STAIRS_UP :: GroupName ItemKind
pattern STAIRS_DOWN :: GroupName ItemKind
pattern ESCAPE :: GroupName ItemKind
pattern STAIRS_TRAP_UP :: GroupName ItemKind
pattern STAIRS_TRAP_DOWN :: GroupName ItemKind
pattern LECTERN :: GroupName ItemKind
pattern SHALLOW_WATER :: GroupName ItemKind
pattern STRAIGHT_PATH :: GroupName ItemKind
pattern FROZEN_GROUND :: GroupName ItemKind
embedsGN :: [GroupName ItemKind]
embeds :: [ItemKind]


-- | Definitions of tile kinds. Every terrain tile in the game is an
--   instantiated tile kind.
module Content.TileKind
pattern FILLER_WALL :: GroupName TileKind
pattern FLOOR_CORRIDOR_LIT :: GroupName TileKind
pattern FLOOR_CORRIDOR_DARK :: GroupName TileKind
pattern TRAIL_LIT :: GroupName TileKind
pattern SAFE_TRAIL_LIT :: GroupName TileKind
pattern LAB_TRAIL_LIT :: GroupName TileKind
pattern DAMP_FLOOR_LIT :: GroupName TileKind
pattern DAMP_FLOOR_DARK :: GroupName TileKind
pattern OUTDOOR_OUTER_FENCE :: GroupName TileKind
pattern DIRT_LIT :: GroupName TileKind
pattern DIRT_DARK :: GroupName TileKind
pattern FLOOR_ARENA_LIT :: GroupName TileKind
pattern FLOOR_ARENA_DARK :: GroupName TileKind
pattern EMPTY_SET_LIT :: GroupName TileKind
pattern EMPTY_SET_DARK :: GroupName TileKind
pattern NOISE_SET_LIT :: GroupName TileKind
pattern POWER_SET_LIT :: GroupName TileKind
pattern POWER_SET_DARK :: GroupName TileKind
pattern BATTLE_SET_LIT :: GroupName TileKind
pattern BATTLE_SET_DARK :: GroupName TileKind
pattern BRAWL_SET_LIT :: GroupName TileKind
pattern SHOOTOUT_SET_LIT :: GroupName TileKind
pattern ZOO_SET_LIT :: GroupName TileKind
pattern ZOO_SET_DARK :: GroupName TileKind
pattern FLIGHT_SET_LIT :: GroupName TileKind
pattern FLIGHT_SET_DARK :: GroupName TileKind
pattern AMBUSH_SET_LIT :: GroupName TileKind
pattern AMBUSH_SET_DARK :: GroupName TileKind
pattern ARENA_SET_LIT :: GroupName TileKind
pattern ARENA_SET_DARK :: GroupName TileKind
pattern RECT_WINDOWS_VERTICAL_LIT :: GroupName TileKind
pattern RECT_WINDOWS_VERTICAL_DARK :: GroupName TileKind
pattern RECT_WINDOWS_HORIZONTAL_LIT :: GroupName TileKind
pattern RECT_WINDOWS_HORIZONTAL_DARK :: GroupName TileKind
pattern TREE_SHADE_WALKABLE_LIT :: GroupName TileKind
pattern TREE_SHADE_WALKABLE_DARK :: GroupName TileKind
pattern SMOKE_CLUMP_LIT :: GroupName TileKind
pattern SMOKE_CLUMP_DARK :: GroupName TileKind
pattern GLASSHOUSE_VERTICAL_LIT :: GroupName TileKind
pattern GLASSHOUSE_VERTICAL_DARK :: GroupName TileKind
pattern GLASSHOUSE_HORIZONTAL_LIT :: GroupName TileKind
pattern GLASSHOUSE_HORIZONTAL_DARK :: GroupName TileKind
pattern BUSH_CLUMP_LIT :: GroupName TileKind
pattern BUSH_CLUMP_DARK :: GroupName TileKind
pattern FOG_CLUMP_LIT :: GroupName TileKind
pattern FOG_CLUMP_DARK :: GroupName TileKind
pattern STAIR_TERMINAL_LIT :: GroupName TileKind
pattern STAIR_TERMINAL_DARK :: GroupName TileKind
pattern CACHE :: GroupName TileKind
pattern SIGNBOARD :: GroupName TileKind
pattern STAIRCASE_UP :: GroupName TileKind
pattern ORDINARY_STAIRCASE_UP :: GroupName TileKind
pattern STAIRCASE_OUTDOOR_UP :: GroupName TileKind
pattern GATED_STAIRCASE_UP :: GroupName TileKind
pattern STAIRCASE_DOWN :: GroupName TileKind
pattern ORDINARY_STAIRCASE_DOWN :: GroupName TileKind
pattern STAIRCASE_OUTDOOR_DOWN :: GroupName TileKind
pattern GATED_STAIRCASE_DOWN :: GroupName TileKind
pattern TILE_INDOOR_ESCAPE_UP :: GroupName TileKind
pattern TILE_INDOOR_ESCAPE_DOWN :: GroupName TileKind
pattern TILE_OUTDOOR_ESCAPE_DOWN :: GroupName TileKind
pattern FLOOR_ACTOR_ITEM_LIT :: GroupName TileKind
pattern FLOOR_ACTOR_ITEM_DARK :: GroupName TileKind
pattern S_PILLAR :: GroupName TileKind
pattern S_RUBBLE_PILE :: GroupName TileKind
pattern S_LAMP_POST :: GroupName TileKind
pattern S_TREE_LIT :: GroupName TileKind
pattern S_TREE_DARK :: GroupName TileKind
pattern S_WALL_LIT :: GroupName TileKind
pattern S_WALL_DARK :: GroupName TileKind
pattern S_WALL_HORIZONTAL_LIT :: GroupName TileKind
pattern S_WALL_HORIZONTAL_DARK :: GroupName TileKind
pattern S_PULPIT :: GroupName TileKind
pattern S_BUSH_LIT :: GroupName TileKind
pattern S_FOG_LIT :: GroupName TileKind
pattern S_SMOKE_LIT :: GroupName TileKind
pattern S_FLOOR_ACTOR_LIT :: GroupName TileKind
pattern S_FLOOR_ACTOR_DARK :: GroupName TileKind
pattern S_FLOOR_ASHES_LIT :: GroupName TileKind
pattern S_FLOOR_ASHES_DARK :: GroupName TileKind
pattern S_SHADED_GROUND :: GroupName TileKind
pattern S_SHALLOW_WATER_LIT :: GroupName TileKind
pattern S_SHALLOW_WATER_DARK :: GroupName TileKind
groupNamesSingleton :: [GroupName TileKind]
groupNames :: [GroupName TileKind]
content :: [TileKind]


-- | Definitions of place kinds. Every room in the game is an instantiated
--   place kind.
module Content.PlaceKind
pattern ROGUE :: GroupName PlaceKind
pattern LABORATORY :: GroupName PlaceKind
pattern ZOO :: GroupName PlaceKind
pattern BRAWL :: GroupName PlaceKind
pattern SHOOTOUT :: GroupName PlaceKind
pattern ARENA :: GroupName PlaceKind
pattern FLIGHT :: GroupName PlaceKind
pattern AMBUSH :: GroupName PlaceKind
pattern BATTLE :: GroupName PlaceKind
pattern NOISE :: GroupName PlaceKind
pattern MINE :: GroupName PlaceKind
pattern EMPTY :: GroupName PlaceKind
pattern INDOOR_ESCAPE_DOWN :: GroupName PlaceKind
pattern INDOOR_ESCAPE_UP :: GroupName PlaceKind
pattern OUTDOOR_ESCAPE_DOWN :: GroupName PlaceKind
pattern TINY_STAIRCASE :: GroupName PlaceKind
pattern OPEN_STAIRCASE :: GroupName PlaceKind
pattern CLOSED_STAIRCASE :: GroupName PlaceKind
pattern WALLED_STAIRCASE :: GroupName PlaceKind
pattern GATED_TINY_STAIRCASE :: GroupName PlaceKind
pattern GATED_OPEN_STAIRCASE :: GroupName PlaceKind
pattern GATED_CLOSED_STAIRCASE :: GroupName PlaceKind
pattern OUTDOOR_TINY_STAIRCASE :: GroupName PlaceKind
pattern OUTDOOR_CLOSED_STAIRCASE :: GroupName PlaceKind
pattern OUTDOOR_WALLED_STAIRCASE :: GroupName PlaceKind
groupNamesSingleton :: [GroupName PlaceKind]
groupNames :: [GroupName PlaceKind]
content :: [PlaceKind]


-- | Definitions of kinds of factions present in a game, both human and
--   computer-controlled.
module Content.FactionKind
pattern EXPLORER_REPRESENTATIVE :: GroupName FactionKind
pattern EXPLORER_SHORT :: GroupName FactionKind
pattern EXPLORER_NO_ESCAPE :: GroupName FactionKind
pattern EXPLORER_MEDIUM :: GroupName FactionKind
pattern EXPLORER_TRAPPED :: GroupName FactionKind
pattern EXPLORER_AUTOMATED :: GroupName FactionKind
pattern EXPLORER_AUTOMATED_TRAPPED :: GroupName FactionKind
pattern EXPLORER_CAPTIVE :: GroupName FactionKind
pattern EXPLORER_PACIFIST :: GroupName FactionKind
pattern COMPETITOR_REPRESENTATIVE :: GroupName FactionKind
pattern COMPETITOR_SHORT :: GroupName FactionKind
pattern COMPETITOR_NO_ESCAPE :: GroupName FactionKind
pattern CIVILIAN_REPRESENTATIVE :: GroupName FactionKind
pattern CONVICT_REPRESENTATIVE :: GroupName FactionKind
pattern MONSTER_REPRESENTATIVE :: GroupName FactionKind
pattern MONSTER_ANTI :: GroupName FactionKind
pattern MONSTER_ANTI_CAPTIVE :: GroupName FactionKind
pattern MONSTER_ANTI_PACIFIST :: GroupName FactionKind
pattern MONSTER_TOURIST :: GroupName FactionKind
pattern MONSTER_TOURIST_PASSIVE :: GroupName FactionKind
pattern MONSTER_CAPTIVE :: GroupName FactionKind
pattern MONSTER_CAPTIVE_NARRATING :: GroupName FactionKind
pattern ANIMAL_REPRESENTATIVE :: GroupName FactionKind
pattern ANIMAL_MAGNIFICENT :: GroupName FactionKind
pattern ANIMAL_EXQUISITE :: GroupName FactionKind
pattern ANIMAL_CAPTIVE :: GroupName FactionKind
pattern ANIMAL_NARRATING :: GroupName FactionKind
pattern ANIMAL_MAGNIFICENT_NARRATING :: GroupName FactionKind
pattern ANIMAL_CAPTIVE_NARRATING :: GroupName FactionKind
pattern HORROR_REPRESENTATIVE :: GroupName FactionKind
pattern HORROR_CAPTIVE :: GroupName FactionKind
pattern HORROR_PACIFIST :: GroupName FactionKind
pattern REPRESENTATIVE :: GroupName FactionKind
groupNamesSingleton :: [GroupName FactionKind]
groupNames :: [GroupName FactionKind]
content :: [FactionKind]


-- | Definitions of basic items.
module Content.ItemKind
pattern HARPOON :: GroupName ItemKind
pattern EDIBLE_PLANT :: GroupName ItemKind
pattern RING_OF_OPPORTUNITY_GRENADIER :: GroupName ItemKind
pattern ARMOR_LOOSE :: GroupName ItemKind
pattern CLOTHING_MISC :: GroupName ItemKind
pattern CHIC_GEAR :: GroupName ItemKind
groupNamesSingleton :: [GroupName ItemKind]
groupNames :: [GroupName ItemKind]
content :: [ItemKind]
items :: [ItemKind]
otherItemContent :: [ItemKind]


-- | Definitions of of cave kinds. Every level in the game is an
--   instantiated cave kind.
module Content.CaveKind
pattern CAVE_ROGUE :: GroupName CaveKind
pattern CAVE_ARENA :: GroupName CaveKind
pattern CAVE_SMOKING :: GroupName CaveKind
pattern CAVE_LABORATORY :: GroupName CaveKind
pattern CAVE_NOISE :: GroupName CaveKind
pattern CAVE_MINE :: GroupName CaveKind
pattern CAVE_EMPTY :: GroupName CaveKind
pattern CAVE_SHALLOW_ROGUE :: GroupName CaveKind
pattern CAVE_OUTERMOST :: GroupName CaveKind
pattern CAVE_RAID :: GroupName CaveKind
pattern CAVE_BRAWL :: GroupName CaveKind
pattern CAVE_SHOOTOUT :: GroupName CaveKind
pattern CAVE_HUNT :: GroupName CaveKind
pattern CAVE_FLIGHT :: GroupName CaveKind
pattern CAVE_ZOO :: GroupName CaveKind
pattern CAVE_AMBUSH :: GroupName CaveKind
pattern CAVE_BATTLE :: GroupName CaveKind
pattern CAVE_SAFARI_1 :: GroupName CaveKind
pattern CAVE_SAFARI_2 :: GroupName CaveKind
pattern CAVE_SAFARI_3 :: GroupName CaveKind
groupNamesSingleton :: [GroupName CaveKind]
groupNames :: [GroupName CaveKind]
content :: [CaveKind]


-- | Definitions of game mode kinds.
module Content.ModeKind
groupNamesSingleton :: [GroupName ModeKind]
groupNames :: [GroupName ModeKind]
content :: [ModeKind]
pattern RAID :: GroupName ModeKind
pattern BRAWL :: GroupName ModeKind
pattern LONG :: GroupName ModeKind
pattern CRAWL :: GroupName ModeKind
pattern FOGGY :: GroupName ModeKind
pattern SHOOTOUT :: GroupName ModeKind
pattern PERILOUS :: GroupName ModeKind
pattern HUNT :: GroupName ModeKind
pattern NIGHT :: GroupName ModeKind
pattern FLIGHT :: GroupName ModeKind
pattern BURNING :: GroupName ModeKind
pattern ZOO :: GroupName ModeKind
pattern RANGED :: GroupName ModeKind
pattern AMBUSH :: GroupName ModeKind
pattern SAFARI :: GroupName ModeKind
pattern DIG :: GroupName ModeKind
pattern SEE :: GroupName ModeKind
pattern SHORT :: GroupName ModeKind
pattern CRAWL_EMPTY :: GroupName ModeKind
pattern CRAWL_SURVIVAL :: GroupName ModeKind
pattern SAFARI_SURVIVAL :: GroupName ModeKind
pattern BATTLE :: GroupName ModeKind
pattern BATTLE_DEFENSE :: GroupName ModeKind
pattern BATTLE_SURVIVAL :: GroupName ModeKind
pattern DEFENSE :: GroupName ModeKind
pattern DEFENSE_EMPTY :: GroupName ModeKind


-- | Here the knot of engine code pieces, frontend and the game-specific
--   content definitions is tied, resulting in an executable game.
module TieKnot

-- | Tie the LambdaHack engine client, server and frontend code with the
--   game-specific content definitions, and run the game.
--   
--   The custom monad types to be used are determined by the
--   <tt>executorSer</tt> call, which in turn calls <tt>executorCli</tt>.
--   If other functions are used in their place- the types are different
--   and so the whole pattern of computation differs. Which of the
--   frontends is run inside the UI client depends on the flags supplied
--   when compiling the engine library. Similarly for the choice of native
--   vs JS builds.
tieKnotForAsync :: ServerOptions -> IO ()

-- | Runs tieKnotForAsync in an async and applies the main thread
--   workaround.
tieKnot :: ServerOptions -> IO ()
