| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Timers.Example
- data Map k a :: * -> * -> *
- gapless :: (Bits t, Num t) => t -> Bool
- gapless' :: (Bits t, Num t) => t -> Bool
- gaplessEq :: (Bits a, Num a) => a -> Bool
- countGapless :: (Bits a, Enum a, Num a, Num b) => a -> b
- countGapless' :: (Bits a, Enum a, Num a, Num b) => a -> b
- nextGapless :: (Bits a, Num a) => a -> a
- toMathematica :: Show a => [[a]] -> String
- onlyGapless :: (Bits t, Num t) => [t] -> [t]
- onlyGaplessMathematica :: (Bits t, Num t, Show t) => [t] -> String
- differences :: Num a => [a] -> [a]
- differences_ :: Num a => [a] -> [a]
- prop_differences_ :: [Int] -> Bool
- getRuns :: (Num a, Num b, Eq a) => [a] -> [b]
- getRunsA :: (Num a, Num b, Eq a) => [a] -> [b]
- getRunsB :: (Num a, Num b, Eq a) => [a] -> [b]
- getRuns' :: (Num a, Num b, Eq a) => b -> [a] -> [b]
- getRuns'A :: (Num a, Num b, Eq a) => b -> [a] -> [b]
- getRuns'B :: (Num a, Num b, Eq a) => b -> [a] -> [b]
- addPosition :: (Ord k0, Eq a, Num a) => (a, k0) -> Map k0 ((a, a, a, a, a), [(a, a, a, a, a)]) -> Map k0 ((a, a, a, a, a), [(a, a, a, a, a)])
- type Vec2 = ContVec 2
- type Vec4 = ContVec 4
- type Vec5 = ContVec 5
- addPosition' :: (Ord k0, Eq a, Num a) => a -> k0 -> Map k0 (Vec5 a, [Vec5 a]) -> Map k0 (Vec5 a, [Vec5 a])
- theStream :: (Enum a, Enum b, Num b, Bits b, Num a) => ([(a, b)], Map k v)
- printMap :: (Show b, Show c) => (a1, Map b (a, [(c, c, c, c, c)])) -> IO ()
- printMap' :: (Show a0, Show a2) => (a, Map a0 (a1, [Vec5 a2])) -> IO ()
- 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)]))
- 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]))
- returnEveryN :: (Eq c, Show b, Show c, Ord b, Enum c, Enum b, Num c, Num b, Bits b) => Int -> IO ([(c, b)], Map b ((c, c, c, c, c), [(c, c, c, c, c)]))
- returnEveryN' :: (Eq a2, Enum a2, Num a2, Bits a1, Enum a1, Num a1, Ord a1, Show a2, Show a1) => Int -> IO ([(a2, a1)], Map a1 (Vec5 a2, [ContVec 5 a2]))
Documentation
A Map from keys k to values a.
Instances
| Eq2 Map | |
| Ord2 Map | |
| Show2 Map | |
| Functor (Map k) | |
| Foldable (Map k) | |
| Traversable (Map k) | |
| Eq k => Eq1 (Map k) | |
| Ord k => Ord1 (Map k) | |
| (Ord k, Read k) => Read1 (Map k) | |
| Show k => Show1 (Map k) | |
| Ord k => IsList (Map k v) | |
| (Eq k, Eq a) => Eq (Map k a) | |
| (Data k, Data a, Ord k) => Data (Map k a) | |
| (Ord k, Ord v) => Ord (Map k v) | |
| (Ord k, Read k, Read e) => Read (Map k e) | |
| (Show k, Show a) => Show (Map k a) | |
| Ord k => Semigroup (Map k v) | |
| Ord k => Monoid (Map k v) | |
| (NFData k, NFData a) => NFData (Map k a) | |
| type Item (Map k v) | |
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).
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
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
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'