Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data CostStream
- unconsCost :: CostStream -> (CostingInteger, Maybe CostStream)
- reconsCost :: CostingInteger -> Maybe CostStream -> CostStream
- sumCostStream :: CostStream -> CostingInteger
- mapCostStream :: (CostingInteger -> CostingInteger) -> CostStream -> CostStream
- addCostStream :: CostStream -> CostStream -> CostStream
- minCostStream :: CostStream -> CostStream -> CostStream
Documentation
data CostStream Source #
A lazy stream of CostingInteger
s. Basically NonEmpty CostingInteger
, except the elements
are stored strictly.
The semantics of a stream are those of the sum of its elements. I.e. a stream that is a reordered version of another stream is considered equal to that stream.
All costs are assumed not to be negative and functions handling CostStream
s may rely on this
assumption. Negative costs (a.k.a. allowing the user to forge execution units at runtime)
wouldn't make sense.
Instances
unconsCost :: CostStream -> (CostingInteger, Maybe CostStream) Source #
Uncons an element from a CostStream
and return the rest of the stream, if not empty.
reconsCost :: CostingInteger -> Maybe CostStream -> CostStream Source #
Cons an element to a CostStream
, if given any. Otherwise create a new CostStream
using
CostLast
.
sumCostStream :: CostStream -> CostingInteger Source #
Add up all the costs in a CostStream
.
mapCostStream :: (CostingInteger -> CostingInteger) -> CostStream -> CostStream Source #
Map a function over a CostStream
.
addCostStream :: CostStream -> CostStream -> CostStream Source #
Add two streams by interleaving their elements (as opposed to draining out one of the streams before starting to take elements from the other one). No particular reason to prefer interleaving over draining out one of the streams first.
minCostStream :: CostStream -> CostStream -> CostStream Source #
Calculate the minimum of two CostStream
s. May return a stream that is longer than either of
the two (but not more than twice).