range- This has a bunch of code for specifying and managing ranges in your code.

Safe HaskellSafe-Inferred



Internally the range library converts your ranges into an internal representation of multiple ranges that I call a RangeMerge. When you do multiple unions and intersections in a row converting to and from that data structure becomes extra work that is not required. To amortize those costs away the RangeTree structure exists. You can specify a tree of operations in advance and then evaluate them all at once. This is not only useful for efficiency but for parsing too. Use RangeTree's whenever you wish to perform multiple operations in a row and wish for it to be as efficient as possible.



evaluate :: (Ord a, Enum a) => RangeTree a -> [Range a]Source

Evaluates a Range Tree into the final set of ranges that it compresses down to. Use this whenever you want to finally evaluate your constructed Range Tree.

data RangeTree a Source

A Range Tree is a construct that can be built and then efficiently evaluated so that you can compress an entire tree of operations on ranges into a single range quickly. The only purpose of this tree is to allow efficient construction of range operations that can be evaluated as is required.


RangeNode RangeOperation (RangeTree a) (RangeTree a)

Combine two range trees together with a single operation

RangeNodeInvert (RangeTree a)

Invert a range tree, this is a not operation.

RangeLeaf [Range a]

A leaf with a set of ranges that are collected together.

data RangeOperation Source

These are the operations that can join two disjunct lists of ranges together.



Represents the set union operation.


Represents the set intersection operation.