combinat-0.2.10.0: Generate and manipulate various combinatorial objects.
Safe HaskellNone
LanguageHaskell2010

Math.Combinat.Helper

Description

Miscellaneous helper functions used internally

Synopsis

debugging

debug :: Show a => a -> b -> b Source #

pairs

swap :: (a, b) -> (b, a) Source #

pairs :: [a] -> [(a, a)] Source #

pairsWith :: (a -> a -> b) -> [a] -> [b] Source #

lists

sum' :: Num a => [a] -> a Source #

interleave :: [a] -> [a] -> [a] Source #

evens :: [a] -> [a] Source #

odds :: [a] -> [a] Source #

multiplication

productInterleaved :: [Integer] -> Integer Source #

Product of list of integers, but in interleaved order (for a list of big numbers, it should be faster than the linear order)

productFromTo :: Integral a => a -> a -> Integer Source #

Faster implementation of product [ i | i <- [a+1..b] ]

productFromToStride2 :: Integral a => a -> a -> Integer Source #

Faster implementation of product [ i | i <- [a+1,a+3,..b] ]

equality and ordering

equating :: Eq b => (a -> b) -> a -> a -> Bool Source #

reverseComparing :: Ord b => (a -> b) -> a -> a -> Ordering Source #

reverseCompare :: Ord a => a -> a -> Ordering Source #

reverseSort :: Ord a => [a] -> [a] Source #

groupSortBy :: (Eq b, Ord b) => (a -> b) -> [a] -> [[a]] Source #

nubOrd :: Ord a => [a] -> [a] Source #

increasing / decreasing sequences

first / last

mapWithLast :: (Bool -> a -> b) -> [a] -> [b] Source #

The boolean argument will True only for the last element

mapWithFirst :: (Bool -> a -> b) -> [a] -> [b] Source #

mapWithFirstLast :: (Bool -> Bool -> a -> b) -> [a] -> [b] Source #

older helpers for ASCII drawing

mkLinesUniformWidth :: [String] -> [String] Source #

extend lines with spaces so that they have the same line

counting

count :: Eq a => a -> [a] -> Int Source #

histogram :: (Eq a, Ord a) => [a] -> [(a, Int)] Source #

maybe

bool

iteration

nest :: Int -> (a -> a) -> a -> a Source #

unfold1 :: (a -> Maybe a) -> a -> [a] Source #

unfold :: (b -> (a, Maybe b)) -> b -> [a] Source #

unfoldEither :: (b -> Either c (b, a)) -> b -> (c, [a]) Source #

unfoldM :: Monad m => (b -> m (a, Maybe b)) -> b -> m [a] Source #

mapAccumM :: Monad m => (acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y]) Source #

long zipwith

longZipWith :: a -> b -> (a -> b -> c) -> [a] -> [b] -> [c] Source #

random

type Rand g = RandT g Identity Source #

A simple random monad to make life suck less

runRand :: Rand g a -> g -> (a, g) Source #

flipRunRand :: Rand s a -> s -> (s, a) Source #

newtype RandT g m a Source #

The Rand monad transformer

Constructors

RandT (StateT g m a) 

Instances

Instances details
Monad m => Monad (RandT g m) Source # 
Instance details

Defined in Math.Combinat.Helper

Methods

(>>=) :: RandT g m a -> (a -> RandT g m b) -> RandT g m b #

(>>) :: RandT g m a -> RandT g m b -> RandT g m b #

return :: a -> RandT g m a #

Functor m => Functor (RandT g m) Source # 
Instance details

Defined in Math.Combinat.Helper

Methods

fmap :: (a -> b) -> RandT g m a -> RandT g m b #

(<$) :: a -> RandT g m b -> RandT g m a #

Monad m => Applicative (RandT g m) Source # 
Instance details

Defined in Math.Combinat.Helper

Methods

pure :: a -> RandT g m a #

(<*>) :: RandT g m (a -> b) -> RandT g m a -> RandT g m b #

liftA2 :: (a -> b -> c) -> RandT g m a -> RandT g m b -> RandT g m c #

(*>) :: RandT g m a -> RandT g m b -> RandT g m b #

(<*) :: RandT g m a -> RandT g m b -> RandT g m a #

runRandT :: RandT g m a -> g -> m (a, g) Source #

flipRunRandT :: Monad m => RandT s m a -> s -> m (s, a) Source #

This may be occasionally useful

rand :: (g -> (a, g)) -> Rand g a Source #

Puts a standard-conforming random function into the monad

randChoose :: (RandomGen g, Random a) => (a, a) -> Rand g a Source #

randProxy1 :: Rand g (f n) -> Proxy n -> Rand g (f n) Source #