My module for streams

- data S v = Cons v (S v)
- (<||) :: a -> S a -> S a
- (<<|) :: [a] -> S a -> S a
- (|~|) :: S a -> S a -> S a
- ago :: Integer -> S a -> a
- anyA :: S a
- z0 :: Num a => S a
- asum :: Num a => S a -> S a
- bsum :: Num a => S a -> S a
- csum :: Num a => S a -> S a
- diff :: Num a => S a -> S a
- inv :: Num a => S a -> S a
- sconst :: Num a => a -> S a
- times :: Num a => a -> S a -> S a
- plus :: Num a => S a -> S a -> S a
- interleave :: S a -> S a -> S a
- interleave' :: S a -> S a -> S a
- alternate :: S a -> S a -> S a
- combStreams :: [[a]] -> [[a]]
- drop0L :: S a -> S a
- dropIp1L :: S a -> S a
- dup :: S a -> S a
- (|!|) :: Ord a => S a -> S a -> S a
- merge :: Ord a => S a -> S a -> S a
- union :: Ord a => S a -> S a -> S a
- allEqual :: Eq a => [a] -> Bool
- group :: Eq a => S a -> S [a]
- fix :: (a -> a) -> a
- inits :: S a -> S [a]
- interleave3 :: S a -> S a -> S a
- intersperse :: a -> S a -> S a
- map1 :: (a -> b) -> S a -> S b
- mapAdjacent :: (a -> a -> b) -> [a] -> [b]
- turn :: Integral a => a -> [a]
- type G v o = [v] -> o
- fromFG :: G a a -> S a
- revFix :: G a a -> S a
- rgen :: G a b -> S a -> S b
- fwdFix :: G a a -> S a
- grow :: G a b -> S a -> S b
- hOfFG :: G a b -> b
- tOfFG :: G a b -> a -> G a b
- rep :: (S a -> S b) -> G a b
- rgen' :: G a b -> [a] -> S a -> S b
- hOfRG :: (G a b, [a]) -> b
- tOfRG :: (G a b, [a]) -> a -> (G a b, [a])
- fromRG :: (G a a, [a]) -> S a
- toT :: G a b -> Tree a b
- toG :: Tree a b -> G a b
- data Tree a o = Node o (a -> Tree a o)
- branches :: Tree a b -> a -> Tree a b
- fromT :: Tree a a -> S a
- label :: Tree a b -> b
- type Coalg c a b = (c -> b, c -> a -> c)
- unfold :: Coalg c a b -> c -> Tree a b
- cfix :: Coalg c a a -> c -> S a
- groW :: Coalg c a b -> c -> S a -> S b
- sMap :: (a -> b) -> S a -> S b
- sMap2 :: (a -> b -> c) -> S a -> S b -> S c
- sMap3 :: (a -> b -> c -> d) -> S a -> S b -> S c -> S d
- sMap4 :: (a -> b -> c -> d -> e) -> S a -> S b -> S c -> S d -> S e
- sEven :: S a -> S a
- seven :: S a -> S a
- sOdd :: S a -> S a
- sodd :: S a -> S a
- sbreak :: (a -> Bool) -> S a -> ([a], S a)
- sdropWhile :: (a -> Bool) -> S a -> S a
- stakeWhile :: (a -> Bool) -> S a -> [a]
- sfilter :: (a -> Bool) -> S a -> S a
- spartition :: (a -> Bool) -> S a -> (S a, S a)
- sspan :: (a -> Bool) -> S a -> ([a], S a)
- scan :: (a -> b -> a) -> a -> S b -> S a
- scan' :: (a -> b -> a) -> a -> S b -> S a
- scan1 :: (a -> a -> a) -> S a -> S a
- scan1' :: (a -> a -> a) -> S a -> S a
- scycle :: [a] -> S a
- siterate :: (a -> a) -> a -> S a
- shead :: S a -> a
- stail :: S a -> S a
- tail2 :: S a -> S a
- tails :: S a -> S (S a)
- stake :: Integer -> S a -> [a]
- sdrop :: Int -> S a -> S a
- ssplitAt :: Int -> S a -> ([a], S a)
- smerge :: S a -> S a -> S a
- sunzip :: S (a, b) -> (S a, S b)
- szipWith :: (a -> b -> c) -> S a -> S b -> S c
- transpose :: S (S a) -> S (S a)
- fromJust :: Maybe a -> a
- fromOEIS :: String -> [Integer]
- main :: IO ()

# Streams

Your standard *Streams*, renamed to `S`

because `S`

looks like a meandering
stream.

Monad S | |

Functor S | |

Idiom S | |

Enum a => Enum (S a) | |

Eq v => Eq (S v) | |

Fractional a => Fractional (S a) | |

Integral a => Integral (S a) | |

Num a => Num (S a) | |

Ord v => Ord (S v) | |

Read v => Read (S v) | |

Real a => Real (S a) | |

Show v => Show (S v) | |

Arbitrary a => Arbitrary (S a) | |

CoArbitrary a => CoArbitrary (S a) | |

Serial a => Serial (S a) |

## Cons 1, n:

interleave :: S a -> S a -> S aSource

interleave' :: S a -> S a -> S aSource

combStreams :: [[a]] -> [[a]]Source

## (Improperly) using `Ord`

## (Improperly) using `Eq`

interleave3 :: S a -> S a -> S aSource

