Agda
Safe HaskellNone
LanguageHaskell2010

Agda.Utils.ListInf

Description

Infinite lists (streams).

Wrapper for Data.List.Infinite from the infinite-list package that generalizes some type signatures, using Integral for indexing, and adds some missing functions.

Import this module as follows:

import Agda.Utils.ListInf (ListInf, pattern (:<))
import Agda.Utils.ListInf qualified as ListInf

Motivation: lists constructed by repeat, iterate, cycle etc. are infinite, so the nil case can never arise when consuming them, e.g. in a take or zipWith. Constructing them as properly infinite lists (ListInf) should thus lead to slightly more efficient code, eliminating impossible cases.

Synopsis

Documentation

(!!) :: Integral n => ListInf a -> n -> a Source #

append :: [a] -> ListInf a -> ListInf a Source #

There is only one meaningful way to concatenate a finite and an infinite list, justifying the name append = prependList.

drop :: Integral n => n -> ListInf a -> ListInf a Source #

pad :: [a] -> a -> ListInf a Source #

pad as b implements the frequent pattern as ++ repeat b.

splitAt :: Integral n => n -> ListInf a -> ([a], ListInf a) Source #

splitAt n as == (take n as, drop n as)

take :: Integral n => n -> ListInf a -> [a] Source #

upFrom :: Enum n => n -> ListInf n Source #

upFrom n = [n..] as properly infinite list.

updateAt :: Integral n => n -> (a -> a) -> ListInf a -> ListInf a Source #

Update the nth element of an infinite list. Θ(n).

Precondition: the index n is >= 0.

cycle :: NonEmpty a -> Infinite a #

Repeat a non-empty list ad infinitum. If you were looking for something like fromList :: [a] -> Infinite a, look no further.

It would be less annoying to take [a] instead of NonEmpty a, but we strive to avoid partial functions.

head :: Infinite a -> a #

Get the first elements of an infinite list.

iterate :: (a -> a) -> a -> Infinite a #

Generate an infinite list of repeated applications.

prependList :: [a] -> Infinite a -> Infinite a #

Prepend a list to an infinite list.

repeat :: a -> Infinite a #

Repeat the same element ad infinitum.

tail :: Infinite a -> Infinite a #

Get the elements of an infinite list after the first one.

zip :: Infinite a -> Infinite b -> Infinite (a, b) #

Zip two infinite lists.

zipWith :: (a -> b -> c) -> Infinite a -> Infinite b -> Infinite c #

Zip two infinite lists with a given function.

pattern (:<) :: a -> Infinite a -> Infinite a infixr 5 #