LambdaHack-0.11.0.1: A game engine library for tactical squad ASCII roguelike dungeon crawlers

Safe Haskell | None
Language | Haskell2010

Game.LambdaHack.Core.Frequency

Contents

- The `Frequency` type
- Construction
- Transformation
- Consumption

Description

A list of entities with relative frequencies of appearance.

Synopsis

- data Frequency a
- uniformFreq :: Text -> [a] -> Frequency a
- toFreq :: Text -> [(Int, a)] -> Frequency a
- maxBoundInt32 :: Int
- scaleFreq :: Show a => Int -> Frequency a -> Frequency a
- nullFreq :: Frequency a -> Bool
- runFrequency :: Frequency a -> [(Int, a)]
- nameFrequency :: Frequency a -> Text

# The `Frequency` type

data Frequency a Source #

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 `Eq` instance compares raw representations, not relative, normalized frequencies, so operations don't need to preserve the expected equalities.

#### Instances

Instances details

Alternative Frequency Source # |
Instance details Defined in Game.LambdaHack.Core.Frequency Methods empty :: Frequency a Source # (<|>) :: Frequency a -> Frequency a -> Frequency a Source # some :: Frequency a -> Frequency [a] Source # many :: Frequency a -> Frequency [a] Source #
Applicative Frequency Source # |
Instance details Defined in Game.LambdaHack.Core.Frequency Methods pure :: a -> Frequency a Source # (<*>) :: Frequency (a -> b) -> Frequency a -> Frequency b Source # liftA2 :: (a -> b -> c) -> Frequency a -> Frequency b -> Frequency c Source # (*>) :: Frequency a -> Frequency b -> Frequency b Source # (<*) :: Frequency a -> Frequency b -> Frequency a Source #
Functor Frequency Source # |
Instance details Defined in Game.LambdaHack.Core.Frequency Methods fmap :: (a -> b) -> Frequency a -> Frequency b Source # (<$) :: a -> Frequency b -> Frequency a Source #
Monad Frequency Source # |
Instance details Defined in Game.LambdaHack.Core.Frequency Methods (>>=) :: Frequency a -> (a -> Frequency b) -> Frequency b Source # (>>) :: Frequency a -> Frequency b -> Frequency b Source # return :: a -> Frequency a Source #
MonadPlus Frequency Source # |
Instance details Defined in Game.LambdaHack.Core.Frequency Methods mzero :: Frequency a Source # mplus :: Frequency a -> Frequency a -> Frequency a Source #
Foldable Frequency Source # |

Instance details

Defined in Game.LambdaHack.Core.Frequency

Methods

fold :: Monoid m => Frequency m -> m Source #

foldMap :: Monoid m => (a -> m) -> Frequency a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Frequency a -> m Source #

foldr :: (a -> b -> b) -> b -> Frequency a -> b Source #

foldr' :: (a -> b -> b) -> b -> Frequency a -> b Source #

foldl :: (b -> a -> b) -> b -> Frequency a -> b Source #

foldl' :: (b -> a -> b) -> b -> Frequency a -> b Source #

foldr1 :: (a -> a -> a) -> Frequency a -> a Source #

foldl1 :: (a -> a -> a) -> Frequency a -> a Source #

toList :: Frequency a -> [a] Source #

null :: Frequency a -> Bool Source #

length :: Frequency a -> Int Source #

elem :: Eq a => a -> Frequency a -> Bool Source #

maximum :: Ord a => Frequency a -> a Source #

minimum :: Ord a => Frequency a -> a Source #

sum :: Num a => Frequency a -> a Source #

product :: Num a => Frequency a -> a Source #

Traversable Frequency Source # |
Instance details Defined in Game.LambdaHack.Core.Frequency Methods traverse :: Applicative f => (a -> f b) -> Frequency a -> f (Frequency b) Source # sequenceA :: Applicative f => Frequency (f a) -> f (Frequency a) Source # mapM :: Monad m => (a -> m b) -> Frequency a -> m (Frequency b) Source # sequence :: Monad m => Frequency (m a) -> m (Frequency a) Source #
Generic (Frequency a) Source # |

Instance details

Defined in Game.LambdaHack.Core.Frequency

Associated Types

type Rep (Frequency a) |

Instance details

Defined in Game.LambdaHack.Core.Frequency

type Rep (Frequency a) = D1 ('MetaData "Frequency" "Game.LambdaHack.Core.Frequency" "LambdaHack-0.11.0.1-BLuOaw8nuizISmzkanqI8h" 'False) (C1 ('MetaCons "Frequency" 'PrefixI 'True) (S1 ('MetaSel ('Just "runFrequency") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [(Int, a)]) :*: S1 ('MetaSel ('Just "nameFrequency") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text)))

Methods

from :: Frequency a -> Rep (Frequency a) x Source #

to :: Rep (Frequency a) x -> Frequency a Source #

Show a => Show (Frequency a) Source # |
Instance details Defined in Game.LambdaHack.Core.Frequency Methods showsPrec :: Int -> Frequency a -> ShowS Source # show :: Frequency a -> String Source # showList :: [Frequency a] -> ShowS Source #
Eq a => Eq (Frequency a) Source # |
Instance details Defined in Game.LambdaHack.Core.Frequency Methods (==) :: Frequency a -> Frequency a -> Bool Source # (/=) :: Frequency a -> Frequency a -> Bool Source #
Ord a => Ord (Frequency a) Source # |

Instance details

Defined in Game.LambdaHack.Core.Frequency

Methods

compare :: Frequency a -> Frequency a -> Ordering Source #

(<) :: Frequency a -> Frequency a -> Bool Source #

(<=) :: Frequency a -> Frequency a -> Bool Source #

(>) :: Frequency a -> Frequency a -> Bool Source #

(>=) :: Frequency a -> Frequency a -> Bool Source #

max :: Frequency a -> Frequency a -> Frequency a Source #

min :: Frequency a -> Frequency a -> Frequency a Source #

type Rep (Frequency a) Source # |

Instance details

Defined in Game.LambdaHack.Core.Frequency

type Rep (Frequency a) = D1 ('MetaData "Frequency" "Game.LambdaHack.Core.Frequency" "LambdaHack-0.11.0.1-BLuOaw8nuizISmzkanqI8h" 'False) (C1 ('MetaCons "Frequency" 'PrefixI 'True) (S1 ('MetaSel ('Just "runFrequency") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [(Int, a)]) :*: S1 ('MetaSel ('Just "nameFrequency") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text)))

# Construction

uniformFreq :: Text -> [a] -> Frequency a Source #

Uniform discrete frequency distribution.

toFreq :: Text -> [(Int, a)] -> Frequency a Source #

Takes a name and a list of frequencies and items into the frequency distribution.

maxBoundInt32 :: Int Source #

# Transformation

scaleFreq :: Show a => Int -> Frequency a -> Frequency a Source #

Scale frequency distribution, multiplying it by a positive integer constant.

# Consumption

nullFreq :: Frequency a -> Bool Source #

Test if the frequency distribution is empty.

runFrequency :: Frequency a -> [(Int, a)] Source #

give acces to raw frequency values

nameFrequency :: Frequency a -> Text Source #

short description for debug, etc.