stream-timers-0.1.0.0: Some stream timers, and experiments with them

Safe HaskellNone
LanguageHaskell2010

Data.Timers.Example

Synopsis

Documentation

data Map k a :: * -> * -> * #

A Map from keys k to values a.

Instances

Eq2 Map 

Methods

liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> Map a c -> Map b d -> Bool #

Ord2 Map 

Methods

liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> Map a c -> Map b d -> Ordering #

Show2 Map 

Methods

liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Map a b -> ShowS #

liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Map a b] -> ShowS #

Functor (Map k) 

Methods

fmap :: (a -> b) -> Map k a -> Map k b #

(<$) :: a -> Map k b -> Map k a #

Foldable (Map k) 

Methods

fold :: Monoid m => Map k m -> m #

foldMap :: Monoid m => (a -> m) -> Map k a -> m #

foldr :: (a -> b -> b) -> b -> Map k a -> b #

foldr' :: (a -> b -> b) -> b -> Map k a -> b #

foldl :: (b -> a -> b) -> b -> Map k a -> b #

foldl' :: (b -> a -> b) -> b -> Map k a -> b #

foldr1 :: (a -> a -> a) -> Map k a -> a #

foldl1 :: (a -> a -> a) -> Map k a -> a #

toList :: Map k a -> [a] #

null :: Map k a -> Bool #

length :: Map k a -> Int #

elem :: Eq a => a -> Map k a -> Bool #

maximum :: Ord a => Map k a -> a #

minimum :: Ord a => Map k a -> a #

sum :: Num a => Map k a -> a #

product :: Num a => Map k a -> a #

Traversable (Map k) 

Methods

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

sequenceA :: Applicative f => Map k (f a) -> f (Map k a) #

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

sequence :: Monad m => Map k (m a) -> m (Map k a) #

Eq k => Eq1 (Map k) 

Methods

liftEq :: (a -> b -> Bool) -> Map k a -> Map k b -> Bool #

Ord k => Ord1 (Map k) 

Methods

liftCompare :: (a -> b -> Ordering) -> Map k a -> Map k b -> Ordering #

(Ord k, Read k) => Read1 (Map k) 

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Map k a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Map k a] #

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Map k a) #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Map k a] #

Show k => Show1 (Map k) 

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Map k a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Map k a] -> ShowS #

Ord k => IsList (Map k v) 

Associated Types

type Item (Map k v) :: * #

Methods

fromList :: [Item (Map k v)] -> Map k v #

fromListN :: Int -> [Item (Map k v)] -> Map k v #

toList :: Map k v -> [Item (Map k v)] #

(Eq k, Eq a) => Eq (Map k a) 

Methods

(==) :: Map k a -> Map k a -> Bool #

(/=) :: Map k a -> Map k a -> Bool #

(Data k, Data a, Ord k) => Data (Map k a) 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Map k a -> c (Map k a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Map k a) #

toConstr :: Map k a -> Constr #

dataTypeOf :: Map k a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Map k a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k a)) #

