package bap-knowledge

  1. Overview
  2. Docs

Knowledge Values.

A value is a concrete representation of knowledge. It is a snapshot of all properties associated with some object, i.e., an ordered tuple of slots. The value has no identity and that differs it from the object, as the value is essentially a property of an object - not an object itself.

From another perspective, a value is an extensible record, with fields reified into first-class slots, the record type into the cls values, and an additional constraint that all field types must be an instance of the domain type class (i.e., have a default and an ordering).

Each value has a class. The class value itself is indexed with the class and sort indices. The first index denotes the set of properties that could be associated with the value. The second index further partitions values of that class into subsets, to so that domain specific relations between values could be expressed explicitly with the host language type system.

The value sort is an arbitrary value, which can also be used to store additional static information about the value, i.e., the information that is common to all instances of the sort.

Total ordering and age

In addition to be partially ordered by their information content, values are also totally ordered, so that they could be organized into finite sets and maps.

The total order is induced from the information order, so that if a value x is ordered before y in the information order, then it will be also ordered before y in the total order. And if x and y have the same information content, then they are considered equal. Values with non-comparable information content are ordered by their time-stamp.

Every time a new value created it is assigned a time-stamp. A new value is created by all functions that has 'a value return type, except the refine function. Each time-stamp is unique and no two values could have the same time-stamps unless they are physically the same, or are de-serializations of the same value, or are refinements of the same value. In other words, values with equal time-stamps are guaranteed to bear the same information.

Time-stamp values correlate with the order of evaluation. A value that was evaluated more recently will have a higher time-stamp. Therefore time-stamps define an age of a value. A value which has a smaller time-stamp is younger than a value that has a larger time-stamp.

type 'a t = 'a value
type 'a ord

a witness of the ordering

include Core_kernel.Type_equal.Injective with type 'a t := 'a t
val strip : ('a t, 'b t) Base.Type_equal.equal -> ('a, 'b) Base.Type_equal.equal
val empty : ('a, 'b) cls -> ('a, 'b) cls value

empty cls the empty value of class cls.

The empty value has the least information content, i.e., all slots are empty.

val is_empty : _ value -> bool

is_empty x iff all properties of x are empty.

  • since 2.5.0
val order : 'a value -> 'a value -> Order.partial

order x y orders x and y by their information content.

val join : 'a value -> 'a value -> ('a value, conflict) Core_kernel.result

join x y joins pairwise all slots of x and y.

Each slot of x and y are joined using the Domain.join function. The result is either a pairwise join or a conflict if any of the joins ended up with a conflict.

val merge : ?on_conflict:[ `drop_old | `drop_new | `drop_right | `drop_left ] -> 'a value -> 'a value -> 'a value

merge x y joins x and y and resolves conflicts.

Performs a pairwise join of x and y and in case if any of the joins yields a conflict uses the provided strategy to resolve it.

  • parameter on_conflict

    specifies the conflict resolution strategy (see below). Defaults to `drop_old

    Conflict resolution strategies

    The following conflict resolution strategies are currently supported (more strategies could be added later):

    • `drop_old a conflicting property of an older object is ignored (an object is older if its time-stamp is less than or equal the time-stamp of other object);
    • `drop_new a conflicting property of the newer object is ignored (an object is newer if its time-stamp is greater than or equal the time-stamp of other object);
    • `drop_right a conflicting property of y is ignored;
    • `drop_left a conflicting property of x is ignored.
val cls : ('k, 's) cls value -> ('k, 's) cls

cls x is the class of x.

val get : ('k, 'p) slot -> ('k, _) cls value -> 'p

get p v gets a value of the property p.

val put : ('k, 'p) slot -> ('k, 's) cls value -> 'p -> ('k, 's) cls value

put p v x sets a value of the property p.

val has : ('k, 'p) slot -> ('k, 's) cls value -> bool

has p x if property p of x is not empty.

  • since 2.5.0
val refine : ('k, _) cls value -> 's -> ('k, 's) cls value

refine v s refines the sort of v to s.

Since, this function doesn't change the information stored in the value, the time-stamp of the returned value is the same, therefore v = refine v s.

module type S = sig ... end
val derive : ('a, 's) cls -> (module S with type comparator_witness = ('a, 's) cls ord and type t = ('a, 's) cls t)

derive cls derives the implementation of the S structure.

val pp : Stdlib.Format.formatter -> 'a value -> unit

pp ppf v outputs v to the formatter ppf.

Prints all slots of the value v.

val pp_slots : string list -> Stdlib.Format.formatter -> 'a value -> unit

pp_slots slots ppf v prints the specified set of slots.

Prints only slots that has a name in slots.

OCaml

Innovation. Community. Security.