sparsebit-0.3: Sparse bitmaps for pattern match coverage



This library packages the functional peal paper 'Sparse Bitmaps for Pattern Match Coverage' submitted to ICFP 2009 by Ki Yung Ahn and Tim Sheard. You can look up the tutorial-like paper and the talk slides, which are availabel at:


Pattern matching coverage over Algebraic Data Types(ADTs) has most often been studied in the context of pattern compilation algorithms. However, it is worth considering the pattern matching coverage problem in isolation, since general solutions will be independent of the specifics of any implementation or language.

We define an intuitive and mathematically well-established bit masking semantics for pattern match coverage. We design and implement a sparse bitmap data structure, which realizes this semantics in a compact and flexible manner. This bitmap data structure supports computing coverage solutions of large programs incrementally from coverage solutions of sub-programs. It can also be used as a common data representation for pattern coverage shared between different tools (e.g., compilers, linting tools, software analysis tools) that need pattern match coverage information.



class Expand t whereSource


(*.) :: t -> t -> tSource

type product

Type product of two types is usually a product type (or pair type). Conceptually, for example, Int *. Bool = (Int,Bool). Note, (*.) have at least one identity unit, and type product against such identities may not result in a prodcut type.

unit :: tSource

identity on (*.)

 unit *. a = a = a *. unit

Note, there can be other identities depending on how you define expand. Any type a that satisfy null(expand a) is an identity on (*.). The unit is the most simple and basic identity among them, which serves as a degenerate type for nullary data data constants (e.g., True, False).

expand :: t -> [t]Source

type expansion rule

The definition of expand summarizes the structure of algebraic data type. Conceptually, for example,

 expand unit = [] -- the-non expandable degenerate type
 expand Bool = [unit,unit]  -- True, False
 expand (Maybe a) = [unit, a] -- Nothing, Just a

data BIT t Source


O t

all 0 bits (identity on (.|))

I t

all 1 bits (identity on (.&))

Bs [BIT t] t

sequence of bits (possibley nested)


Eq t => Eq (BIT t) 
Show t => Show (BIT t) 

typeof :: BIT t -> tSource

extract the type information of a given bit

For example,

 typeof (O Bool) = Bool 
 typeof (I Bool) = Int
 typeof (Bs [O unit,I unit] Bool) = Bool

showB :: BIT t -> StringSource

turn bits into strings without the type information

For example,

 showB (Bs [O unit,I unit] Bool) = "[01]"

showB' :: BIT t -> StringSource

same as showB but takes off the outermost square bracket

For example,

 showB' (Bs [O unit,I unit] Bool) = "01"

printB :: BIT t -> IO ()Source

print a newline ended string produced from showB' on the standard output

(.&) :: BIT t -> BIT t -> BIT tSource


(.&.) :: [BIT t] -> [BIT t] -> [BIT t]Source

(.|) :: BIT t -> BIT t -> BIT tSource


(.|.) :: [BIT t] -> [BIT t] -> [BIT t]Source

neg :: BIT t -> BIT tSource

bitwise negation

reduce :: BIT t -> BIT tSource

reduce BITs to canonical forms

(.**) :: Expand t => BIT t -> BIT t -> BIT tSource

tensor product

(=:=) :: Eq t => BIT t -> BIT t -> BoolSource

congruence modulo reduce