LambdaHack-0.6.0.0: A game engine library for roguelike dungeon crawlers

Safe HaskellNone
LanguageHaskell2010

Game.LambdaHack.Common.Frequency

Contents

Description

A list of items with relative frequencies of appearance.

Synopsis

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 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, unless they do some kind of normalization (see Dice).

Instances

Monad Frequency Source # 

Methods

(>>=) :: Frequency a -> (a -> Frequency b) -> Frequency b #

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

return :: a -> Frequency a #

fail :: String -> Frequency a #

Functor Frequency Source # 

Methods

fmap :: (a -> b) -> Frequency a -> Frequency b #

(<$) :: a -> Frequency b -> Frequency a #

Applicative Frequency Source # 

Methods

pure :: a -> Frequency a #

(<*>) :: Frequency (a -> b) -> Frequency a -> Frequency b #

(*>) :: Frequency a -> Frequency b -> Frequency b #

(<*) :: Frequency a -> Frequency b -> Frequency a #

Foldable Frequency Source # 

Methods

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

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

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

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

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

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

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

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

toList :: Frequency a -> [a] #

null :: Frequency a -> Bool #

length :: Frequency a -> Int #

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

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

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

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

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

Traversable Frequency Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Frequency a -> f (Frequency b) #

sequenceA :: Applicative f => Frequency (f a) -> f (Frequency a) #

mapM :: Monad m => (a -> m b) -> Frequency a -> m (Frequency b) #

sequence :: Monad m => Frequency (m a) -> m (Frequency a) #

Alternative Frequency Source # 

Methods

empty :: Frequency a #

(<|>) :: Frequency a -> Frequency a -> Frequency a #

some :: Frequency a -> Frequency [a] #

many :: Frequency a -> Frequency [a] #

MonadPlus Frequency Source # 

Methods

mzero :: Frequency a #

mplus :: Frequency a -> Frequency a -> Frequency a #

Eq a => Eq (Frequency a) Source # 

Methods

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

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

Ord a => Ord (Frequency a) Source # 
Show a => Show (Frequency a) Source # 
Generic (Frequency a) Source # 

Associated Types

type Rep (Frequency a) :: * -> * #

Methods

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

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

Binary a => Binary (Frequency a) Source # 

Methods

put :: Frequency a -> Put #

get :: Get (Frequency a) #

putList :: [Frequency a] -> Put #

NFData a => NFData (Frequency a) Source # 

Methods

rnf :: Frequency a -> () #

Hashable a => Hashable (Frequency a) Source # 

Methods

hashWithSalt :: Int -> Frequency a -> Int #

hash :: Frequency a -> Int #

type Rep (Frequency a) Source # 
type Rep (Frequency a) = D1 (MetaData "Frequency" "Game.LambdaHack.Common.Frequency" "LambdaHack-0.6.0.0-KKqNxYnoEMa5Wo2qfudFog" False) (C1 (MetaCons "Frequency" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "runFrequency") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [(Int, a)])) (S1 (MetaSel (Just Symbol "nameFrequency") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (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.

Transformation

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

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

renameFreq :: Text -> Frequency a -> Frequency a Source #

Change the description of the frequency.

setFreq :: Eq a => Frequency a -> a -> Int -> Frequency a Source #

Set frequency of an element.

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.; keep it lazy, because it's rarely used

meanFreq :: Frequency Int -> Int Source #

Average value of an Int distribution, rounded up to avoid truncating it in the other code higher up, which would equate 1d0 with 1d1.