copilot-libraries-4.7.1: Libraries for the Copilot language.

Copyright | (c) 2011 National Institute of Aerospace / Galois Inc.
Safe Haskell | Safe-Inferred
Language | Haskell2010

Copilot.Library.Utils

Contents

- Functions similar to the Prelude functions on lists
  - Folds
  - Scans
  - Indexing

Description

Utility bounded-list functions (e.g., folds, scans, etc.)

Synopsis

- take :: (Integral a, Typed b) => a -> Stream b -> [Stream b]
- tails :: Typed a => Stream a -> [Stream a]
- cycle :: Typed a => [a] -> Stream a
- nfoldl :: (Typed a, Typed b) => Int -> (Stream a -> Stream b -> Stream a) -> Stream a -> Stream b -> Stream a
- nfoldl1 :: Typed a => Int -> (Stream a -> Stream a -> Stream a) -> Stream a -> Stream a
- nfoldr :: (Typed a, Typed b) => Int -> (Stream a -> Stream b -> Stream b) -> Stream b -> Stream a -> Stream b
- nfoldr1 :: Typed a => Int -> (Stream a -> Stream a -> Stream a) -> Stream a -> Stream a
- nscanl :: (Typed a, Typed b) => Int -> (Stream a -> Stream b -> Stream a) -> Stream a -> Stream b -> [Stream a]
- nscanr :: Typed a => Int -> (Stream a -> Stream b -> Stream b) -> Stream b -> Stream a -> [Stream b]
- nscanl1 :: Typed a => Int -> (Stream a -> Stream a -> Stream a) -> Stream a -> [Stream a]
- nscanr1 :: Typed a => Int -> (Stream a -> Stream a -> Stream a) -> Stream a -> [Stream a]
- case' :: Typed a => [Stream Bool] -> [Stream a] -> Stream a
- (!!!) :: (Typed a, Eq b, Num b, Typed b) => [Stream a] -> Stream b -> Stream a

# Functions similar to the Prelude functions on lists

take :: (Integral a, Typed b) => a -> Stream b -> [Stream b] Source #

Given a stream and a number, produce a finite list of streams dropping an increasing number of elements of the given stream, up to that number. For example, for a given stream `s`, the expression `take 2 s` is equal to `[ drop 0 s, drop 1 s]`.

tails :: Typed a => Stream a -> [Stream a] Source #

Given a stream, produce an infinite list of streams dropping an increasing number of elements of the given stream. For example, for a given stream `s`, the expression `tails s` is equal to `[ drop 0 s, drop 1 s, drop 2 s, ...]`.

cycle :: Typed a => [a] -> Stream a Source #

Cycle a list to form an infinite stream.

## Folds

nfoldl :: (Typed a, Typed b) => Int -> (Stream a -> Stream b -> Stream a) -> Stream a -> Stream b -> Stream a Source #

Given a number, a function on streams, and two streams, fold from the left the function over the finite list of tails of the second stream (up to the given number).

nfoldl1 :: Typed a => Int -> (Stream a -> Stream a -> Stream a) -> Stream a -> Stream a Source #

Given a number, a function on streams, and two streams, fold from the left the function over the finite list of tails of the second stream (up to the given number).

This function differs from `nfoldl` in that it does not require an initial accumulator and it assumes the argument number `n` is positive.

nfoldr :: (Typed a, Typed b) => Int -> (Stream a -> Stream b -> Stream b) -> Stream b -> Stream a -> Stream b Source #

Given a number, a function on streams, and two streams, fold from the right the function over the finite list of tails of the second stream (up to the given number).

nfoldr1 :: Typed a => Int -> (Stream a -> Stream a -> Stream a) -> Stream a -> Stream a Source #

Given a number, a function on streams, and two streams, fold from the right the function over the finite list of tails of the second stream (up to the given number).

This function differs from `nfoldr` in that it does not require an initial accumulator and it assumes the argument number `n` is positive.

## Scans

nscanl :: (Typed a, Typed b) => Int -> (Stream a -> Stream b -> Stream a) -> Stream a -> Stream b -> [Stream a] Source #

Given a number, a function on streams, and two streams, fold from the left the function over the finite list of tails of the second stream (up to the given number).

This function differs from `nfoldl` in that it returns the intermediate results as well.

nscanr :: Typed a => Int -> (Stream a -> Stream b -> Stream b) -> Stream b -> Stream a -> [Stream b] Source #

Given a number, a function on streams, and two streams, fold from the right the function over the finite list of tails of the second stream (up to the given number).

This function differs from `nfoldr` in that it returns the intermediate results as well.

nscanl1 :: Typed a => Int -> (Stream a -> Stream a -> Stream a) -> Stream a -> [Stream a] Source #

Given a number, a function on streams, and two streams, fold from the left the function over the finite list of tails of the second stream (up to the given number).

This function assumes the number of elements to scan is positive, and it also returns the intermediate results.

nscanr1 :: Typed a => Int -> (Stream a -> Stream a -> Stream a) -> Stream a -> [Stream a] Source #

Given a number, a function on streams, and two streams, fold from the right the function over the finite list of tails of the second stream (up to the given number).

This function assumes the number of elements to scan is positive, and it also returns the intermediate results.

## Indexing

case' :: Typed a => [Stream Bool] -> [Stream a] -> Stream a Source #

Case-like function: The index of the first predicate that is true in the predicate list selects the stream result. If no predicate is true, the last element is chosen (default element)

(!!!) :: (Typed a, Eq b, Num b, Typed b) => [Stream a] -> Stream b -> Stream a Source #

Index.

WARNING: Very expensive! Consider using this only for very short lists.