intersperse :: a -> S a -> S aSource

mapAdjacent :: (a -> a -> b) -> [a] -> [b]Source

`G`

enerating Functions

A generating function for Streams.

## Generating Functions, etc

## Gen to Tree:

## Tree to Gen:

# Infinite `Tree`

s

## Trees

# Coalgebras

## Coalgebraic

## Using `Bool`

Predicates

sdropWhile :: (a -> Bool) -> S a -> S aSource

stakeWhile :: (a -> Bool) -> S a -> [a]Source

## Drivers

## Heads and Tails

## Indexed

## Zips and Unzips

## Utility Functions

unzip, specialized to Stream tuples

`filter`

`p`

`xs`

, removes any elements from `xs`

that do not satisfy `p`

.

*Beware*: this function may diverge if there is no element of
`xs`

that satisfies `p`

, e.g. `filter odd (repeat 0)`

will loop.

`takeWhile`

`p`

`xs`

returns the longest prefix of the stream
`xs`

for which the predicate `p`

holds.

`dropWhile`

`p`

`xs`

returns the suffix remaining after
`takeWhile`

`p`

`xs`

.

*Beware*: this function may diverge if every element of `xs`

satisfies `p`

, e.g. `dropWhile even (repeat 0)`

will loop.

`sspan`

`p`

`xs`

returns the longest prefix of `xs`

that satisfies
`p`

, together with the remainder of the stream.

The `break`

`p`

function is equivalent to `span`

`not . p`

.

The `splitAt`

function takes an integer `n`

and a stream `xs`

and returns a pair consisting of the prefix of `xs`

of length
`n`

and the remaining stream immediately following this prefix.

*Beware*: passing a negative integer as the first argument will
cause an error.

The `partition`

function takes a predicate `p`

and a stream
`xs`

, and returns a pair of streams. The first stream corresponds
to the elements of `xs`

for which `p`

holds; the second stream
corresponds to the elements of `xs`

for which `p`

does not hold.

*Beware*: One of the elements of the tuple may be undefined. For
example, `fst (partition even (repeat 0)) == repeat 0`

; on the
other hand `snd (partition even (repeat 0))`

is undefined.

The `group`

function takes a stream and returns a stream of
lists such that flattening the resulting stream is equal to the
argument. Moreover, each sublist in the resulting stream
contains only equal elements. For example,

`drop`

`n`

`xs`

drops the first `n`

elements off the front of
the sequence `xs`

.

*Beware*: passing a negative integer as the first argument will
cause an error.

The `stails`

function takes a stream `xs`

and returns all the
suffixes of `xs`

.

merge, version 2 [Hinze UFP p.35]

map, version 1 | map, version 2 | map2, really zip?

from Unique Fixed Point p.35

union for streams

Interleave two Streams `xs`

and `ys`

, alternating elements
from each list.

[x1,x2,...] `interleave` [y1,y2,...] == [x1,y1,x2,y2,...]

`intersperse`

`y`

`xs`

creates an alternating stream of
elements from `xs`

and `y`

.

infix prepend

turn something

`cycle`

`xs`

returns the infinite repetition of `xs`

:

cycle [1,2,3] = Cons 1 (Cons 2 (Cons 3 (Cons 1 (Cons 2 ...

Arithmatic, Jumping, ...

multiplication | stream inversion | finite (forward) difference | duplicate the head of the stream | even (indexed) elements | odd (indexed) elements | even (indexed) elements, v2 | odd (indexed) elements, v2 | drop function, results in (4*n - 1) | drop function, results in (2*n) | an alternative tail function

a kind of sum function | right inverse of diff

from Hinze UFP p.45

from Hinze UFP p.49

from Hinze UFP p.4

iterate (inductively) over a stream

this can't be stopped?

from Hinze UFP p.39

from Hinze UFP p.41

2D operator?

from Hinze UFP p.45

from Hinze UFP p.45

mutually recursive

from Hinze UFP p.45

from Hinze UFP p.45

scan f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]

`scan'`

is a strict scan.

`scan1`

is a variant of `scan`

that has no starting value argument:

scan1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]

`scan1'`

is a strict scan that has no starting value.

`transpose`

computes the transposition of a stream of streams.

from Hinze UFP p.45

from Hinze UFP p.45

standard fix-point function | standard fix-point function, specialized to Streams (forward ordering) | standard fix-point function, specialized to Streams (reverse ordering)

transform a generator to a Stream operator | transform a generator to a Stream operator - v2? | transform a Stream operator to a generator | transform a generator, along with a reversed list, into a Stream operator

smart constructor for Tree labels | smart constructor for Tree branches | translate a Tree to a Generator | translate a Generator to a Tree | translate a Tree element to a Stream element | translate a Generator element to a Stream element | fromFG helper function (head) | fromFG helper function (tail) | fromRG: translate a Generator (and a reversed list) to a Stream element | fromRG helper function (head) | fromRG helper function (tail)

unfold operator, specialized to Co-Algebras | standard fix-point function, specialized to Co-Algebras | generate a Stream operator, given a Co-Algebra

utility function to lookup sequence in OEIS | utility function to check of all elements of a list are equal | utility function to unwrap a (known good) Maybe | utility function to map over adjacent elements in a list

Power Series Glasses

Horner's Rule on Streams

s = sconst (shead t) + (z |*| stail s)

implies

z |*| s = 0 <|| s