gmapT :: (forall b. Data b => b -> b) -> Map k a -> Map k a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Map k a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Map k a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Map k a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Map k a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Map k a -> m (Map k a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Map k a -> m (Map k a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Map k a -> m (Map k a) #

(Ord k, Ord v) => Ord (Map k v) 

Methods

compare :: Map k v -> Map k v -> Ordering #

(<) :: Map k v -> Map k v -> Bool #

(<=) :: Map k v -> Map k v -> Bool #

(>) :: Map k v -> Map k v -> Bool #

(>=) :: Map k v -> Map k v -> Bool #

max :: Map k v -> Map k v -> Map k v #

min :: Map k v -> Map k v -> Map k v #

(Ord k, Read k, Read e) => Read (Map k e) 

Methods

readsPrec :: Int -> ReadS (Map k e) #

readList :: ReadS [Map k e] #

readPrec :: ReadPrec (Map k e) #

readListPrec :: ReadPrec [Map k e] #

(Show k, Show a) => Show (Map k a) 

Methods

showsPrec :: Int -> Map k a -> ShowS #

show :: Map k a -> String #

showList :: [Map k a] -> ShowS #

Ord k => Semigroup (Map k v) 

Methods

(<>) :: Map k v -> Map k v -> Map k v #

sconcat :: NonEmpty (Map k v) -> Map k v #

stimes :: Integral b => b -> Map k v -> Map k v #

Ord k => Monoid (Map k v) 

Methods

mempty :: Map k v #

mappend :: Map k v -> Map k v -> Map k v #

mconcat :: [Map k v] -> Map k v #

(NFData k, NFData a) => NFData (Map k a) 

Methods

rnf :: Map k a -> () #

type Item (Map k v) 
type Item (Map k v) = (k, v)

gapless :: (Bits t, Num t) => t -> Bool Source #

Mystery function... (read the source)

gapless' :: (Bits t, Num t) => t -> Bool Source #

Helper function to gapless

gaplessEq :: (Bits a, Num a) => a -> Bool Source #

Are gapless and gapless' equal?

countGapless :: (Bits a, Enum a, Num a, Num b) => a -> b Source #

Number of gapless numbers in [1..n]

countGapless' :: (Bits a, Enum a, Num a, Num b) => a -> b Source #

Number of gapless' numbers in [1..n]

nextGapless :: (Bits a, Num a) => a -> a Source #

What it says on the box

toMathematica :: Show a => [[a]] -> String Source #

Convert a list of lists to a list of Mathematica lists.

onlyGapless :: (Bits t, Num t) => [t] -> [t] Source #

One-liner to export gapless to mathematica:

 concatMap (x->concat["{",show(head x),",",show(length x),"},"]).group . (x->zipWith(-)(tail x)x) . onlyGapless $ [1..100]

See only_gapless.md

onlyGaplessMathematica :: (Bits t, Num t, Show t) => [t] -> String Source #

onlyGapless, differences, grouped, then converted to Mathematica lists. {--}

differences :: Num a => [a] -> [a] Source #

First differences:

 [x0, x1, x2, x3..] -> [x1 - x0, x2 - x1, x3 - x2..]

differences_ :: Num a => [a] -> [a] Source #

Should be equivalent to differences

prop_differences_ :: [Int] -> Bool Source #

Compare differences and differences_, specialized for testing

getRuns :: (Num a, Num b, Eq a) => [a] -> [b] Source #

Warning, this function is incomplete.

λ> take 10 . getRuns . repeat $ 0 == _|_
λ> take 10 . getRuns . repeat $ 1 == _|_
λ> take 10 . getRuns . cycle $ [0] == _|_
λ> take 10 . getRuns . cycle $ [1] == _|_
λ> take 10 . getRuns . cycle $ [0,0] == _|_
λ> take 10 . getRuns . cycle $ [0,1] == [1,1,1,1,1,1,1,1,1,1]
λ> take 10 . getRuns . cycle $ [1,0] == [1,1,1,1,1,1,1,1,1,1]
λ> take 10 . getRuns . cycle $ [1,1] == _|_
λ> take 10 . getRuns . cycle $ [0,0,0] == _|_
λ> take 10 . getRuns . cycle $ [0,0,1] == [2,2,2,2,2,2,2,2,2,2]
λ> take 10 . getRuns . cycle $ [0,1,0] == [1,2,2,2,2,2,2,2,2,2]
λ> take 10 . getRuns . cycle $ [0,1,1] == [1,1,1,1,1,1,1,1,1,1]
λ> take 10 . getRuns . cycle $ [1,0,0] == [2,2,2,2,2,2,2,2,2,2]
λ> take 10 . getRuns . cycle $ [1,0,1] == [1,1,1,1,1,1,1,1,1,1]
λ> take 10 . getRuns . cycle $ [1,1,0] == [1,1,1,1,1,1,1,1,1,1]
λ> take 10 . getRuns . cycle $ [1,1,1]

It's a fun autamata, note that it must be passed an infinite list, or else it'll hit an exception. Even then, on some infinite lists, it'll loop forever without printing (if it never hits 1's).

getRunsA :: (Num a, Num b, Eq a) => [a] -> [b] Source #

A "match [] first" version of getRuns

getRunsB :: (Num a, Num b, Eq a) => [a] -> [b] Source #

A "match [] last" version of getRuns

getRuns' :: (Num a, Num b, Eq a) => b -> [a] -> [b] Source #

Warning, this function is incomplete.

getRuns'A :: (Num a, Num b, Eq a) => b -> [a] -> [b] Source #

A "match [] first" version of getRuns'

getRuns'B :: (Num a, Num b, Eq a) => b -> [a] -> [b] Source #

A "match [] last" version of getRuns'

addPosition Source #

Arguments

:: (Ord k0, Eq a, Num a) 
=> (a, k0)

(position, value)

-> Map k0 ((a, a, a, a, a), [(a, a, a, a, a)])

Map Value (last input position, list of its previous runs)

-> Map k0 ((a, a, a, a, a), [(a, a, a, a, a)])

Map Value (new input position, list of its previous runs)

Add a position to the Map

type Vec2 = ContVec 2 Source #

Abbrev. to make it easier to make the code generic

type Vec4 = ContVec 4 Source #

Abbrev. to make it easier to make the code generic

type Vec5 = ContVec 5 Source #

Abbrev. to make it easier to make the code generic

addPosition' :: (Ord k0, Eq a, Num a) => a -> k0 -> Map k0 (Vec5 a, [Vec5 a]) -> Map k0 (Vec5 a, [Vec5 a]) Source #

A version of addPosition using Vec5 instead of tuples

theStream :: (Enum a, Enum b, Num b, Bits b, Num a) => ([(a, b)], Map k v) Source #

The initial state of the stream

printMap :: (Show b, Show c) => (a1, Map b (a, [(c, c, c, c, c)])) -> IO () Source #

Print the resulting Map

printMap' :: (Show a0, Show a2) => (a, Map a0 (a1, [Vec5 a2])) -> IO () Source #

Print the resulting Map, specialized to Vec5's instead of tuples

printEveryNOfStream :: (Eq a, Bits k0, Num k0, Num a, Enum k0, Enum a, Ord k0, Show k0, Show a) => Int -> IO ([(a, k0)], Map k0 ((a, a, a, a, a), [(a, a, a, a, a)])) Source #

Print every nth value of the stream, specialized to the following value (it's an infinite loop, so the return value simply encodes which types the algorithm is specialized to).

printEveryNOfStream' :: (Eq a, Bits k0, Num k0, Num a, Enum k0, Enum a, Ord k0, Show (ContVec 5 a), Show k0, Show a) => Int -> IO ([(a, k0)], Map k0 (Vec5 a, [Vec5 a])) Source #

printEveryNOfStream, secialized to ContVec's and using addPosition'

returnEveryN Source #

Arguments

:: (Eq c, Show b, Show c, Ord b, Enum c, Enum b, Num c, Num b, Bits b) 
=> Int

How often

-> IO ([(c, b)], Map b ((c, c, c, c, c), [(c, c, c, c, c)]))

Results from theStream

See printEveryNOfStream, except is uses sideEffectEveryN instead of printEveryN

returnEveryN' Source #

Arguments

:: (Eq a2, Enum a2, Num a2, Bits a1, Enum a1, Num a1, Ord a1, Show a2, Show a1) 
=> Int

How often

-> IO ([(a2, a1)], Map a1 (Vec5 a2, [ContVec 5 a2]))

Results from theStream

A version of returnEveryN using addPosition' and printMap'