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.

type ListInf = Infinite Source #

cycle :: NonEmpty a -> Infinite a #

head :: Infinite a -> a #

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

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

repeat :: a -> Infinite a #

tail :: Infinite a -> Infinite a #

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

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

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