Example reports

In this section, you can see a number of report examples using the value expression language.

Custom data structures

In the following we present some standard data structures and show how they can be implemented in CSL. As these structures are not built into the language itself we must define them ourselves if we need a structure that satisfies certain properties.

Set

A Set is a collection data structure that guarantees that all entries are unique.

module Set {
  val empty = []
  val contains = \(k:String) -> List::any (\e -> e = k)
  val remove = \(k:String) -> List::filter (\x -> not (x = k))
  val insert = \(k:String) -> \(l:List String) -> Cons k (Set::remove k l) 
  val toSet = foldr Set::insert []
  val isEmpty = \l -> List::length l = 0
}

val set1 = Set::insert "one" Set::empty
  // ["one"]

val set2 = Set::insert "one" (Set::toSet ["one", "two"])
  // ["one", "two"]

val set3 = Set::contains "two" (Set::toSet ["one", "two"])
  // True

val set4 = Set::remove "one" (Set::toSet ["one", "two"])
  // ["two"]

val set5 = Set::remove "foo" (Set::toSet ["one", "two"])
  // ["one", "two"]

Association list

An association list is a map-like data structure where keys and values are pairs.

module AssocList {
  val empty = []
  val contains = \ (k:String) -> List::any (\(x, _) -> k = x)
  val remove = \ (k:String) -> List::filter (\(x, _) -> not (x  = k))
  val update = \ (k:String) -> \ v -> \ l -> Cons (k, v) (AssocList::remove k l)
  val keys = List::map fst
  val values = List::map snd
  val isEmpty = \l -> List::length l = 0
}

val c = AssocList::update "a" 4 [("a", 1), ("b", 2)]

val vs = AssocList::values c
  // [4, 2]

val ks = AssocList::keys c
  // ["a", "b"]