importPour l'utiliser : import Data.Stream
Stream — always-infinite sequences
Synopsis
data Stream a
= a :: Lazy (Stream a)
An infinite sequence: every Stream has a first element and a (lazy, memoised) rest — there is no empty case. It shares the cons operator :: with List and LazyList (resolved by type), but having no Nil means head and tail are total — a Stream is never empty.
Import it qualified, e.g. import Data.Stream as S, and write S.head, S.take, … so these names don't shadow the List versions.
::
a head in front of an infinite lazy tail (no Nil: total head/tail)
repeat : a -> Stream a
iterate : (a -> a) -> a -> Stream a
iterate f x is x, f x, f (f x), ….
from : Int -> Stream Int
The integers from n upward: n, n+1, n+2, ….
head : Stream a -> a
The first element. Total — a Stream always has one.
tail : Stream a -> Stream a
Everything after the first element. Total.
at : Nat -> Stream a -> a
at n s is the n-th element (0-based). n : Nat.
(!) : Stream a -> Nat -> Maybe a
Safe subscript s[i]? — always Just (a stream is infinite).
index : Stream a -> Nat -> a
take : Nat -> Stream a -> List a
take n s is the first n elements, as a strict List.
drop : Nat -> Stream a -> Stream a
drop n s discards the first n elements.
map : (a -> b) -> Stream a -> Stream b
Apply f to every element, lazily.
zipWith : (a -> b -> c) -> Stream a -> Stream b -> Stream c
Combine two streams pairwise.